Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
aaf5e20f
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看板
提交
aaf5e20f
编写于
3月 01, 2022
作者:
M
Minghao Li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
sync encode test
上级
12c202aa
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
58 addition
and
33 deletion
+58
-33
source/libs/sync/inc/syncInt.h
source/libs/sync/inc/syncInt.h
+8
-10
source/libs/sync/src/syncIO.c
source/libs/sync/src/syncIO.c
+13
-7
source/libs/sync/src/syncMain.c
source/libs/sync/src/syncMain.c
+36
-15
source/libs/sync/src/syncUtil.c
source/libs/sync/src/syncUtil.c
+1
-1
未找到文件。
source/libs/sync/inc/syncInt.h
浏览文件 @
aaf5e20f
...
...
@@ -97,14 +97,17 @@ typedef struct SRaftId {
}
SRaftId
;
typedef
struct
SSyncNode
{
int8_t
replica
;
int8_t
quorum
;
int32_t
refCount
;
int64_t
rid
;
SyncGroupId
vgId
;
SSyncCfg
syncCfg
;
char
path
[
TSDB_FILENAME_LEN
];
SSyncFSM
*
pFsm
;
// passed from outside
void
*
rpcClient
;
int32_t
(
*
FpSendMsg
)(
void
*
rpcClient
,
const
SEpSet
*
pEpSet
,
SRpcMsg
*
pMsg
);
int32_t
refCount
;
int64_t
rid
;
SNodeInfo
me
;
SNodeInfo
peers
[
TSDB_MAX_REPLICA
];
...
...
@@ -112,7 +115,6 @@ typedef struct SSyncNode {
ESyncRole
role
;
SRaftId
raftId
;
SSyncFSM
*
pFsm
;
tmr_h
pPingTimer
;
int32_t
pingTimerMS
;
...
...
@@ -145,10 +147,6 @@ typedef struct SSyncNode {
int32_t
(
*
FpOnAppendEntriesReply
)(
SSyncNode
*
ths
,
SyncAppendEntriesReply
*
pMsg
);
// passed from outside
void
*
rpcClient
;
int32_t
(
*
FpSendMsg
)(
void
*
rpcClient
,
const
SEpSet
*
pEpSet
,
SRpcMsg
*
pMsg
);
}
SSyncNode
;
SSyncNode
*
syncNodeOpen
(
const
SSyncInfo
*
pSyncInfo
);
...
...
source/libs/sync/src/syncIO.c
浏览文件 @
aaf5e20f
...
...
@@ -30,19 +30,26 @@ static int32_t doSyncIOOnMsg(struct SSyncIO *io, void *pParent, SRpcMsg *pMsg, S
static
int32_t
doSyncIODestroy
(
SSyncIO
*
io
);
static
SSyncIO
*
syncIOCreate
();
static
void
*
syncIOConsumer
(
void
*
param
);
static
void
*
syncIOConsumer
(
void
*
param
);
static
int
syncIOAuth
(
void
*
parent
,
char
*
meterId
,
char
*
spi
,
char
*
encrypt
,
char
*
secret
,
char
*
ckey
);
static
void
syncIODoReply
(
void
*
pParent
,
SRpcMsg
*
pMsg
,
SEpSet
*
pEpSet
);
static
void
syncIODoRequest
(
void
*
pParent
,
SRpcMsg
*
pMsg
,
SEpSet
*
pEpSet
);
static
void
syncIOTick
(
void
*
param
,
void
*
tmrId
);
// ----------------------------
int32_t
syncIOSendMsg
(
void
*
handle
,
const
SEpSet
*
pEpSet
,
SRpcMsg
*
pMsg
)
{
return
0
;
}
int32_t
syncIOSendMsg
(
void
*
handle
,
const
SEpSet
*
pEpSet
,
SRpcMsg
*
pMsg
)
{
pMsg
->
handle
=
NULL
;
rpcSendRequest
(
handle
,
pEpSet
,
pMsg
,
NULL
);
return
0
;
}
int32_t
syncIOStart
()
{
gSyncIO
=
syncIOCreate
();
assert
(
gSyncIO
!=
NULL
);
int32_t
ret
=
doSyncIOStart
(
gSyncIO
);
assert
(
ret
==
0
);
return
0
;
}
...
...
@@ -67,15 +74,14 @@ static void syncIOTick(void *param, void *tmrId) {
taosWriteQitem
(
io
->
pMsgQ
,
pTemp
);
bool
b
=
taosTmrReset
(
syncIOTick
,
1000
,
io
,
io
->
syncTimerManager
,
io
->
syncTimer
);
assert
(
b
);
taosTmrReset
(
syncIOTick
,
1000
,
io
,
io
->
syncTimerManager
,
io
->
syncTimer
);
}
static
void
*
syncIOConsumer
(
void
*
param
)
{
SSyncIO
*
io
=
param
;
STaosQall
*
qall
;
SRpcMsg
*
pRpcMsg
,
rpcMsg
;
SRpcMsg
*
pRpcMsg
,
rpcMsg
;
int
type
;
qall
=
taosAllocateQall
();
...
...
@@ -215,8 +221,8 @@ static int32_t doSyncIOStart(SSyncIO *io) {
}
// start tmr thread
io
->
syncTimerManager
=
taosTmrInit
(
1000
,
50
,
10000
,
"SYNC"
);
io
->
syncTimer
=
taosTmrStart
(
syncIOTick
,
1000
,
io
,
io
->
syncTimerManager
);
//
io->syncTimerManager = taosTmrInit(1000, 50, 10000, "SYNC");
//
io->syncTimer = taosTmrStart(syncIOTick, 1000, io, io->syncTimerManager);
return
0
;
}
...
...
source/libs/sync/src/syncMain.c
浏览文件 @
aaf5e20f
...
...
@@ -69,15 +69,34 @@ SSyncNode* syncNodeOpen(const SSyncInfo* pSyncInfo) {
assert
(
pSyncNode
!=
NULL
);
memset
(
pSyncNode
,
0
,
sizeof
(
SSyncNode
));
pSyncNode
->
vgId
=
pSyncInfo
->
vgId
;
pSyncNode
->
syncCfg
=
pSyncInfo
->
syncCfg
;
memcpy
(
pSyncNode
->
path
,
pSyncInfo
->
path
,
sizeof
(
pSyncNode
->
path
));
pSyncNode
->
pFsm
=
pSyncInfo
->
pFsm
;
pSyncNode
->
rpcClient
=
pSyncInfo
->
rpcClient
;
pSyncNode
->
FpSendMsg
=
pSyncInfo
->
FpSendMsg
;
pSyncNode
->
me
=
pSyncInfo
->
syncCfg
.
nodeInfo
[
pSyncInfo
->
syncCfg
.
myIndex
];
pSyncNode
->
peersNum
=
pSyncInfo
->
syncCfg
.
replicaNum
-
1
;
int
j
=
0
;
for
(
int
i
=
0
;
i
<
pSyncInfo
->
syncCfg
.
replicaNum
;
++
i
)
{
if
(
i
!=
pSyncInfo
->
syncCfg
.
myIndex
)
{
pSyncNode
->
peers
[
j
]
=
pSyncInfo
->
syncCfg
.
nodeInfo
[
i
];
j
++
;
}
}
pSyncNode
->
role
=
TAOS_SYNC_STATE_FOLLOWER
;
syncUtilnodeInfo2raftId
(
&
pSyncNode
->
me
,
pSyncNode
->
vgId
,
&
pSyncNode
->
raftId
);
pSyncNode
->
pPingTimer
=
NULL
;
pSyncNode
->
pingTimerMS
=
1000
;
atomic_store_8
(
&
pSyncNode
->
pingTimerStart
,
0
);
pSyncNode
->
FpPingTimer
=
syncNodePingTimerCb
;
pSyncNode
->
pingTimerCounter
=
0
;
pSyncNode
->
rpcClient
=
pSyncInfo
->
rpcClient
;
pSyncNode
->
FpSendMsg
=
pSyncInfo
->
FpSendMsg
;
pSyncNode
->
FpOnPing
=
syncNodeOnPingCb
;
pSyncNode
->
FpOnPingReply
=
syncNodeOnPingReplyCb
;
pSyncNode
->
FpOnRequestVote
=
syncNodeOnRequestVoteCb
;
...
...
@@ -97,10 +116,11 @@ void syncNodePingAll(SSyncNode* pSyncNode) {
sTrace
(
"syncNodePingAll %p "
,
pSyncNode
);
int32_t
ret
=
0
;
for
(
int
i
=
0
;
i
<
pSyncNode
->
syncCfg
.
replicaNum
;
++
i
)
{
SyncPing
*
pSyncPing
;
SRaftId
raftId
;
syncUtilnodeInfo2raftId
(
&
pSyncNode
->
syncCfg
.
nodeInfo
[
i
],
pSyncNode
->
vgId
,
&
raftId
);
ret
=
syncNodePing
(
pSyncNode
,
&
raftId
,
pSyncPing
);
SyncPing
*
pMsg
=
syncPingBuild
(
strlen
(
"ping"
)
+
1
);
memcpy
(
pMsg
->
data
,
"ping"
,
strlen
(
"ping"
)
+
1
);
syncUtilnodeInfo2raftId
(
&
pSyncNode
->
syncCfg
.
nodeInfo
[
i
],
pSyncNode
->
vgId
,
&
pMsg
->
destId
);
pMsg
->
srcId
=
pSyncNode
->
raftId
;
ret
=
syncNodePing
(
pSyncNode
,
&
pMsg
->
destId
,
pMsg
);
assert
(
ret
==
0
);
}
}
...
...
@@ -118,10 +138,11 @@ void syncNodePingPeers(SSyncNode* pSyncNode) {
void
syncNodePingSelf
(
SSyncNode
*
pSyncNode
)
{
int32_t
ret
=
0
;
SyncPing
*
pSyncPing
;
SRaftId
raftId
;
syncUtilnodeInfo2raftId
(
&
pSyncNode
->
me
,
pSyncNode
->
vgId
,
&
raftId
);
ret
=
syncNodePing
(
pSyncNode
,
&
raftId
,
pSyncPing
);
SyncPing
*
pMsg
=
syncPingBuild
(
strlen
(
"ping"
)
+
1
);
memcpy
(
pMsg
->
data
,
"ping"
,
strlen
(
"ping"
)
+
1
);
pMsg
->
destId
=
pSyncNode
->
raftId
;
pMsg
->
srcId
=
pSyncNode
->
raftId
;
ret
=
syncNodePing
(
pSyncNode
,
&
pMsg
->
destId
,
pMsg
);
assert
(
ret
==
0
);
}
...
...
@@ -147,9 +168,9 @@ int32_t syncNodeStopPingTimer(SSyncNode* pSyncNode) {
// ------ local funciton ---------
static
int32_t
syncNodePing
(
SSyncNode
*
pSyncNode
,
const
SRaftId
*
destRaftId
,
SyncPing
*
pMsg
)
{
int32_t
ret
=
0
;
SRpcMsg
*
rpcMsg
;
syncPing2RpcMsg
(
pMsg
,
rpcMsg
);
syncNodeSendMsgById
(
destRaftId
,
pSyncNode
,
rpcMsg
);
SRpcMsg
rpcMsg
;
syncPing2RpcMsg
(
pMsg
,
&
rpcMsg
);
syncNodeSendMsgById
(
destRaftId
,
pSyncNode
,
&
rpcMsg
);
return
ret
;
}
...
...
source/libs/sync/src/syncUtil.c
浏览文件 @
aaf5e20f
...
...
@@ -22,7 +22,7 @@
uint64_t
syncUtilAddr2U64
(
const
char
*
host
,
uint16_t
port
)
{
uint64_t
u64
;
uint32_t
hostU32
=
(
uint32_t
)
inet_addr
(
host
);
assert
(
hostU32
!=
(
uint32_t
)
-
1
);
//
assert(hostU32 != (uint32_t)-1);
u64
=
(((
uint64_t
)
hostU32
)
<<
32
)
|
(((
uint32_t
)
port
)
<<
16
);
return
u64
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录