Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
f7432337
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1187
Star
22018
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看板
提交
f7432337
编写于
3月 22, 2022
作者:
M
Minghao Li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
sync refactor
上级
1c311368
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
74 addition
and
47 deletion
+74
-47
include/libs/sync/sync.h
include/libs/sync/sync.h
+13
-10
source/libs/sync/src/syncAppendEntries.c
source/libs/sync/src/syncAppendEntries.c
+4
-4
source/libs/sync/src/syncCommit.c
source/libs/sync/src/syncCommit.c
+1
-1
source/libs/sync/src/syncIO.c
source/libs/sync/src/syncIO.c
+3
-3
source/libs/sync/src/syncMain.c
source/libs/sync/src/syncMain.c
+2
-2
source/libs/sync/test/syncReplicateTest.cpp
source/libs/sync/test/syncReplicateTest.cpp
+19
-9
source/libs/sync/test/syncReplicateTest2.cpp
source/libs/sync/test/syncReplicateTest2.cpp
+13
-9
source/libs/sync/test/syncWriteTest.cpp
source/libs/sync/test/syncWriteTest.cpp
+19
-9
未找到文件。
include/libs/sync/sync.h
浏览文件 @
f7432337
...
...
@@ -69,17 +69,20 @@ typedef struct SSnapshot {
typedef
struct
SSyncFSM
{
void
*
data
;
// when value in p
Buf
finish a raft flow, FpCommitCb is called, code indicates the result
// when value in p
Msg
finish a raft flow, FpCommitCb is called, code indicates the result
// user can do something according to the code and isWeak. for example, write data into tsdb
void
(
*
FpCommitCb
)(
struct
SSyncFSM
*
pFsm
,
const
SRpcMsg
*
pBuf
,
SyncIndex
index
,
bool
isWeak
,
int32_t
code
);
void
(
*
FpCommitCb
)(
struct
SSyncFSM
*
pFsm
,
const
SRpcMsg
*
pMsg
,
SyncIndex
index
,
bool
isWeak
,
int32_t
code
,
ESyncState
state
);
// when value in p
Buf
has been written into local log store, FpPreCommitCb is called, code indicates the result
// when value in p
Msg
has been written into local log store, FpPreCommitCb is called, code indicates the result
// user can do something according to the code and isWeak. for example, write data into tsdb
void
(
*
FpPreCommitCb
)(
struct
SSyncFSM
*
pFsm
,
const
SRpcMsg
*
pBuf
,
SyncIndex
index
,
bool
isWeak
,
int32_t
code
);
void
(
*
FpPreCommitCb
)(
struct
SSyncFSM
*
pFsm
,
const
SRpcMsg
*
pMsg
,
SyncIndex
index
,
bool
isWeak
,
int32_t
code
,
ESyncState
state
);
// when log entry is updated by a new one, FpRollBackCb is called
// user can do something to roll back. for example, delete data from tsdb, or just ignore it
void
(
*
FpRollBackCb
)(
struct
SSyncFSM
*
pFsm
,
const
SRpcMsg
*
pBuf
,
SyncIndex
index
,
bool
isWeak
,
int32_t
code
);
void
(
*
FpRollBackCb
)(
struct
SSyncFSM
*
pFsm
,
const
SRpcMsg
*
pMsg
,
SyncIndex
index
,
bool
isWeak
,
int32_t
code
,
ESyncState
state
);
// user should implement this function, use "data" to take snapshot into "snapshot"
int32_t
(
*
FpTakeSnapshot
)(
SSnapshot
*
snapshot
);
...
...
@@ -155,11 +158,11 @@ typedef struct SSyncNode SSyncNode;
int32_t
syncInit
();
void
syncCleanUp
();
int64_t
syncStart
(
const
SSyncInfo
*
pSyncInfo
);
void
syncStop
(
int64_t
rid
);
int32_t
syncReconfig
(
int64_t
rid
,
const
SSyncCfg
*
pSyncCfg
);
int32_t
syncPropose
(
int64_t
rid
,
const
SRpcMsg
*
pMsg
,
bool
isWeak
);
// use this function
int32_t
syncForwardToPeer
(
int64_t
rid
,
const
SRpcMsg
*
pMsg
,
bool
isWeak
);
// just for compatibility
int64_t
syncStart
(
const
SSyncInfo
*
pSyncInfo
);
void
syncStop
(
int64_t
rid
);
int32_t
syncReconfig
(
int64_t
rid
,
const
SSyncCfg
*
pSyncCfg
);
int32_t
syncPropose
(
int64_t
rid
,
const
SRpcMsg
*
pMsg
,
bool
isWeak
);
// use this function
int32_t
syncForwardToPeer
(
int64_t
rid
,
const
SRpcMsg
*
pMsg
,
bool
isWeak
);
// for compatibility, the same as syncPropose
ESyncState
syncGetMyRole
(
int64_t
rid
);
extern
int32_t
sDebugFlag
;
...
...
source/libs/sync/src/syncAppendEntries.c
浏览文件 @
f7432337
...
...
@@ -213,7 +213,7 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) {
SRpcMsg
rpcMsg
;
syncEntry2OriginalRpc
(
pRollBackEntry
,
&
rpcMsg
);
ths
->
pFsm
->
FpRollBackCb
(
ths
->
pFsm
,
&
rpcMsg
,
pRollBackEntry
->
index
,
pRollBackEntry
->
isWeak
,
0
);
ths
->
pFsm
->
FpRollBackCb
(
ths
->
pFsm
,
&
rpcMsg
,
pRollBackEntry
->
index
,
pRollBackEntry
->
isWeak
,
0
,
ths
->
state
);
rpcFreeCont
(
rpcMsg
.
pCont
);
syncEntryDestory
(
pRollBackEntry
);
}
...
...
@@ -230,7 +230,7 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) {
syncEntry2OriginalRpc
(
pAppendEntry
,
&
rpcMsg
);
if
(
ths
->
pFsm
!=
NULL
)
{
if
(
ths
->
pFsm
->
FpPreCommitCb
!=
NULL
)
{
ths
->
pFsm
->
FpPreCommitCb
(
ths
->
pFsm
,
&
rpcMsg
,
pAppendEntry
->
index
,
pAppendEntry
->
isWeak
,
2
);
ths
->
pFsm
->
FpPreCommitCb
(
ths
->
pFsm
,
&
rpcMsg
,
pAppendEntry
->
index
,
pAppendEntry
->
isWeak
,
2
,
ths
->
state
);
}
}
rpcFreeCont
(
rpcMsg
.
pCont
);
...
...
@@ -255,7 +255,7 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) {
syncEntry2OriginalRpc
(
pAppendEntry
,
&
rpcMsg
);
if
(
ths
->
pFsm
!=
NULL
)
{
if
(
ths
->
pFsm
->
FpPreCommitCb
!=
NULL
)
{
ths
->
pFsm
->
FpPreCommitCb
(
ths
->
pFsm
,
&
rpcMsg
,
pAppendEntry
->
index
,
pAppendEntry
->
isWeak
,
3
);
ths
->
pFsm
->
FpPreCommitCb
(
ths
->
pFsm
,
&
rpcMsg
,
pAppendEntry
->
index
,
pAppendEntry
->
isWeak
,
3
,
ths
->
state
);
}
}
rpcFreeCont
(
rpcMsg
.
pCont
);
...
...
@@ -326,7 +326,7 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) {
syncEntry2OriginalRpc
(
pEntry
,
&
rpcMsg
);
if
(
ths
->
pFsm
->
FpCommitCb
!=
NULL
)
{
ths
->
pFsm
->
FpCommitCb
(
ths
->
pFsm
,
&
rpcMsg
,
pEntry
->
index
,
pEntry
->
isWeak
,
0
);
ths
->
pFsm
->
FpCommitCb
(
ths
->
pFsm
,
&
rpcMsg
,
pEntry
->
index
,
pEntry
->
isWeak
,
0
,
ths
->
state
);
}
rpcFreeCont
(
rpcMsg
.
pCont
);
...
...
source/libs/sync/src/syncCommit.c
浏览文件 @
f7432337
...
...
@@ -91,7 +91,7 @@ void syncMaybeAdvanceCommitIndex(SSyncNode* pSyncNode) {
syncEntry2OriginalRpc
(
pEntry
,
&
rpcMsg
);
if
(
pSyncNode
->
pFsm
->
FpCommitCb
!=
NULL
)
{
pSyncNode
->
pFsm
->
FpCommitCb
(
pSyncNode
->
pFsm
,
&
rpcMsg
,
pEntry
->
index
,
pEntry
->
isWeak
,
0
);
pSyncNode
->
pFsm
->
FpCommitCb
(
pSyncNode
->
pFsm
,
&
rpcMsg
,
pEntry
->
index
,
pEntry
->
isWeak
,
0
,
pSyncNode
->
state
);
}
rpcFreeCont
(
rpcMsg
.
pCont
);
...
...
source/libs/sync/src/syncIO.c
浏览文件 @
f7432337
...
...
@@ -29,7 +29,7 @@ static int32_t syncIODestroy(SSyncIO *io);
static
int32_t
syncIOStartInternal
(
SSyncIO
*
io
);
static
int32_t
syncIOStopInternal
(
SSyncIO
*
io
);
static
void
*
syncIOConsumerFunc
(
void
*
param
);
static
void
*
syncIOConsumerFunc
(
void
*
param
);
static
void
syncIOProcessRequest
(
void
*
pParent
,
SRpcMsg
*
pMsg
,
SEpSet
*
pEpSet
);
static
void
syncIOProcessReply
(
void
*
pParent
,
SRpcMsg
*
pMsg
,
SEpSet
*
pEpSet
);
static
int32_t
syncIOAuth
(
void
*
parent
,
char
*
meterId
,
char
*
spi
,
char
*
encrypt
,
char
*
secret
,
char
*
ckey
);
...
...
@@ -234,9 +234,9 @@ static int32_t syncIOStopInternal(SSyncIO *io) {
}
static
void
*
syncIOConsumerFunc
(
void
*
param
)
{
SSyncIO
*
io
=
param
;
SSyncIO
*
io
=
param
;
STaosQall
*
qall
;
SRpcMsg
*
pRpcMsg
,
rpcMsg
;
SRpcMsg
*
pRpcMsg
,
rpcMsg
;
qall
=
taosAllocateQall
();
while
(
1
)
{
...
...
source/libs/sync/src/syncMain.c
浏览文件 @
f7432337
...
...
@@ -849,7 +849,7 @@ static int32_t syncNodeOnClientRequestCb(SSyncNode* ths, SyncClientRequest* pMsg
if
(
ths
->
pFsm
!=
NULL
)
{
if
(
ths
->
pFsm
->
FpPreCommitCb
!=
NULL
)
{
ths
->
pFsm
->
FpPreCommitCb
(
ths
->
pFsm
,
&
rpcMsg
,
pEntry
->
index
,
pEntry
->
isWeak
,
0
);
ths
->
pFsm
->
FpPreCommitCb
(
ths
->
pFsm
,
&
rpcMsg
,
pEntry
->
index
,
pEntry
->
isWeak
,
0
,
ths
->
state
);
}
}
rpcFreeCont
(
rpcMsg
.
pCont
);
...
...
@@ -864,7 +864,7 @@ static int32_t syncNodeOnClientRequestCb(SSyncNode* ths, SyncClientRequest* pMsg
if
(
ths
->
pFsm
!=
NULL
)
{
if
(
ths
->
pFsm
->
FpPreCommitCb
!=
NULL
)
{
ths
->
pFsm
->
FpPreCommitCb
(
ths
->
pFsm
,
&
rpcMsg
,
pEntry
->
index
,
pEntry
->
isWeak
,
1
);
ths
->
pFsm
->
FpPreCommitCb
(
ths
->
pFsm
,
&
rpcMsg
,
pEntry
->
index
,
pEntry
->
isWeak
,
1
,
ths
->
state
);
}
}
rpcFreeCont
(
rpcMsg
.
pCont
);
...
...
source/libs/sync/test/syncReplicateTest.cpp
浏览文件 @
f7432337
...
...
@@ -28,19 +28,29 @@ SSyncFSM * pFsm;
SWal
*
pWal
;
SSyncNode
*
gSyncNode
;
void
CommitCb
(
struct
SSyncFSM
*
pFsm
,
const
SRpcMsg
*
pBuf
,
SyncIndex
index
,
bool
isWeak
,
int32_t
code
)
{
printf
(
"==CommitCb== pFsm:%p, index:%ld, isWeak:%d, code:%d
\n
"
,
pFsm
,
index
,
isWeak
,
code
);
syncRpcMsgPrint2
((
char
*
)
"==CommitCb=="
,
(
SRpcMsg
*
)
pBuf
);
void
CommitCb
(
struct
SSyncFSM
*
pFsm
,
const
SRpcMsg
*
pMsg
,
SyncIndex
index
,
bool
isWeak
,
int32_t
code
,
ESyncState
state
)
{
char
logBuf
[
256
];
snprintf
(
logBuf
,
sizeof
(
logBuf
),
"==callback== ==CommitCb== pFsm:%p, index:%ld, isWeak:%d, code:%d, state:%d %s
\n
"
,
pFsm
,
index
,
isWeak
,
code
,
state
,
syncUtilState2String
(
state
));
syncRpcMsgPrint2
(
logBuf
,
(
SRpcMsg
*
)
pMsg
);
}
void
PreCommitCb
(
struct
SSyncFSM
*
pFsm
,
const
SRpcMsg
*
pBuf
,
SyncIndex
index
,
bool
isWeak
,
int32_t
code
)
{
printf
(
"==PreCommitCb== pFsm:%p, index:%ld, isWeak:%d, code:%d
\n
"
,
pFsm
,
index
,
isWeak
,
code
);
syncRpcMsgPrint2
((
char
*
)
"==PreCommitCb=="
,
(
SRpcMsg
*
)
pBuf
);
void
PreCommitCb
(
struct
SSyncFSM
*
pFsm
,
const
SRpcMsg
*
pMsg
,
SyncIndex
index
,
bool
isWeak
,
int32_t
code
,
ESyncState
state
)
{
char
logBuf
[
256
];
snprintf
(
logBuf
,
sizeof
(
logBuf
),
"==callback== ==PreCommitCb== pFsm:%p, index:%ld, isWeak:%d, code:%d, state:%d %s
\n
"
,
pFsm
,
index
,
isWeak
,
code
,
state
,
syncUtilState2String
(
state
));
syncRpcMsgPrint2
(
logBuf
,
(
SRpcMsg
*
)
pMsg
);
}
void
RollBackCb
(
struct
SSyncFSM
*
pFsm
,
const
SRpcMsg
*
pBuf
,
SyncIndex
index
,
bool
isWeak
,
int32_t
code
)
{
printf
(
"==RollBackCb== pFsm:%p, index:%ld, isWeak:%d, code:%d
\n
"
,
pFsm
,
index
,
isWeak
,
code
);
syncRpcMsgPrint2
((
char
*
)
"==RollBackCb=="
,
(
SRpcMsg
*
)
pBuf
);
void
RollBackCb
(
struct
SSyncFSM
*
pFsm
,
const
SRpcMsg
*
pMsg
,
SyncIndex
index
,
bool
isWeak
,
int32_t
code
,
ESyncState
state
)
{
char
logBuf
[
256
];
snprintf
(
logBuf
,
sizeof
(
logBuf
),
"==callback== ==RollBackCb== pFsm:%p, index:%ld, isWeak:%d, code:%d, state:%d %s
\n
"
,
pFsm
,
index
,
isWeak
,
code
,
state
,
syncUtilState2String
(
state
));
syncRpcMsgPrint2
(
logBuf
,
(
SRpcMsg
*
)
pMsg
);
}
void
initFsm
()
{
...
...
source/libs/sync/test/syncReplicateTest2.cpp
浏览文件 @
f7432337
...
...
@@ -27,24 +27,28 @@ SSyncInfo syncInfo;
SSyncFSM
*
pFsm
;
SWal
*
pWal
;
void
CommitCb
(
struct
SSyncFSM
*
pFsm
,
const
SRpcMsg
*
pMsg
,
SyncIndex
index
,
bool
isWeak
,
int32_t
code
)
{
void
CommitCb
(
struct
SSyncFSM
*
pFsm
,
const
SRpcMsg
*
pMsg
,
SyncIndex
index
,
bool
isWeak
,
int32_t
code
,
ESyncState
state
)
{
char
logBuf
[
256
];
snprintf
(
logBuf
,
sizeof
(
logBuf
),
"==callback== ==CommitCb== pFsm:%p, index:%ld, isWeak:%d, code:%d
\n
"
,
pFsm
,
index
,
isWeak
,
code
);
snprintf
(
logBuf
,
sizeof
(
logBuf
),
"==callback== ==CommitCb== pFsm:%p, index:%ld, isWeak:%d, code:%d
, state:%d %s
\n
"
,
pFsm
,
index
,
isWeak
,
code
,
state
,
syncUtilState2String
(
state
)
);
syncRpcMsgPrint2
(
logBuf
,
(
SRpcMsg
*
)
pMsg
);
}
void
PreCommitCb
(
struct
SSyncFSM
*
pFsm
,
const
SRpcMsg
*
pMsg
,
SyncIndex
index
,
bool
isWeak
,
int32_t
code
)
{
void
PreCommitCb
(
struct
SSyncFSM
*
pFsm
,
const
SRpcMsg
*
pMsg
,
SyncIndex
index
,
bool
isWeak
,
int32_t
code
,
ESyncState
state
)
{
char
logBuf
[
256
];
snprintf
(
logBuf
,
sizeof
(
logBuf
),
"==callback== ==PreCommitCb== pFsm:%p, index:%ld, isWeak:%d, code:%d
\n
"
,
pFsm
,
index
,
isWeak
,
code
);
snprintf
(
logBuf
,
sizeof
(
logBuf
),
"==callback== ==PreCommitCb== pFsm:%p, index:%ld, isWeak:%d, code:%d, state:%d %s
\n
"
,
pFsm
,
index
,
isWeak
,
code
,
state
,
syncUtilState2String
(
state
));
syncRpcMsgPrint2
(
logBuf
,
(
SRpcMsg
*
)
pMsg
);
}
void
RollBackCb
(
struct
SSyncFSM
*
pFsm
,
const
SRpcMsg
*
pMsg
,
SyncIndex
index
,
bool
isWeak
,
int32_t
code
)
{
void
RollBackCb
(
struct
SSyncFSM
*
pFsm
,
const
SRpcMsg
*
pMsg
,
SyncIndex
index
,
bool
isWeak
,
int32_t
code
,
ESyncState
state
)
{
char
logBuf
[
256
];
snprintf
(
logBuf
,
sizeof
(
logBuf
),
"==callback== ==RollBackCb== pFsm:%p, index:%ld, isWeak:%d, code:%d
\n
"
,
pFsm
,
index
,
isWeak
,
code
);
snprintf
(
logBuf
,
sizeof
(
logBuf
),
"==callback== ==RollBackCb== pFsm:%p, index:%ld, isWeak:%d, code:%d
, state:%d %s
\n
"
,
pFsm
,
index
,
isWeak
,
code
,
state
,
syncUtilState2String
(
state
)
);
syncRpcMsgPrint2
(
logBuf
,
(
SRpcMsg
*
)
pMsg
);
}
...
...
source/libs/sync/test/syncWriteTest.cpp
浏览文件 @
f7432337
...
...
@@ -28,19 +28,29 @@ SSyncFSM * pFsm;
SWal
*
pWal
;
SSyncNode
*
gSyncNode
;
void
CommitCb
(
struct
SSyncFSM
*
pFsm
,
const
SRpcMsg
*
pBuf
,
SyncIndex
index
,
bool
isWeak
,
int32_t
code
)
{
printf
(
"==CommitCb== pFsm:%p, index:%ld, isWeak:%d, code:%d
\n
"
,
pFsm
,
index
,
isWeak
,
code
);
syncRpcMsgPrint2
((
char
*
)
"==CommitCb=="
,
(
SRpcMsg
*
)
pBuf
);
void
CommitCb
(
struct
SSyncFSM
*
pFsm
,
const
SRpcMsg
*
pMsg
,
SyncIndex
index
,
bool
isWeak
,
int32_t
code
,
ESyncState
state
)
{
char
logBuf
[
256
];
snprintf
(
logBuf
,
sizeof
(
logBuf
),
"==callback== ==CommitCb== pFsm:%p, index:%ld, isWeak:%d, code:%d, state:%d %s
\n
"
,
pFsm
,
index
,
isWeak
,
code
,
state
,
syncUtilState2String
(
state
));
syncRpcMsgPrint2
(
logBuf
,
(
SRpcMsg
*
)
pMsg
);
}
void
PreCommitCb
(
struct
SSyncFSM
*
pFsm
,
const
SRpcMsg
*
pBuf
,
SyncIndex
index
,
bool
isWeak
,
int32_t
code
)
{
printf
(
"==PreCommitCb== pFsm:%p, index:%ld, isWeak:%d, code:%d
\n
"
,
pFsm
,
index
,
isWeak
,
code
);
syncRpcMsgPrint2
((
char
*
)
"==PreCommitCb=="
,
(
SRpcMsg
*
)
pBuf
);
void
PreCommitCb
(
struct
SSyncFSM
*
pFsm
,
const
SRpcMsg
*
pMsg
,
SyncIndex
index
,
bool
isWeak
,
int32_t
code
,
ESyncState
state
)
{
char
logBuf
[
256
];
snprintf
(
logBuf
,
sizeof
(
logBuf
),
"==callback== ==PreCommitCb== pFsm:%p, index:%ld, isWeak:%d, code:%d, state:%d %s
\n
"
,
pFsm
,
index
,
isWeak
,
code
,
state
,
syncUtilState2String
(
state
));
syncRpcMsgPrint2
(
logBuf
,
(
SRpcMsg
*
)
pMsg
);
}
void
RollBackCb
(
struct
SSyncFSM
*
pFsm
,
const
SRpcMsg
*
pBuf
,
SyncIndex
index
,
bool
isWeak
,
int32_t
code
)
{
printf
(
"==RollBackCb== pFsm:%p, index:%ld, isWeak:%d, code:%d
\n
"
,
pFsm
,
index
,
isWeak
,
code
);
syncRpcMsgPrint2
((
char
*
)
"==RollBackCb=="
,
(
SRpcMsg
*
)
pBuf
);
void
RollBackCb
(
struct
SSyncFSM
*
pFsm
,
const
SRpcMsg
*
pMsg
,
SyncIndex
index
,
bool
isWeak
,
int32_t
code
,
ESyncState
state
)
{
char
logBuf
[
256
];
snprintf
(
logBuf
,
sizeof
(
logBuf
),
"==callback== ==RollBackCb== pFsm:%p, index:%ld, isWeak:%d, code:%d, state:%d %s
\n
"
,
pFsm
,
index
,
isWeak
,
code
,
state
,
syncUtilState2String
(
state
));
syncRpcMsgPrint2
(
logBuf
,
(
SRpcMsg
*
)
pMsg
);
}
void
initFsm
()
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录