Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
00c0926c
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22017
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看板
提交
00c0926c
编写于
6月 23, 2022
作者:
M
Minghao Li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor(sync): hold wal handle with log store
上级
cdb6b242
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
60 addition
and
34 deletion
+60
-34
source/libs/sync/inc/syncRaftLog.h
source/libs/sync/inc/syncRaftLog.h
+5
-3
source/libs/sync/src/syncMain.c
source/libs/sync/src/syncMain.c
+6
-2
source/libs/sync/src/syncRaftCfg.c
source/libs/sync/src/syncRaftCfg.c
+21
-17
source/libs/sync/src/syncRaftLog.c
source/libs/sync/src/syncRaftLog.c
+28
-12
未找到文件。
source/libs/sync/inc/syncRaftLog.h
浏览文件 @
00c0926c
...
...
@@ -26,11 +26,13 @@ extern "C" {
#include "syncInt.h"
#include "syncRaftEntry.h"
#include "taosdef.h"
#include "wal.h"
typedef
struct
SSyncLogStoreData
{
SSyncNode
*
pSyncNode
;
SWal
*
pWal
;
SyncIndex
beginIndex
;
// valid begin index, default 0, may be set beginIndex > 0
SSyncNode
*
pSyncNode
;
SWal
*
pWal
;
SWalReadHandle
*
pWalHandle
;
SyncIndex
beginIndex
;
// valid begin index, default 0, may be set beginIndex > 0
}
SSyncLogStoreData
;
SSyncLogStore
*
logStoreCreate
(
SSyncNode
*
pSyncNode
);
...
...
source/libs/sync/src/syncMain.c
浏览文件 @
00c0926c
...
...
@@ -1311,6 +1311,10 @@ void syncNodeEventLog(const SSyncNode* pSyncNode, char* str) {
SyncIndex
logBeginIndex
=
pSyncNode
->
pLogStore
->
syncLogBeginIndex
(
pSyncNode
->
pLogStore
);
char
*
pCfgStr
=
syncCfg2SimpleStr
(
&
(
pSyncNode
->
pRaftCfg
->
cfg
));
char
*
printStr
=
""
;
if
(
pCfgStr
!=
NULL
)
{
printStr
=
pCfgStr
;
}
if
(
userStrLen
<
256
)
{
char
logBuf
[
256
+
256
];
...
...
@@ -1322,7 +1326,7 @@ void syncNodeEventLog(const SSyncNode* pSyncNode, char* str) {
pSyncNode
->
vgId
,
syncUtilState2String
(
pSyncNode
->
state
),
str
,
pSyncNode
->
pRaftStore
->
currentTerm
,
pSyncNode
->
commitIndex
,
logBeginIndex
,
logLastIndex
,
snapshot
.
lastApplyIndex
,
pSyncNode
->
pRaftCfg
->
isStandBy
,
pSyncNode
->
replicaNum
,
pSyncNode
->
pRaftCfg
->
lastConfigIndex
,
pSyncNode
->
changing
,
p
Cfg
Str
);
pSyncNode
->
changing
,
p
rint
Str
);
}
else
{
snprintf
(
logBuf
,
sizeof
(
logBuf
),
"%s"
,
str
);
}
...
...
@@ -1339,7 +1343,7 @@ void syncNodeEventLog(const SSyncNode* pSyncNode, char* str) {
pSyncNode
->
vgId
,
syncUtilState2String
(
pSyncNode
->
state
),
str
,
pSyncNode
->
pRaftStore
->
currentTerm
,
pSyncNode
->
commitIndex
,
logBeginIndex
,
logLastIndex
,
snapshot
.
lastApplyIndex
,
pSyncNode
->
pRaftCfg
->
isStandBy
,
pSyncNode
->
replicaNum
,
pSyncNode
->
pRaftCfg
->
lastConfigIndex
,
pSyncNode
->
changing
,
p
Cfg
Str
);
pSyncNode
->
changing
,
p
rint
Str
);
}
else
{
snprintf
(
s
,
len
,
"%s"
,
str
);
}
...
...
source/libs/sync/src/syncRaftCfg.c
浏览文件 @
00c0926c
...
...
@@ -107,26 +107,30 @@ char *syncCfg2Str(SSyncCfg *pSyncCfg) {
}
char
*
syncCfg2SimpleStr
(
SSyncCfg
*
pSyncCfg
)
{
int32_t
len
=
512
;
char
*
s
=
taosMemoryMalloc
(
len
);
memset
(
s
,
0
,
len
);
snprintf
(
s
,
len
,
"{replica-num:%d, my-index:%d, "
,
pSyncCfg
->
replicaNum
,
pSyncCfg
->
myIndex
);
char
*
p
=
s
+
strlen
(
s
);
for
(
int
i
=
0
;
i
<
pSyncCfg
->
replicaNum
;
++
i
)
{
/*
if (p + 128 + 32 > s + len) {
break;
if
(
pSyncCfg
!=
NULL
)
{
int32_t
len
=
512
;
char
*
s
=
taosMemoryMalloc
(
len
);
memset
(
s
,
0
,
len
);
snprintf
(
s
,
len
,
"{replica-num:%d, my-index:%d, "
,
pSyncCfg
->
replicaNum
,
pSyncCfg
->
myIndex
);
char
*
p
=
s
+
strlen
(
s
);
for
(
int
i
=
0
;
i
<
pSyncCfg
->
replicaNum
;
++
i
)
{
/*
if (p + 128 + 32 > s + len) {
break;
}
*/
char
buf
[
128
+
32
];
snprintf
(
buf
,
sizeof
(
buf
),
"%s:%d, "
,
pSyncCfg
->
nodeInfo
[
i
].
nodeFqdn
,
pSyncCfg
->
nodeInfo
[
i
].
nodePort
);
strncpy
(
p
,
buf
,
sizeof
(
buf
));
p
=
s
+
strlen
(
s
);
}
*/
char
buf
[
128
+
32
];
snprintf
(
buf
,
sizeof
(
buf
),
"%s:%d, "
,
pSyncCfg
->
nodeInfo
[
i
].
nodeFqdn
,
pSyncCfg
->
nodeInfo
[
i
].
nodePort
);
strncpy
(
p
,
buf
,
sizeof
(
buf
));
p
=
s
+
strlen
(
s
);
strcpy
(
p
-
2
,
"}"
);
return
s
;
}
strcpy
(
p
-
2
,
"}"
);
return
s
;
return
NULL
;
}
int32_t
syncCfgFromJson
(
const
cJSON
*
pRoot
,
SSyncCfg
*
pSyncCfg
)
{
...
...
source/libs/sync/src/syncRaftLog.c
浏览文件 @
00c0926c
...
...
@@ -16,7 +16,6 @@
#include "syncRaftLog.h"
#include "syncRaftCfg.h"
#include "syncRaftStore.h"
#include "wal.h"
// refactor, log[0 .. n] ==> log[m .. n]
static
int32_t
raftLogSetBeginIndex
(
struct
SSyncLogStore
*
pLogStore
,
SyncIndex
beginIndex
);
...
...
@@ -233,7 +232,8 @@ static int32_t raftLogGetEntry(struct SSyncLogStore* pLogStore, SyncIndex index,
*
ppEntry
=
NULL
;
SWalReadHandle
*
pWalHandle
=
walOpenReadHandle
(
pWal
);
// SWalReadHandle* pWalHandle = walOpenReadHandle(pWal);
SWalReadHandle
*
pWalHandle
=
pData
->
pWalHandle
;
if
(
pWalHandle
==
NULL
)
{
return
-
1
;
}
...
...
@@ -256,9 +256,11 @@ static int32_t raftLogGetEntry(struct SSyncLogStore* pLogStore, SyncIndex index,
}
}
while
(
0
);
int32_t
saveErr
=
terrno
;
walCloseReadHandle
(
pWalHandle
);
terrno
=
saveErr
;
/*
int32_t saveErr = terrno;
walCloseReadHandle(pWalHandle);
terrno = saveErr;
*/
return
code
;
}
...
...
@@ -274,9 +276,11 @@ static int32_t raftLogGetEntry(struct SSyncLogStore* pLogStore, SyncIndex index,
ASSERT
((
*
ppEntry
)
->
dataLen
==
pWalHandle
->
pHead
->
head
.
bodyLen
);
memcpy
((
*
ppEntry
)
->
data
,
pWalHandle
->
pHead
->
head
.
body
,
pWalHandle
->
pHead
->
head
.
bodyLen
);
int32_t
saveErr
=
terrno
;
walCloseReadHandle
(
pWalHandle
);
terrno
=
saveErr
;
/*
int32_t saveErr = terrno;
walCloseReadHandle(pWalHandle);
terrno = saveErr;
*/
return
code
;
}
...
...
@@ -319,6 +323,10 @@ SSyncLogStore* logStoreCreate(SSyncNode* pSyncNode) {
SSyncLogStoreData
*
pData
=
pLogStore
->
data
;
pData
->
pSyncNode
=
pSyncNode
;
pData
->
pWal
=
pSyncNode
->
pWal
;
ASSERT
(
pData
->
pWal
!=
NULL
);
pData
->
pWalHandle
=
walOpenReadHandle
(
pData
->
pWal
);
ASSERT
(
pData
->
pWalHandle
!=
NULL
);
SyncIndex
firstVer
=
walGetFirstVer
(
pData
->
pWal
);
SyncIndex
lastVer
=
walGetLastVer
(
pData
->
pWal
);
...
...
@@ -357,6 +365,11 @@ SSyncLogStore* logStoreCreate(SSyncNode* pSyncNode) {
void
logStoreDestory
(
SSyncLogStore
*
pLogStore
)
{
if
(
pLogStore
!=
NULL
)
{
SSyncLogStoreData
*
pData
=
pLogStore
->
data
;
if
(
pData
->
pWalHandle
!=
NULL
)
{
walCloseReadHandle
(
pData
->
pWalHandle
);
}
taosMemoryFree
(
pLogStore
->
data
);
taosMemoryFree
(
pLogStore
);
}
...
...
@@ -405,7 +418,8 @@ SSyncRaftEntry* logStoreGetEntry(SSyncLogStore* pLogStore, SyncIndex index) {
SWal
*
pWal
=
pData
->
pWal
;
if
(
index
>=
SYNC_INDEX_BEGIN
&&
index
<=
logStoreLastIndex
(
pLogStore
))
{
SWalReadHandle
*
pWalHandle
=
walOpenReadHandle
(
pWal
);
// SWalReadHandle* pWalHandle = walOpenReadHandle(pWal);
SWalReadHandle
*
pWalHandle
=
pData
->
pWalHandle
;
ASSERT
(
pWalHandle
!=
NULL
);
int32_t
code
=
walReadWithHandle
(
pWalHandle
,
index
);
...
...
@@ -441,9 +455,11 @@ SSyncRaftEntry* logStoreGetEntry(SSyncLogStore* pLogStore, SyncIndex index) {
ASSERT
(
pEntry
->
dataLen
==
pWalHandle
->
pHead
->
head
.
bodyLen
);
memcpy
(
pEntry
->
data
,
pWalHandle
->
pHead
->
head
.
body
,
pWalHandle
->
pHead
->
head
.
bodyLen
);
int32_t
saveErr
=
terrno
;
walCloseReadHandle
(
pWalHandle
);
terrno
=
saveErr
;
/*
int32_t saveErr = terrno;
walCloseReadHandle(pWalHandle);
terrno = saveErr;
*/
return
pEntry
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录