Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
db4e02c7
T
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1184
Star
22015
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
db4e02c7
编写于
6月 17, 2022
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: add log to debug mnode sync
上级
ab2f2686
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
62 addition
and
73 deletion
+62
-73
source/dnode/mnode/impl/src/mndSync.c
source/dnode/mnode/impl/src/mndSync.c
+7
-23
source/dnode/mnode/impl/src/mndTrans.c
source/dnode/mnode/impl/src/mndTrans.c
+4
-9
source/dnode/mnode/impl/test/sdb/sdbTest.cpp
source/dnode/mnode/impl/test/sdb/sdbTest.cpp
+16
-8
source/dnode/mnode/sdb/inc/sdb.h
source/dnode/mnode/sdb/inc/sdb.h
+5
-9
source/dnode/mnode/sdb/src/sdb.c
source/dnode/mnode/sdb/src/sdb.c
+16
-19
source/dnode/mnode/sdb/src/sdbFile.c
source/dnode/mnode/sdb/src/sdbFile.c
+6
-2
source/libs/sync/src/syncSnapshot.c
source/libs/sync/src/syncSnapshot.c
+8
-3
未找到文件。
source/dnode/mnode/impl/src/mndSync.c
浏览文件 @
db4e02c7
...
...
@@ -46,13 +46,14 @@ void mndSyncCommitMsg(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbM
int32_t
transId
=
sdbGetIdFromRaw
(
pMnode
->
pSdb
,
pRaw
);
pMgmt
->
errCode
=
cbMeta
.
code
;
mDebug
(
"trans:%d, is proposed, saved:%d code:0x%x, index:%"
PRId64
" term:%"
PRId64
" role:%s raw:%p"
,
transId
,
pMgmt
->
transId
,
cbMeta
.
code
,
cbMeta
.
index
,
cbMeta
.
term
,
syncStr
(
cbMeta
.
state
),
pRaw
);
mDebug
(
"trans:%d, is proposed, saved:%d code:0x%x, apply index:%"
PRId64
" term:%"
PRIu64
" config:%"
PRId64
" role:%s raw:%p"
,
transId
,
pMgmt
->
transId
,
cbMeta
.
code
,
cbMeta
.
index
,
cbMeta
.
term
,
cbMeta
.
lastConfigIndex
,
syncStr
(
cbMeta
.
state
),
pRaw
);
if
(
pMgmt
->
errCode
==
0
)
{
sdbWriteWithoutFree
(
pMnode
->
pSdb
,
pRaw
);
sdbSetApplyIndex
(
pMnode
->
pSdb
,
cbMeta
.
index
);
sdbSetApplyTerm
(
pMnode
->
pSdb
,
cbMeta
.
term
);
sdbSetApplyInfo
(
pMnode
->
pSdb
,
cbMeta
.
index
,
cbMeta
.
term
,
cbMeta
.
lastConfigIndex
);
}
if
(
pMgmt
->
transId
==
transId
)
{
...
...
@@ -68,36 +69,19 @@ void mndSyncCommitMsg(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbM
mndReleaseTrans
(
pMnode
,
pTrans
);
}
if
(
cbMeta
.
index
-
sdbGetApplyIndex
(
pMnode
->
pSdb
)
>
100
)
{
SSnapshotMeta
sMeta
=
{
0
};
// if (syncGetSnapshotMeta(pMnode->syncMgmt.sync, &sMeta) == 0) {
if
(
syncGetSnapshotMetaByIndex
(
pMnode
->
syncMgmt
.
sync
,
cbMeta
.
index
,
&
sMeta
)
==
0
)
{
sdbSetCurConfig
(
pMnode
->
pSdb
,
sMeta
.
lastConfigIndex
);
}
sdbWriteFile
(
pMnode
->
pSdb
);
}
sdbWriteFile
(
pMnode
->
pSdb
,
SDB_WRITE_DELTA
);
}
}
int32_t
mndSyncGetSnapshot
(
struct
SSyncFSM
*
pFsm
,
SSnapshot
*
pSnapshot
)
{
SMnode
*
pMnode
=
pFsm
->
data
;
pSnapshot
->
lastApplyIndex
=
sdbGetCommitIndex
(
pMnode
->
pSdb
);
pSnapshot
->
lastApplyTerm
=
sdbGetCommitTerm
(
pMnode
->
pSdb
);
pSnapshot
->
lastConfigIndex
=
sdbGetCurConfig
(
pMnode
->
pSdb
);
sdbGetCommitInfo
(
pMnode
->
pSdb
,
&
pSnapshot
->
lastApplyIndex
,
&
pSnapshot
->
lastApplyTerm
,
&
pSnapshot
->
lastConfigIndex
);
return
0
;
}
void
mndRestoreFinish
(
struct
SSyncFSM
*
pFsm
)
{
SMnode
*
pMnode
=
pFsm
->
data
;
SSnapshotMeta
sMeta
=
{
0
};
// if (syncGetSnapshotMeta(pMnode->syncMgmt.sync, &sMeta) == 0) {
SyncIndex
snapshotIndex
=
sdbGetApplyIndex
(
pMnode
->
pSdb
);
if
(
syncGetSnapshotMetaByIndex
(
pMnode
->
syncMgmt
.
sync
,
snapshotIndex
,
&
sMeta
)
==
0
)
{
sdbSetCurConfig
(
pMnode
->
pSdb
,
sMeta
.
lastConfigIndex
);
}
if
(
!
pMnode
->
deploy
)
{
mInfo
(
"mnode sync restore finished, and will handle outstanding transactions"
);
mndTransPullup
(
pMnode
);
...
...
source/dnode/mnode/impl/src/mndTrans.c
浏览文件 @
db4e02c7
...
...
@@ -1435,13 +1435,8 @@ void mndTransPullup(SMnode *pMnode) {
mndReleaseTrans
(
pMnode
,
pTrans
);
}
SSnapshotMeta
sMeta
=
{
0
};
// if (syncGetSnapshotMeta(pMnode->syncMgmt.sync, &sMeta) == 0) {
SyncIndex
snapshotIndex
=
sdbGetApplyIndex
(
pMnode
->
pSdb
);
if
(
syncGetSnapshotMetaByIndex
(
pMnode
->
syncMgmt
.
sync
,
snapshotIndex
,
&
sMeta
)
==
0
)
{
sdbSetCurConfig
(
pMnode
->
pSdb
,
sMeta
.
lastConfigIndex
);
}
sdbWriteFile
(
pMnode
->
pSdb
);
// todo, set to SDB_WRITE_DELTA
sdbWriteFile
(
pMnode
->
pSdb
,
0
);
taosArrayDestroy
(
pArray
);
}
...
...
source/dnode/mnode/impl/test/sdb/sdbTest.cpp
浏览文件 @
db4e02c7
...
...
@@ -493,8 +493,11 @@ TEST_F(MndTestSdb, 01_Write_Str) {
ASSERT_EQ
(
sdbGetSize
(
pSdb
,
SDB_USER
),
2
);
ASSERT_EQ
(
sdbGetMaxId
(
pSdb
,
SDB_USER
),
-
1
);
ASSERT_EQ
(
sdbGetTableVer
(
pSdb
,
SDB_USER
),
2
);
sdbSetApplyIndex
(
pSdb
,
-
1
);
ASSERT_EQ
(
sdbGetApplyIndex
(
pSdb
),
-
1
);
sdbSetApplyInfo
(
pSdb
,
-
1
,
-
1
,
-
1
);
int64_t
index
,
config
;
int64_t
term
;
sdbGetCommitInfo
(
pSdb
,
&
index
,
&
term
,
&
config
);
ASSERT_EQ
(
index
,
-
1
);
ASSERT_EQ
(
mnode
.
insertTimes
,
2
);
ASSERT_EQ
(
mnode
.
deleteTimes
,
0
);
...
...
@@ -700,11 +703,12 @@ TEST_F(MndTestSdb, 01_Write_Str) {
}
// write version
sdbSetApplyIndex
(
pSdb
,
0
);
sdbSetApplyIndex
(
pSdb
,
1
);
ASSERT_EQ
(
sdbGetApplyIndex
(
pSdb
),
1
);
ASSERT_EQ
(
sdbWriteFile
(
pSdb
),
0
);
ASSERT_EQ
(
sdbWriteFile
(
pSdb
),
0
);
sdbSetApplyInfo
(
pSdb
,
0
,
0
,
0
);
sdbSetApplyInfo
(
pSdb
,
1
,
0
,
0
);
sdbGetCommitInfo
(
pSdb
,
&
index
,
&
term
,
&
config
);
ASSERT_EQ
(
index
,
1
);
ASSERT_EQ
(
sdbWriteFile
(
pSdb
,
0
),
0
);
ASSERT_EQ
(
sdbWriteFile
(
pSdb
,
0
),
0
);
sdbCleanup
(
pSdb
);
ASSERT_EQ
(
mnode
.
insertTimes
,
7
);
...
...
@@ -772,7 +776,11 @@ TEST_F(MndTestSdb, 01_Read_Str) {
ASSERT_EQ
(
sdbGetSize
(
pSdb
,
SDB_USER
),
2
);
ASSERT_EQ
(
sdbGetMaxId
(
pSdb
,
SDB_USER
),
-
1
);
ASSERT_EQ
(
sdbGetTableVer
(
pSdb
,
SDB_USER
),
5
);
ASSERT_EQ
(
sdbGetApplyIndex
(
pSdb
),
1
);
int64_t
index
,
config
;
int64_t
term
;
sdbGetCommitInfo
(
pSdb
,
&
index
,
&
term
,
&
config
);
ASSERT_EQ
(
index
,
1
);
ASSERT_EQ
(
mnode
.
insertTimes
,
4
);
ASSERT_EQ
(
mnode
.
deleteTimes
,
0
);
...
...
source/dnode/mnode/sdb/inc/sdb.h
浏览文件 @
db4e02c7
...
...
@@ -37,6 +37,8 @@ extern "C" {
#define mTrace(...) { if (mDebugFlag & DEBUG_TRACE) { taosPrintLog("MND ", DEBUG_TRACE, mDebugFlag, __VA_ARGS__); }}
// clang-format on
#define SDB_WRITE_DELTA 100
#define SDB_GET_VAL(pData, dataPos, val, pos, func, type) \
{ \
if (func(pRaw, dataPos, val) != 0) { \
...
...
@@ -258,7 +260,7 @@ int32_t sdbReadFile(SSdb *pSdb);
* @param pSdb The sdb object.
* @return int32_t 0 for success, -1 for failure.
*/
int32_t
sdbWriteFile
(
SSdb
*
pSdb
);
int32_t
sdbWriteFile
(
SSdb
*
pSdb
,
int32_t
delta
);
/**
* @brief Parse and write raw data to sdb, then free the pRaw object
...
...
@@ -362,14 +364,8 @@ int64_t sdbGetTableVer(SSdb *pSdb, ESdbType type);
* @param index The update value of the apply index.
* @return int32_t The current index of sdb
*/
void
sdbSetApplyIndex
(
SSdb
*
pSdb
,
int64_t
index
);
void
sdbSetApplyTerm
(
SSdb
*
pSdb
,
int64_t
term
);
void
sdbSetCurConfig
(
SSdb
*
pSdb
,
int64_t
config
);
int64_t
sdbGetApplyIndex
(
SSdb
*
pSdb
);
int64_t
sdbGetApplyTerm
(
SSdb
*
pSdb
);
int64_t
sdbGetCommitIndex
(
SSdb
*
pSdb
);
int64_t
sdbGetCommitTerm
(
SSdb
*
pSdb
);
int64_t
sdbGetCurConfig
(
SSdb
*
pSdb
);
void
sdbSetApplyInfo
(
SSdb
*
pSdb
,
int64_t
index
,
int64_t
term
,
int64_t
config
);
void
sdbGetCommitInfo
(
SSdb
*
pSdb
,
int64_t
*
index
,
int64_t
*
term
,
int64_t
*
config
);
SSdbRaw
*
sdbAllocRaw
(
ESdbType
type
,
int8_t
sver
,
int32_t
dataLen
);
void
sdbFreeRaw
(
SSdbRaw
*
pRaw
);
...
...
source/dnode/mnode/sdb/src/sdb.c
浏览文件 @
db4e02c7
...
...
@@ -68,7 +68,7 @@ SSdb *sdbInit(SSdbOpt *pOption) {
void
sdbCleanup
(
SSdb
*
pSdb
)
{
mDebug
(
"start to cleanup sdb"
);
sdbWriteFile
(
pSdb
);
sdbWriteFile
(
pSdb
,
0
);
if
(
pSdb
->
currDir
!=
NULL
)
{
taosMemoryFreeClear
(
pSdb
->
currDir
);
...
...
@@ -160,23 +160,20 @@ static int32_t sdbCreateDir(SSdb *pSdb) {
return
0
;
}
void
sdbSetApplyIndex
(
SSdb
*
pSdb
,
int64_t
index
)
{
pSdb
->
applyIndex
=
index
;
}
void
sdbSetApplyTerm
(
SSdb
*
pSdb
,
int64_t
term
)
{
pSdb
->
applyTerm
=
term
;
}
void
sdbSetCurConfig
(
SSdb
*
pSdb
,
int64_t
config
)
{
if
(
pSdb
->
applyConfig
!=
config
)
{
mDebug
(
"mnode sync config set from %"
PRId64
" to %"
PRId64
,
pSdb
->
applyConfig
,
config
);
void
sdbSetApplyInfo
(
SSdb
*
pSdb
,
int64_t
index
,
int64_t
term
,
int64_t
config
)
{
mTrace
(
"mnode apply info changed, from index:%"
PRId64
" term:%"
PRId64
" config:%"
PRId64
", to index:%"
PRId64
" term:%"
PRId64
" config:%"
PRId64
,
pSdb
->
applyIndex
,
pSdb
->
applyTerm
,
pSdb
->
applyConfig
,
index
,
term
,
config
);
pSdb
->
applyIndex
=
index
;
pSdb
->
applyIndex
=
term
;
pSdb
->
applyConfig
=
config
;
}
}
int64_t
sdbGetApplyIndex
(
SSdb
*
pSdb
)
{
return
pSdb
->
applyIndex
;
}
int64_t
sdbGetApplyTerm
(
SSdb
*
pSdb
)
{
return
pSdb
->
applyTerm
;
}
int64_t
sdbGetCommitIndex
(
SSdb
*
pSdb
)
{
return
pSdb
->
commitIndex
;
}
int64_t
sdbGetCommitTerm
(
SSdb
*
pSdb
)
{
return
pSdb
->
commitTerm
;
}
int64_t
sdbGetCurConfig
(
SSdb
*
pSdb
)
{
return
pSdb
->
commitConfig
;
}
\ No newline at end of file
void
sdbGetCommitInfo
(
SSdb
*
pSdb
,
int64_t
*
index
,
int64_t
*
term
,
int64_t
*
config
)
{
*
index
=
pSdb
->
commitIndex
;
*
term
=
pSdb
->
commitTerm
;
*
config
=
pSdb
->
commitConfig
;
mTrace
(
"mnode current info, apply index:%"
PRId64
" term:%"
PRId64
" config:%"
PRId64
", commit index:%"
PRId64
" term:%"
PRId64
" config:%"
PRId64
,
pSdb
->
applyIndex
,
pSdb
->
applyTerm
,
pSdb
->
applyConfig
,
*
index
,
*
term
,
*
config
);
}
source/dnode/mnode/sdb/src/sdbFile.c
浏览文件 @
db4e02c7
...
...
@@ -445,12 +445,16 @@ static int32_t sdbWriteFileImp(SSdb *pSdb) {
return
code
;
}
int32_t
sdbWriteFile
(
SSdb
*
pSdb
)
{
int32_t
sdbWriteFile
(
SSdb
*
pSdb
,
int32_t
delta
)
{
int32_t
code
=
0
;
if
(
pSdb
->
applyIndex
==
pSdb
->
commitIndex
)
{
return
0
;
}
if
(
pSdb
->
applyIndex
-
pSdb
->
commitIndex
<
delta
)
{
return
0
;
}
taosThreadMutexLock
(
&
pSdb
->
filelock
);
if
(
pSdb
->
pWal
!=
NULL
)
{
code
=
walBeginSnapshot
(
pSdb
->
pWal
,
pSdb
->
applyIndex
);
...
...
@@ -475,7 +479,7 @@ int32_t sdbDeploy(SSdb *pSdb) {
return
-
1
;
}
if
(
sdbWriteFile
(
pSdb
)
!=
0
)
{
if
(
sdbWriteFile
(
pSdb
,
0
)
!=
0
)
{
return
-
1
;
}
...
...
source/libs/sync/src/syncSnapshot.c
浏览文件 @
db4e02c7
...
...
@@ -50,6 +50,7 @@ SSyncSnapshotSender *snapshotSenderCreate(SSyncNode *pSyncNode, int32_t replicaI
}
else
{
sError
(
"snapshotSenderCreate cannot create sender"
);
}
return
pSender
;
}
...
...
@@ -84,6 +85,10 @@ void snapshotSenderStart(SSyncSnapshotSender *pSender) {
// get current snapshot info
pSender
->
pSyncNode
->
pFsm
->
FpGetSnapshot
(
pSender
->
pSyncNode
->
pFsm
,
&
(
pSender
->
snapshot
));
sTrace
(
"snapshotSenderStart lastApplyIndex:%ld, lastApplyTerm:%lu, lastConfigIndex:%ld"
,
pSender
->
snapshot
.
lastApplyIndex
,
pSender
->
snapshot
.
lastApplyTerm
,
pSender
->
snapshot
.
lastConfigIndex
);
if
(
pSender
->
snapshot
.
lastConfigIndex
!=
SYNC_INDEX_INVALID
)
{
/*
SSyncRaftEntry *pEntry = NULL;
...
...
@@ -421,7 +426,7 @@ cJSON *snapshotSender2Json(SSyncSnapshotSender *pSender) {
char
*
snapshotSender2Str
(
SSyncSnapshotSender
*
pSender
)
{
cJSON
*
pJson
=
snapshotSender2Json
(
pSender
);
char
*
serialized
=
cJSON_Print
(
pJson
);
char
*
serialized
=
cJSON_Print
(
pJson
);
cJSON_Delete
(
pJson
);
return
serialized
;
}
...
...
@@ -542,7 +547,7 @@ cJSON *snapshotReceiver2Json(SSyncSnapshotReceiver *pReceiver) {
cJSON_AddStringToObject
(
pFromId
,
"addr"
,
u64buf
);
{
uint64_t
u64
=
pReceiver
->
fromId
.
addr
;
cJSON
*
pTmp
=
pFromId
;
cJSON
*
pTmp
=
pFromId
;
char
host
[
128
]
=
{
0
};
uint16_t
port
;
syncUtilU642Addr
(
u64
,
host
,
sizeof
(
host
),
&
port
);
...
...
@@ -566,7 +571,7 @@ cJSON *snapshotReceiver2Json(SSyncSnapshotReceiver *pReceiver) {
char
*
snapshotReceiver2Str
(
SSyncSnapshotReceiver
*
pReceiver
)
{
cJSON
*
pJson
=
snapshotReceiver2Json
(
pReceiver
);
char
*
serialized
=
cJSON_Print
(
pJson
);
char
*
serialized
=
cJSON_Print
(
pJson
);
cJSON_Delete
(
pJson
);
return
serialized
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录