Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
73d768d2
TDengine
项目概览
taosdata
/
TDengine
11 个月 前同步成功
通知
1179
Star
22014
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,发现更多精彩内容 >>
提交
73d768d2
编写于
3月 10, 2022
作者:
M
Minghao Li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
sync refactor
上级
901b5976
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
67 addition
and
52 deletion
+67
-52
source/libs/sync/inc/syncMessage.h
source/libs/sync/inc/syncMessage.h
+1
-1
source/libs/sync/inc/syncRaftEntry.h
source/libs/sync/inc/syncRaftEntry.h
+6
-2
source/libs/sync/inc/syncRaftLog.h
source/libs/sync/inc/syncRaftLog.h
+13
-28
source/libs/sync/src/syncMessage.c
source/libs/sync/src/syncMessage.c
+3
-3
source/libs/sync/src/syncRaftEntry.c
source/libs/sync/src/syncRaftEntry.c
+21
-6
source/libs/sync/src/syncRaftLog.c
source/libs/sync/src/syncRaftLog.c
+23
-12
未找到文件。
source/libs/sync/inc/syncMessage.h
浏览文件 @
73d768d2
...
...
@@ -83,7 +83,7 @@ typedef struct SyncPing {
char
data
[];
}
SyncPing
;
#define SYNC_PING_FIX_LEN (sizeof(uint32_t) + sizeof(uint32_t) + sizeof(SRaftId) + sizeof(SRaftId) + sizeof(uint32_t))
//
#define SYNC_PING_FIX_LEN (sizeof(uint32_t) + sizeof(uint32_t) + sizeof(SRaftId) + sizeof(SRaftId) + sizeof(uint32_t))
SyncPing
*
syncPingBuild
(
uint32_t
dataLen
);
void
syncPingDestroy
(
SyncPing
*
pMsg
);
...
...
source/libs/sync/inc/syncRaftEntry.h
浏览文件 @
73d768d2
...
...
@@ -46,8 +46,12 @@ char* syncEntrySerialize(const SSyncRaftEntry* pEntry, uint32_t* len);
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
);
// for debug
void
syncEntryPrint
(
const
SSyncRaftEntry
*
pEntry
);
void
syncEntryPrint2
(
char
*
s
,
const
SSyncRaftEntry
*
pEntry
);
void
syncEntryLog
(
const
SSyncRaftEntry
*
pEntry
);
void
syncEntryLog2
(
char
*
s
,
const
SSyncRaftEntry
*
pEntry
);
#ifdef __cplusplus
}
...
...
source/libs/sync/inc/syncRaftLog.h
浏览文件 @
73d768d2
...
...
@@ -32,39 +32,24 @@ typedef struct SSyncLogStoreData {
SWal
*
pWal
;
}
SSyncLogStoreData
;
SSyncLogStore
*
logStoreCreate
(
SSyncNode
*
pSyncNode
);
void
logStoreDestory
(
SSyncLogStore
*
pLogStore
);
// append one log entry
int32_t
logStoreAppendEntry
(
SSyncLogStore
*
pLogStore
,
SSyncRaftEntry
*
pEntry
);
// get one log entry, user need to free pEntry->pCont
SSyncLogStore
*
logStoreCreate
(
SSyncNode
*
pSyncNode
);
void
logStoreDestory
(
SSyncLogStore
*
pLogStore
);
int32_t
logStoreAppendEntry
(
SSyncLogStore
*
pLogStore
,
SSyncRaftEntry
*
pEntry
);
SSyncRaftEntry
*
logStoreGetEntry
(
SSyncLogStore
*
pLogStore
,
SyncIndex
index
);
// truncate log with index, entries after the given index (>=index) will be deleted
int32_t
logStoreTruncate
(
SSyncLogStore
*
pLogStore
,
SyncIndex
fromIndex
);
// return index of last entry
SyncIndex
logStoreLastIndex
(
SSyncLogStore
*
pLogStore
);
// return term of last entry
SyncTerm
logStoreLastTerm
(
SSyncLogStore
*
pLogStore
);
// update log store commit index with "index"
int32_t
logStoreUpdateCommitIndex
(
SSyncLogStore
*
pLogStore
,
SyncIndex
index
);
// return commit index of log
SyncIndex
logStoreGetCommitIndex
(
SSyncLogStore
*
pLogStore
);
int32_t
logStoreTruncate
(
SSyncLogStore
*
pLogStore
,
SyncIndex
fromIndex
);
SyncIndex
logStoreLastIndex
(
SSyncLogStore
*
pLogStore
);
SyncTerm
logStoreLastTerm
(
SSyncLogStore
*
pLogStore
);
int32_t
logStoreUpdateCommitIndex
(
SSyncLogStore
*
pLogStore
,
SyncIndex
index
);
SyncIndex
logStoreGetCommitIndex
(
SSyncLogStore
*
pLogStore
);
SSyncRaftEntry
*
logStoreGetLastEntry
(
SSyncLogStore
*
pLogStore
);
cJSON
*
logStore2Json
(
SSyncLogStore
*
pLogStore
);
char
*
logStore2Str
(
SSyncLogStore
*
pLogStore
);
cJSON
*
logStore2Json
(
SSyncLogStore
*
pLogStore
);
char
*
logStore2Str
(
SSyncLogStore
*
pLogStore
);
// for debug
void
logStorePrint
(
SSyncLogStore
*
pLogStore
);
void
logStorePrint2
(
char
*
s
,
SSyncLogStore
*
pLogStore
);
void
logStoreLog
(
SSyncLogStore
*
pLogStore
);
void
logStoreLog2
(
char
*
s
,
SSyncLogStore
*
pLogStore
);
#ifdef __cplusplus
}
...
...
source/libs/sync/src/syncMessage.c
浏览文件 @
73d768d2
...
...
@@ -150,7 +150,7 @@ SyncTimeout* syncTimeoutBuild2(ESyncTimeoutType timeoutType, uint64_t logicClock
// ---- message process SyncPing----
SyncPing
*
syncPingBuild
(
uint32_t
dataLen
)
{
uint32_t
bytes
=
SYNC_PING_FIX_LEN
+
dataLen
;
uint32_t
bytes
=
sizeof
(
SyncPing
)
+
dataLen
;
SyncPing
*
pMsg
=
malloc
(
bytes
);
memset
(
pMsg
,
0
,
bytes
);
pMsg
->
bytes
=
bytes
;
...
...
@@ -173,7 +173,7 @@ void syncPingSerialize(const SyncPing* pMsg, char* buf, uint32_t bufLen) {
void
syncPingDeserialize
(
const
char
*
buf
,
uint32_t
len
,
SyncPing
*
pMsg
)
{
memcpy
(
pMsg
,
buf
,
len
);
assert
(
len
==
pMsg
->
bytes
);
assert
(
pMsg
->
bytes
==
SYNC_PING_FIX_LEN
+
pMsg
->
dataLen
);
assert
(
pMsg
->
bytes
==
sizeof
(
SyncPing
)
+
pMsg
->
dataLen
);
}
void
syncPing2RpcMsg
(
const
SyncPing
*
pMsg
,
SRpcMsg
*
pRpcMsg
)
{
...
...
@@ -272,7 +272,7 @@ void syncPingReplySerialize(const SyncPingReply* pMsg, char* buf, uint32_t bufLe
void
syncPingReplyDeserialize
(
const
char
*
buf
,
uint32_t
len
,
SyncPingReply
*
pMsg
)
{
memcpy
(
pMsg
,
buf
,
len
);
assert
(
len
==
pMsg
->
bytes
);
assert
(
pMsg
->
bytes
==
SYNC_PING_FIX_LEN
+
pMsg
->
dataLen
);
assert
(
pMsg
->
bytes
==
sizeof
(
SyncPing
)
+
pMsg
->
dataLen
);
}
void
syncPingReply2RpcMsg
(
const
SyncPingReply
*
pMsg
,
SRpcMsg
*
pRpcMsg
)
{
...
...
source/libs/sync/src/syncRaftEntry.c
浏览文件 @
73d768d2
...
...
@@ -104,14 +104,29 @@ char* syncEntry2Str(const SSyncRaftEntry* pEntry) {
return
serialized
;
}
// for debug -----------
void
syncEntryPrint
(
const
SSyncRaftEntry
*
pEntry
)
{
char
*
s
=
syncEntry2Str
(
pEntry
);
sTrace
(
"%s"
,
s
);
free
(
s
);
char
*
serialized
=
syncEntry2Str
(
pEntry
);
printf
(
"syncEntryPrint | len:%lu | %s
\n
"
,
strlen
(
serialized
),
serialized
);
fflush
(
NULL
);
free
(
serialized
);
}
void
syncEntryPrint2
(
char
*
s
,
const
SSyncRaftEntry
*
pEntry
)
{
char
*
ss
=
syncEntry2Str
(
pEntry
);
sTrace
(
"%s | %s"
,
s
,
ss
);
free
(
ss
);
char
*
serialized
=
syncEntry2Str
(
pEntry
);
printf
(
"syncEntryPrint | len:%lu | %s | %s
\n
"
,
strlen
(
serialized
),
s
,
serialized
);
fflush
(
NULL
);
free
(
serialized
);
}
void
syncEntryLog
(
const
SSyncRaftEntry
*
pEntry
)
{
char
*
serialized
=
syncEntry2Str
(
pEntry
);
sTrace
(
"syncEntryPrint | len:%lu | %s"
,
strlen
(
serialized
),
serialized
);
free
(
serialized
);
}
void
syncEntryLog2
(
char
*
s
,
const
SSyncRaftEntry
*
pEntry
)
{
char
*
serialized
=
syncEntry2Str
(
pEntry
);
sTrace
(
"syncEntryPrint | len:%lu | %s | %s"
,
strlen
(
serialized
),
s
,
serialized
);
free
(
serialized
);
}
\ No newline at end of file
source/libs/sync/src/syncRaftLog.c
浏览文件 @
73d768d2
...
...
@@ -43,7 +43,6 @@ void logStoreDestory(SSyncLogStore* pLogStore) {
}
}
// append one log entry
int32_t
logStoreAppendEntry
(
SSyncLogStore
*
pLogStore
,
SSyncRaftEntry
*
pEntry
)
{
SSyncLogStoreData
*
pData
=
pLogStore
->
data
;
SWal
*
pWal
=
pData
->
pWal
;
...
...
@@ -61,7 +60,6 @@ int32_t logStoreAppendEntry(SSyncLogStore* pLogStore, SSyncRaftEntry* pEntry) {
free
(
serialized
);
}
// get one log entry, user need to free pEntry->pCont
SSyncRaftEntry
*
logStoreGetEntry
(
SSyncLogStore
*
pLogStore
,
SyncIndex
index
)
{
SSyncLogStoreData
*
pData
=
pLogStore
->
data
;
SWal
*
pWal
=
pData
->
pWal
;
...
...
@@ -77,14 +75,12 @@ SSyncRaftEntry* logStoreGetEntry(SSyncLogStore* pLogStore, SyncIndex index) {
return
pEntry
;
}
// truncate log with index, entries after the given index (>=index) will be deleted
int32_t
logStoreTruncate
(
SSyncLogStore
*
pLogStore
,
SyncIndex
fromIndex
)
{
SSyncLogStoreData
*
pData
=
pLogStore
->
data
;
SWal
*
pWal
=
pData
->
pWal
;
walRollback
(
pWal
,
fromIndex
);
}
// return index of last entry
SyncIndex
logStoreLastIndex
(
SSyncLogStore
*
pLogStore
)
{
SSyncLogStoreData
*
pData
=
pLogStore
->
data
;
SWal
*
pWal
=
pData
->
pWal
;
...
...
@@ -92,7 +88,6 @@ SyncIndex logStoreLastIndex(SSyncLogStore* pLogStore) {
return
lastIndex
;
}
// return term of last entry
SyncTerm
logStoreLastTerm
(
SSyncLogStore
*
pLogStore
)
{
SyncTerm
lastTerm
=
0
;
SSyncRaftEntry
*
pLastEntry
=
logStoreGetLastEntry
(
pLogStore
);
...
...
@@ -103,14 +98,12 @@ SyncTerm logStoreLastTerm(SSyncLogStore* pLogStore) {
return
lastTerm
;
}
// update log store commit index with "index"
int32_t
logStoreUpdateCommitIndex
(
SSyncLogStore
*
pLogStore
,
SyncIndex
index
)
{
SSyncLogStoreData
*
pData
=
pLogStore
->
data
;
SWal
*
pWal
=
pData
->
pWal
;
walCommit
(
pWal
,
index
);
}
// return commit index of log
SyncIndex
logStoreGetCommitIndex
(
SSyncLogStore
*
pLogStore
)
{
SSyncLogStoreData
*
pData
=
pLogStore
->
data
;
return
pData
->
pSyncNode
->
commitIndex
;
...
...
@@ -163,11 +156,29 @@ char* logStore2Str(SSyncLogStore* pLogStore) {
return
serialized
;
}
// for debug
// for debug
-----------------
void
logStorePrint
(
SSyncLogStore
*
pLogStore
)
{
char
*
s
=
logStore2Str
(
pLogStore
);
// sTrace("%s", s);
fprintf
(
stderr
,
"logStorePrint: [len:%lu]| %s
\n
"
,
strlen
(
s
),
s
);
char
*
serialized
=
logStore2Str
(
pLogStore
);
printf
(
"logStorePrint | len:%lu | %s
\n
"
,
strlen
(
serialized
),
serialized
);
fflush
(
NULL
);
free
(
serialized
);
}
void
logStorePrint2
(
char
*
s
,
SSyncLogStore
*
pLogStore
)
{
char
*
serialized
=
logStore2Str
(
pLogStore
);
printf
(
"logStorePrint | len:%lu | %s | %s
\n
"
,
strlen
(
serialized
),
s
,
serialized
);
fflush
(
NULL
);
free
(
serialized
);
}
free
(
s
);
void
logStoreLog
(
SSyncLogStore
*
pLogStore
)
{
char
*
serialized
=
logStore2Str
(
pLogStore
);
sTrace
(
"logStorePrint | len:%lu | %s"
,
strlen
(
serialized
),
serialized
);
free
(
serialized
);
}
void
logStoreLog2
(
char
*
s
,
SSyncLogStore
*
pLogStore
)
{
char
*
serialized
=
logStore2Str
(
pLogStore
);
sTrace
(
"logStorePrint | len:%lu | %s | %s"
,
strlen
(
serialized
),
s
,
serialized
);
free
(
serialized
);
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录