Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
889d1339
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
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看板
提交
889d1339
编写于
3月 10, 2022
作者:
M
Minghao Li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
sync refactor
上级
ebeb4bb7
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
47 addition
and
27 deletion
+47
-27
source/libs/sync/inc/syncRaftEntry.h
source/libs/sync/inc/syncRaftEntry.h
+1
-0
source/libs/sync/src/syncRaftEntry.c
source/libs/sync/src/syncRaftEntry.c
+6
-0
source/libs/sync/src/syncRaftLog.c
source/libs/sync/src/syncRaftLog.c
+19
-15
source/libs/sync/test/syncLogStoreTest.cpp
source/libs/sync/test/syncLogStoreTest.cpp
+21
-12
未找到文件。
source/libs/sync/inc/syncRaftEntry.h
浏览文件 @
889d1339
...
...
@@ -47,6 +47,7 @@ SSyncRaftEntry* syncEntryDeserialize(const char* buf, uint32_t len);
cJSON
*
syncEntry2Json
(
const
SSyncRaftEntry
*
pEntry
);
char
*
syncEntry2Str
(
const
SSyncRaftEntry
*
pEntry
);
void
syncEntryPrint
(
const
SSyncRaftEntry
*
pEntry
);
void
syncEntryPrint2
(
char
*
s
,
const
SSyncRaftEntry
*
pEntry
);
#ifdef __cplusplus
}
...
...
source/libs/sync/src/syncRaftEntry.c
浏览文件 @
889d1339
...
...
@@ -109,3 +109,9 @@ void syncEntryPrint(const SSyncRaftEntry* pEntry) {
sTrace
(
"%s"
,
s
);
free
(
s
);
}
void
syncEntryPrint2
(
char
*
s
,
const
SSyncRaftEntry
*
pEntry
)
{
char
*
ss
=
syncEntry2Str
(
pEntry
);
sTrace
(
"%s | %s"
,
s
,
ss
);
free
(
ss
);
}
\ No newline at end of file
source/libs/sync/src/syncRaftLog.c
浏览文件 @
889d1339
...
...
@@ -53,9 +53,11 @@ int32_t logStoreAppendEntry(SSyncLogStore* pLogStore, SSyncRaftEntry* pEntry) {
char
*
serialized
=
syncEntrySerialize
(
pEntry
,
&
len
);
assert
(
serialized
!=
NULL
);
walWrite
(
pWal
,
pEntry
->
index
,
pEntry
->
msgType
,
serialized
,
len
);
walFsync
(
pWal
,
true
);
int
code
;
code
=
walWrite
(
pWal
,
pEntry
->
index
,
pEntry
->
msgType
,
serialized
,
len
);
assert
(
code
==
0
);
walFsync
(
pWal
,
true
);
free
(
serialized
);
}
...
...
@@ -84,23 +86,20 @@ int32_t logStoreTruncate(SSyncLogStore* pLogStore, SyncIndex fromIndex) {
// return index of last entry
SyncIndex
logStoreLastIndex
(
SSyncLogStore
*
pLogStore
)
{
/*
SSyncRaftEntry* pLastEntry = logStoreGetLastEntry(pLogStore);
SyncIndex lastIndex = pLastEntry->index;
free(pLastEntry);
*/
SSyncLogStoreData
*
pData
=
pLogStore
->
data
;
SWal
*
pWal
=
pData
->
pWal
;
int64_t
last
=
walGetLastVer
(
pWal
);
SyncIndex
lastIndex
=
last
<
0
?
0
:
last
;
SyncIndex
lastIndex
=
walGetLastVer
(
pWal
);
return
lastIndex
;
}
// return term of last entry
SyncTerm
logStoreLastTerm
(
SSyncLogStore
*
pLogStore
)
{
SyncTerm
lastTerm
=
0
;
SSyncRaftEntry
*
pLastEntry
=
logStoreGetLastEntry
(
pLogStore
);
SyncTerm
lastTerm
=
pLastEntry
->
term
;
if
(
pLastEntry
!=
NULL
)
{
lastTerm
=
pLastEntry
->
term
;
free
(
pLastEntry
);
}
return
lastTerm
;
}
...
...
@@ -121,8 +120,11 @@ SSyncRaftEntry* logStoreGetLastEntry(SSyncLogStore* pLogStore) {
SSyncLogStoreData
*
pData
=
pLogStore
->
data
;
SWal
*
pWal
=
pData
->
pWal
;
SyncIndex
lastIndex
=
walGetLastVer
(
pWal
);
SSyncRaftEntry
*
pEntry
;
SSyncRaftEntry
*
pEntry
=
NULL
;
if
(
lastIndex
>
0
)
{
pEntry
=
logStoreGetEntry
(
pLogStore
,
lastIndex
);
}
return
pEntry
;
}
...
...
@@ -143,7 +145,7 @@ cJSON* logStore2Json(SSyncLogStore* pLogStore) {
cJSON
*
pEntries
=
cJSON_CreateArray
();
cJSON_AddItemToObject
(
pRoot
,
"pEntries"
,
pEntries
);
SyncIndex
lastIndex
=
logStoreLastIndex
(
pLogStore
);
for
(
SyncIndex
i
=
1
;
i
<=
lastIndex
;
++
i
)
{
for
(
SyncIndex
i
=
0
;
i
<=
lastIndex
;
++
i
)
{
SSyncRaftEntry
*
pEntry
=
logStoreGetEntry
(
pLogStore
,
i
);
cJSON_AddItemToArray
(
pEntries
,
syncEntry2Json
(
pEntry
));
syncEntryDestory
(
pEntry
);
...
...
@@ -164,6 +166,8 @@ char* logStore2Str(SSyncLogStore* pLogStore) {
// for debug
void
logStorePrint
(
SSyncLogStore
*
pLogStore
)
{
char
*
s
=
logStore2Str
(
pLogStore
);
sTrace
(
"%s"
,
s
);
// sTrace("%s", s);
fprintf
(
stderr
,
"logStorePrint: [len:%lu]| %s
\n
"
,
strlen
(
s
),
s
);
free
(
s
);
}
\ No newline at end of file
source/libs/sync/test/syncLogStoreTest.cpp
浏览文件 @
889d1339
...
...
@@ -35,16 +35,19 @@ SSyncNode* syncNodeInit() {
syncInfo
.
pFsm
=
pFsm
;
snprintf
(
syncInfo
.
path
,
sizeof
(
syncInfo
.
path
),
"%s"
,
"./"
);
int
code
=
walInit
();
assert
(
code
==
0
);
SWalCfg
walCfg
;
memset
(
&
walCfg
,
0
,
sizeof
(
SWalCfg
));
walCfg
.
vgId
=
syncInfo
.
vgId
;
walCfg
.
fsyncPeriod
=
1000
;
walCfg
.
retentionPeriod
=
1000
;
walCfg
.
rollPeriod
=
1000
;
walCfg
.
retentionSize
=
1000
00
;
walCfg
.
segSize
=
1000
00
;
walCfg
.
level
=
TAOS_WAL_
WRITE
;
walCfg
.
retentionSize
=
1000
;
walCfg
.
segSize
=
1000
;
walCfg
.
level
=
TAOS_WAL_
FSYNC
;
pWal
=
walOpen
(
"./wal_test"
,
&
walCfg
);
assert
(
pWal
!=
NULL
);
syncInfo
.
pWal
=
pWal
;
...
...
@@ -80,8 +83,20 @@ SSyncNode* syncInitTest() { return syncNodeInit(); }
void
logStoreTest
()
{
logStorePrint
(
pSyncNode
->
pLogStore
);
for
(
int
i
=
0
;
i
<
5
;
++
i
)
{
SSyncRaftEntry
*
pEntry
;
int32_t
dataLen
=
10
;
SSyncRaftEntry
*
pEntry
=
syncEntryBuild
(
dataLen
);
assert
(
pEntry
!=
NULL
);
pEntry
->
msgType
=
1
;
pEntry
->
originalRpcType
=
2
;
pEntry
->
seqNum
=
3
;
pEntry
->
isWeak
=
true
;
pEntry
->
term
=
100
;
pEntry
->
index
=
pSyncNode
->
pLogStore
->
getLastIndex
(
pSyncNode
->
pLogStore
)
+
1
;
snprintf
(
pEntry
->
data
,
dataLen
,
"value%d"
,
i
);
//syncEntryPrint2((char*)"write entry:", pEntry);
pSyncNode
->
pLogStore
->
appendEntry
(
pSyncNode
->
pLogStore
,
pEntry
);
syncEntryDestory
(
pEntry
);
}
logStorePrint
(
pSyncNode
->
pLogStore
);
...
...
@@ -117,16 +132,10 @@ int main(int argc, char** argv) {
pSyncNode
=
syncInitTest
();
assert
(
pSyncNode
!=
NULL
);
syncNodePrint
((
char
*
)
"syncLogStoreTest"
,
pSyncNode
);
initRaftId
(
pSyncNode
);
//--------------------------------------------------------------
//syncNodePrint((char*)"syncLogStoreTest", pSyncNode);
//initRaftId(pSyncNode);
logStoreTest
();
//--------------------------------------------------------------
// walClose(pWal);
return
0
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录