Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
1a789177
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1184
Star
22015
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
1a789177
编写于
3月 14, 2022
作者:
M
Minghao Li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
sync index
上级
51ceed98
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
72 addition
and
29 deletion
+72
-29
source/libs/sync/inc/syncRaftLog.h
source/libs/sync/inc/syncRaftLog.h
+3
-0
source/libs/sync/inc/syncUtil.h
source/libs/sync/inc/syncUtil.h
+2
-0
source/libs/sync/src/syncMain.c
source/libs/sync/src/syncMain.c
+27
-27
source/libs/sync/src/syncRaftLog.c
source/libs/sync/src/syncRaftLog.c
+1
-1
source/libs/sync/src/syncReplication.c
source/libs/sync/src/syncReplication.c
+19
-0
source/libs/sync/src/syncUtil.c
source/libs/sync/src/syncUtil.c
+10
-0
source/libs/sync/test/syncLogStoreTest.cpp
source/libs/sync/test/syncLogStoreTest.cpp
+10
-1
未找到文件。
source/libs/sync/inc/syncRaftLog.h
浏览文件 @
1a789177
...
...
@@ -27,6 +27,9 @@ extern "C" {
#include "syncRaftEntry.h"
#include "taosdef.h"
#define SYNC_INDEX_BEGIN 0
#define SYNC_INDEX_INVALID -1
typedef
struct
SSyncLogStoreData
{
SSyncNode
*
pSyncNode
;
SWal
*
pWal
;
...
...
source/libs/sync/inc/syncUtil.h
浏览文件 @
1a789177
...
...
@@ -52,6 +52,8 @@ const char* syncUtilState2String(ESyncState state);
bool
syncUtilCanPrint
(
char
c
);
char
*
syncUtilprintBin
(
char
*
ptr
,
uint32_t
len
);
char
*
syncUtilprintBin2
(
char
*
ptr
,
uint32_t
len
);
SyncIndex
syncUtilMinIndex
(
SyncIndex
a
,
SyncIndex
b
);
SyncIndex
syncUtilMaxIndex
(
SyncIndex
a
,
SyncIndex
b
);
#ifdef __cplusplus
}
...
...
source/libs/sync/src/syncMain.c
浏览文件 @
1a789177
...
...
@@ -327,33 +327,6 @@ char* syncNode2Str(const SSyncNode* pSyncNode) {
return
serialized
;
}
// for debug --------------
void
syncNodePrint
(
SSyncNode
*
pObj
)
{
char
*
serialized
=
syncNode2Str
(
pObj
);
printf
(
"syncNodePrint | len:%lu | %s
\n
"
,
strlen
(
serialized
),
serialized
);
fflush
(
NULL
);
free
(
serialized
);
}
void
syncNodePrint2
(
char
*
s
,
SSyncNode
*
pObj
)
{
char
*
serialized
=
syncNode2Str
(
pObj
);
printf
(
"syncNodePrint2 | len:%lu | %s | %s
\n
"
,
strlen
(
serialized
),
s
,
serialized
);
fflush
(
NULL
);
free
(
serialized
);
}
void
syncNodeLog
(
SSyncNode
*
pObj
)
{
char
*
serialized
=
syncNode2Str
(
pObj
);
sTrace
(
"syncNodeLog | len:%lu | %s"
,
strlen
(
serialized
),
serialized
);
free
(
serialized
);
}
void
syncNodeLog2
(
char
*
s
,
SSyncNode
*
pObj
)
{
char
*
serialized
=
syncNode2Str
(
pObj
);
sTrace
(
"syncNodeLog2 | len:%lu | %s | %s"
,
strlen
(
serialized
),
s
,
serialized
);
free
(
serialized
);
}
int32_t
syncNodeSendMsgById
(
const
SRaftId
*
destRaftId
,
SSyncNode
*
pSyncNode
,
SRpcMsg
*
pMsg
)
{
SEpSet
epSet
;
syncUtilraftId2EpSet
(
destRaftId
,
&
epSet
);
...
...
@@ -491,6 +464,33 @@ int32_t syncNodeStopHeartbeatTimer(SSyncNode* pSyncNode) {
return
0
;
}
// for debug --------------
void
syncNodePrint
(
SSyncNode
*
pObj
)
{
char
*
serialized
=
syncNode2Str
(
pObj
);
printf
(
"syncNodePrint | len:%lu | %s
\n
"
,
strlen
(
serialized
),
serialized
);
fflush
(
NULL
);
free
(
serialized
);
}
void
syncNodePrint2
(
char
*
s
,
SSyncNode
*
pObj
)
{
char
*
serialized
=
syncNode2Str
(
pObj
);
printf
(
"syncNodePrint2 | len:%lu | %s | %s
\n
"
,
strlen
(
serialized
),
s
,
serialized
);
fflush
(
NULL
);
free
(
serialized
);
}
void
syncNodeLog
(
SSyncNode
*
pObj
)
{
char
*
serialized
=
syncNode2Str
(
pObj
);
sTrace
(
"syncNodeLog | len:%lu | %s"
,
strlen
(
serialized
),
serialized
);
free
(
serialized
);
}
void
syncNodeLog2
(
char
*
s
,
SSyncNode
*
pObj
)
{
char
*
serialized
=
syncNode2Str
(
pObj
);
sTrace
(
"syncNodeLog2 | len:%lu | %s | %s"
,
strlen
(
serialized
),
s
,
serialized
);
free
(
serialized
);
}
// ------ local funciton ---------
static
int32_t
syncNodeOnPingCb
(
SSyncNode
*
ths
,
SyncPing
*
pMsg
)
{
int32_t
ret
=
0
;
...
...
source/libs/sync/src/syncRaftLog.c
浏览文件 @
1a789177
...
...
@@ -130,7 +130,7 @@ cJSON* logStore2Json(SSyncLogStore* pLogStore) {
cJSON_AddStringToObject
(
pRoot
,
"pSyncNode"
,
u64buf
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%p"
,
pData
->
pWal
);
cJSON_AddStringToObject
(
pRoot
,
"pWal"
,
u64buf
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%l
u
"
,
logStoreLastIndex
(
pLogStore
));
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%l
d
"
,
logStoreLastIndex
(
pLogStore
));
cJSON_AddStringToObject
(
pRoot
,
"LastIndex"
,
u64buf
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%lu"
,
logStoreLastTerm
(
pLogStore
));
cJSON_AddStringToObject
(
pRoot
,
"LastTerm"
,
u64buf
);
...
...
source/libs/sync/src/syncReplication.c
浏览文件 @
1a789177
...
...
@@ -14,7 +14,9 @@
*/
#include "syncReplication.h"
#include "syncIndexMgr.h"
#include "syncMessage.h"
#include "syncRaftEntry.h"
// TLA+ Spec
// AppendEntries(i, j) ==
...
...
@@ -42,7 +44,24 @@
// /\ UNCHANGED <<serverVars, candidateVars, leaderVars, logVars>>
//
int32_t
syncNodeAppendEntriesPeers
(
SSyncNode
*
pSyncNode
)
{
assert
(
pSyncNode
->
state
==
TAOS_SYNC_STATE_LEADER
);
int32_t
ret
=
0
;
for
(
int
i
=
0
;
i
<
pSyncNode
->
peersNum
;
++
i
)
{
SRaftId
*
pDestId
=
&
(
pSyncNode
->
peersId
[
i
]);
SyncIndex
nextIndex
=
syncIndexMgrGetIndex
(
pSyncNode
->
pNextIndex
,
pDestId
);
SyncIndex
preLogIndex
=
nextIndex
-
1
;
SyncTerm
preLogTerm
=
0
;
if
(
preLogIndex
>=
0
)
{
SSyncRaftEntry
*
pPreEntry
=
pSyncNode
->
pLogStore
->
getEntry
(
pSyncNode
->
pLogStore
,
preLogIndex
);
preLogTerm
=
pPreEntry
->
term
;
}
else
{
preLogTerm
=
0
;
}
// SyncTerm lastIndex =
// pSyncNode->pLogStore->getLastIndex < nextIndex ? pSyncNode->pLogStore->getLastIndex : nextIndex;
}
return
ret
;
}
...
...
source/libs/sync/src/syncUtil.c
浏览文件 @
1a789177
...
...
@@ -184,4 +184,14 @@ char* syncUtilprintBin2(char* ptr, uint32_t len) {
p
+=
n
;
}
return
s
;
}
SyncIndex
syncUtilMinIndex
(
SyncIndex
a
,
SyncIndex
b
)
{
SyncIndex
r
=
a
<
b
?
a
:
b
;
return
r
;
}
SyncIndex
syncUtilMaxIndex
(
SyncIndex
a
,
SyncIndex
b
)
{
SyncIndex
r
=
a
>
b
?
a
:
b
;
return
r
;
}
\ No newline at end of file
source/libs/sync/test/syncLogStoreTest.cpp
浏览文件 @
1a789177
...
...
@@ -81,7 +81,10 @@ SSyncNode* syncNodeInit() {
SSyncNode
*
syncInitTest
()
{
return
syncNodeInit
();
}
void
logStoreTest
()
{
logStorePrint
(
pSyncNode
->
pLogStore
);
logStorePrint2
((
char
*
)
"logStoreTest2"
,
pSyncNode
->
pLogStore
);
assert
(
pSyncNode
->
pLogStore
->
getLastIndex
(
pSyncNode
->
pLogStore
)
==
SYNC_INDEX_INVALID
);
for
(
int
i
=
0
;
i
<
5
;
++
i
)
{
int32_t
dataLen
=
10
;
SSyncRaftEntry
*
pEntry
=
syncEntryBuild
(
dataLen
);
...
...
@@ -97,6 +100,10 @@ void logStoreTest() {
// syncEntryPrint2((char*)"write entry:", pEntry);
pSyncNode
->
pLogStore
->
appendEntry
(
pSyncNode
->
pLogStore
,
pEntry
);
syncEntryDestory
(
pEntry
);
if
(
i
==
0
)
{
assert
(
pSyncNode
->
pLogStore
->
getLastIndex
(
pSyncNode
->
pLogStore
)
==
SYNC_INDEX_BEGIN
);
}
}
logStorePrint
(
pSyncNode
->
pLogStore
);
...
...
@@ -129,6 +136,8 @@ int main(int argc, char** argv) {
ret
=
syncEnvStart
();
assert
(
ret
==
0
);
taosRemoveDir
(
"./wal_test"
);
pSyncNode
=
syncInitTest
();
assert
(
pSyncNode
!=
NULL
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录