Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
ee43a70c
T
TDengine
项目概览
taosdata
/
TDengine
接近 2 年 前同步成功
通知
1192
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看板
提交
ee43a70c
编写于
3月 02, 2022
作者:
M
Minghao Li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
sync modify timer
上级
aaf5e20f
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
76 addition
and
36 deletion
+76
-36
source/libs/sync/inc/syncInt.h
source/libs/sync/inc/syncInt.h
+15
-15
source/libs/sync/inc/syncMessage.h
source/libs/sync/inc/syncMessage.h
+4
-0
source/libs/sync/src/syncIO.c
source/libs/sync/src/syncIO.c
+6
-5
source/libs/sync/src/syncMain.c
source/libs/sync/src/syncMain.c
+34
-15
source/libs/sync/src/syncMessage.c
source/libs/sync/src/syncMessage.c
+14
-0
source/libs/sync/test/syncPingTest.cpp
source/libs/sync/test/syncPingTest.cpp
+3
-1
未找到文件。
source/libs/sync/inc/syncInt.h
浏览文件 @
ee43a70c
...
...
@@ -48,23 +48,23 @@ extern int32_t sDebugFlag;
taosPrintLog("SYN WARN ", sDebugFlag, __VA_ARGS__); \
} \
}
#define sInfo(...) \
{ \
if (sDebugFlag & DEBUG_INFO) { \
taosPrintLog("SYN ", sDebugFlag, __VA_ARGS__); \
} \
#define sInfo(...)
\
{
\
if (sDebugFlag & DEBUG_INFO) {
\
taosPrintLog("SYN
INFO
", sDebugFlag, __VA_ARGS__); \
}
\
}
#define sDebug(...) \
{ \
if (sDebugFlag & DEBUG_DEBUG) { \
taosPrintLog("SYN ", sDebugFlag, __VA_ARGS__); \
} \
#define sDebug(...)
\
{
\
if (sDebugFlag & DEBUG_DEBUG) {
\
taosPrintLog("SYN
DEBUG
", sDebugFlag, __VA_ARGS__); \
}
\
}
#define sTrace(...) \
{ \
if (sDebugFlag & DEBUG_TRACE) { \
taosPrintLog("SYN ", sDebugFlag, __VA_ARGS__); \
} \
#define sTrace(...)
\
{
\
if (sDebugFlag & DEBUG_TRACE) {
\
taosPrintLog("SYN
TRACE
", sDebugFlag, __VA_ARGS__); \
}
\
}
struct
SRaft
;
...
...
source/libs/sync/inc/syncMessage.h
浏览文件 @
ee43a70c
...
...
@@ -72,6 +72,10 @@ void syncPingFromRpcMsg(const SRpcMsg* pRpcMsg, SyncPing* pMsg);
cJSON
*
syncPing2Json
(
const
SyncPing
*
pMsg
);
SyncPing
*
syncPingBuild2
(
const
SRaftId
*
srcId
,
const
SRaftId
*
destId
,
const
char
*
str
);
SyncPing
*
syncPingBuild3
(
const
SRaftId
*
srcId
,
const
SRaftId
*
destId
);
typedef
struct
SyncPingReply
{
uint32_t
bytes
;
uint32_t
msgType
;
...
...
source/libs/sync/src/syncIO.c
浏览文件 @
ee43a70c
...
...
@@ -38,6 +38,7 @@ static void syncIOTick(void *param, void *tmrId);
// ----------------------------
int32_t
syncIOSendMsg
(
void
*
handle
,
const
SEpSet
*
pEpSet
,
SRpcMsg
*
pMsg
)
{
sTrace
(
"syncIOSendMsg ... "
);
pMsg
->
handle
=
NULL
;
rpcSendRequest
(
handle
,
pEpSet
,
pMsg
,
NULL
);
return
0
;
...
...
@@ -74,7 +75,7 @@ static void syncIOTick(void *param, void *tmrId) {
taosWriteQitem
(
io
->
pMsgQ
,
pTemp
);
taosTmrReset
(
syncIOTick
,
1000
,
io
,
io
->
syncTimerManager
,
io
->
syncTimer
);
taosTmrReset
(
syncIOTick
,
1000
,
io
,
io
->
syncTimerManager
,
&
io
->
syncTimer
);
}
static
void
*
syncIOConsumer
(
void
*
param
)
{
...
...
@@ -191,7 +192,7 @@ static int32_t doSyncIOStart(SSyncIO *io) {
{
SRpcInit
rpcInit
;
memset
(
&
rpcInit
,
0
,
sizeof
(
rpcInit
));
rpcInit
.
localPort
=
3800
0
;
rpcInit
.
localPort
=
701
0
;
rpcInit
.
label
=
"SYNC-IO-SERVER"
;
rpcInit
.
numOfThreads
=
1
;
rpcInit
.
cfp
=
syncIODoRequest
;
...
...
@@ -209,7 +210,7 @@ static int32_t doSyncIOStart(SSyncIO *io) {
}
io
->
epSet
.
inUse
=
0
;
addEpIntoEpSet
(
&
io
->
epSet
,
"127.0.0.1"
,
3800
0
);
addEpIntoEpSet
(
&
io
->
epSet
,
"127.0.0.1"
,
701
0
);
// start consumer thread
{
...
...
@@ -221,8 +222,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
浏览文件 @
ee43a70c
...
...
@@ -113,37 +113,36 @@ void syncNodeClose(SSyncNode* pSyncNode) {
}
void
syncNodePingAll
(
SSyncNode
*
pSyncNode
)
{
sTrace
(
"syncNodePingAll %p "
,
pSyncNode
);
sTrace
(
"syncNodePingAll
pSyncNode:
%p "
,
pSyncNode
);
int32_t
ret
=
0
;
for
(
int
i
=
0
;
i
<
pSyncNode
->
syncCfg
.
replicaNum
;
++
i
)
{
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
);
SRaftId
destId
;
syncUtilnodeInfo2raftId
(
&
pSyncNode
->
syncCfg
.
nodeInfo
[
i
],
pSyncNode
->
vgId
,
&
destId
);
SyncPing
*
pMsg
=
syncPingBuild3
(
&
pSyncNode
->
raftId
,
&
destId
);
ret
=
syncNodePing
(
pSyncNode
,
&
destId
,
pMsg
);
assert
(
ret
==
0
);
syncPingDestroy
(
pMsg
);
}
}
void
syncNodePingPeers
(
SSyncNode
*
pSyncNode
)
{
int32_t
ret
=
0
;
for
(
int
i
=
0
;
i
<
pSyncNode
->
peersNum
;
++
i
)
{
S
yncPing
*
pSyncPing
;
SRaftId
raftId
;
syncUtilnodeInfo2raftId
(
&
pSyncNode
->
peers
[
i
],
pSyncNode
->
vgId
,
&
raf
tId
);
ret
=
syncNodePing
(
pSyncNode
,
&
raftId
,
pSyncPin
g
);
S
RaftId
destId
;
syncUtilnodeInfo2raftId
(
&
pSyncNode
->
peers
[
i
],
pSyncNode
->
vgId
,
&
destId
)
;
SyncPing
*
pMsg
=
syncPingBuild3
(
&
pSyncNode
->
raftId
,
&
des
tId
);
ret
=
syncNodePing
(
pSyncNode
,
&
destId
,
pMs
g
);
assert
(
ret
==
0
);
syncPingDestroy
(
pMsg
);
}
}
void
syncNodePingSelf
(
SSyncNode
*
pSyncNode
)
{
int32_t
ret
=
0
;
SyncPing
*
pMsg
=
syncPingBuild
(
strlen
(
"ping"
)
+
1
);
memcpy
(
pMsg
->
data
,
"ping"
,
strlen
(
"ping"
)
+
1
);
pMsg
->
destId
=
pSyncNode
->
raftId
;
pMsg
->
srcId
=
pSyncNode
->
raftId
;
int32_t
ret
;
SyncPing
*
pMsg
=
syncPingBuild3
(
&
pSyncNode
->
raftId
,
&
pSyncNode
->
raftId
);
ret
=
syncNodePing
(
pSyncNode
,
&
pMsg
->
destId
,
pMsg
);
assert
(
ret
==
0
);
syncPingDestroy
(
pMsg
);
}
int32_t
syncNodeStartPingTimer
(
SSyncNode
*
pSyncNode
)
{
...
...
@@ -167,10 +166,29 @@ int32_t syncNodeStopPingTimer(SSyncNode* pSyncNode) {
// ------ local funciton ---------
static
int32_t
syncNodePing
(
SSyncNode
*
pSyncNode
,
const
SRaftId
*
destRaftId
,
SyncPing
*
pMsg
)
{
sTrace
(
"syncNodePing pSyncNode:%p "
,
pSyncNode
);
int32_t
ret
=
0
;
SRpcMsg
rpcMsg
;
syncPing2RpcMsg
(
pMsg
,
&
rpcMsg
);
syncNodeSendMsgById
(
destRaftId
,
pSyncNode
,
&
rpcMsg
);
{
cJSON
*
pJson
=
syncPing2Json
(
pMsg
);
char
*
serialized
=
cJSON_Print
(
pJson
);
sTrace
(
"syncNodePing pMsg:%s "
,
serialized
);
free
(
serialized
);
cJSON_Delete
(
pJson
);
}
{
SyncPing
*
pMsg2
=
rpcMsg
.
pCont
;
cJSON
*
pJson
=
syncPing2Json
(
pMsg2
);
char
*
serialized
=
cJSON_Print
(
pJson
);
sTrace
(
"syncNodePing pMsg2:%s "
,
serialized
);
free
(
serialized
);
cJSON_Delete
(
pJson
);
}
return
ret
;
}
...
...
@@ -185,6 +203,7 @@ static int32_t syncNodeAppendEntries(SSyncNode* ths, const SyncAppendEntries* pM
}
static
int32_t
syncNodeSendMsgById
(
const
SRaftId
*
destRaftId
,
SSyncNode
*
pSyncNode
,
SRpcMsg
*
pMsg
)
{
sTrace
(
"syncNodeSendMsgById pSyncNode:%p "
,
pSyncNode
);
SEpSet
epSet
;
syncUtilraftId2EpSet
(
destRaftId
,
&
epSet
);
pSyncNode
->
FpSendMsg
(
pSyncNode
->
rpcClient
,
&
epSet
,
pMsg
);
...
...
source/libs/sync/src/syncMessage.c
浏览文件 @
ee43a70c
...
...
@@ -80,6 +80,20 @@ cJSON* syncPing2Json(const SyncPing* pMsg) {
return
pJson
;
}
SyncPing
*
syncPingBuild2
(
const
SRaftId
*
srcId
,
const
SRaftId
*
destId
,
const
char
*
str
)
{
uint32_t
dataLen
=
strlen
(
str
)
+
1
;
SyncPing
*
pMsg
=
syncPingBuild
(
dataLen
);
pMsg
->
srcId
=
*
srcId
;
pMsg
->
destId
=
*
destId
;
snprintf
(
pMsg
->
data
,
pMsg
->
dataLen
,
"%s"
,
str
);
return
pMsg
;
}
SyncPing
*
syncPingBuild3
(
const
SRaftId
*
srcId
,
const
SRaftId
*
destId
)
{
SyncPing
*
pMsg
=
syncPingBuild2
(
srcId
,
destId
,
"ping"
);
return
pMsg
;
}
// ---- message process SyncPingReply----
SyncPingReply
*
syncPingReplyBuild
(
uint32_t
dataLen
)
{
uint32_t
bytes
=
SYNC_PING_REPLY_FIX_LEN
+
dataLen
;
...
...
source/libs/sync/test/syncPingTest.cpp
浏览文件 @
ee43a70c
...
...
@@ -25,7 +25,7 @@ SSyncNode* doSync() {
SSyncCfg
*
pCfg
=
&
syncInfo
.
syncCfg
;
pCfg
->
myIndex
=
0
;
pCfg
->
replicaNum
=
3
;
pCfg
->
replicaNum
=
1
;
pCfg
->
nodeInfo
[
0
].
nodePort
=
7010
;
taosGetFqdn
(
pCfg
->
nodeInfo
[
0
].
nodeFqdn
);
...
...
@@ -63,6 +63,7 @@ int main() {
ret
=
syncEnvStart
();
assert
(
ret
==
0
);
/*
SSyncNode* pSyncNode = doSync();
ret = syncNodeStartPingTimer(pSyncNode);
...
...
@@ -72,6 +73,7 @@ int main() {
ret = syncNodeStopPingTimer(pSyncNode);
assert(ret == 0);
*/
while
(
1
)
{
taosMsleep
(
1000
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录