Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
1c46b8d0
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看板
未验证
提交
1c46b8d0
编写于
6月 18, 2022
作者:
S
Shengliang Guan
提交者:
GitHub
6月 18, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #13946 from taosdata/fix/tsim
refactor: sdb commit index
上级
d84eff0e
1d5f431d
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
58 addition
and
50 deletion
+58
-50
source/dnode/mnode/sdb/inc/sdb.h
source/dnode/mnode/sdb/inc/sdb.h
+6
-5
source/dnode/mnode/sdb/src/sdb.c
source/dnode/mnode/sdb/src/sdb.c
+16
-15
source/dnode/mnode/sdb/src/sdbFile.c
source/dnode/mnode/sdb/src/sdbFile.c
+33
-28
tests/test/c/sdbDump.c
tests/test/c/sdbDump.c
+3
-2
未找到文件。
source/dnode/mnode/sdb/inc/sdb.h
浏览文件 @
1c46b8d0
...
...
@@ -169,11 +169,12 @@ typedef struct SSdb {
SWal
*
pWal
;
char
*
currDir
;
char
*
tmpDir
;
int64_t
lastCommitVer
;
int64_t
lastCommitTerm
;
int64_t
curVer
;
int64_t
curTerm
;
int64_t
curConfig
;
int64_t
commitIndex
;
int64_t
commitTerm
;
int64_t
commitConfig
;
int64_t
applyIndex
;
int64_t
applyTerm
;
int64_t
applyConfig
;
int64_t
tableVer
[
SDB_MAX
];
int64_t
maxId
[
SDB_MAX
];
EKeyType
keyTypes
[
SDB_MAX
];
...
...
source/dnode/mnode/sdb/src/sdb.c
浏览文件 @
1c46b8d0
...
...
@@ -53,11 +53,12 @@ SSdb *sdbInit(SSdbOpt *pOption) {
}
pSdb
->
pWal
=
pOption
->
pWal
;
pSdb
->
curVer
=
-
1
;
pSdb
->
curTerm
=
-
1
;
pSdb
->
lastCommitVer
=
-
1
;
pSdb
->
lastCommitTerm
=
-
1
;
pSdb
->
curConfig
=
-
1
;
pSdb
->
applyIndex
=
-
1
;
pSdb
->
applyTerm
=
-
1
;
pSdb
->
applyConfig
=
-
1
;
pSdb
->
commitIndex
=
-
1
;
pSdb
->
commitTerm
=
-
1
;
pSdb
->
commitConfig
=
-
1
;
pSdb
->
pMnode
=
pOption
->
pMnode
;
taosThreadMutexInit
(
&
pSdb
->
filelock
,
NULL
);
mDebug
(
"sdb init successfully"
);
...
...
@@ -159,23 +160,23 @@ static int32_t sdbCreateDir(SSdb *pSdb) {
return
0
;
}
void
sdbSetApplyIndex
(
SSdb
*
pSdb
,
int64_t
index
)
{
pSdb
->
curVer
=
index
;
}
void
sdbSetApplyIndex
(
SSdb
*
pSdb
,
int64_t
index
)
{
pSdb
->
applyIndex
=
index
;
}
void
sdbSetApplyTerm
(
SSdb
*
pSdb
,
int64_t
term
)
{
pSdb
->
cur
Term
=
term
;
}
void
sdbSetApplyTerm
(
SSdb
*
pSdb
,
int64_t
term
)
{
pSdb
->
apply
Term
=
term
;
}
void
sdbSetCurConfig
(
SSdb
*
pSdb
,
int64_t
config
)
{
if
(
pSdb
->
cur
Config
!=
config
)
{
mDebug
(
"mnode sync config set from %"
PRId64
" to %"
PRId64
,
pSdb
->
cur
Config
,
config
);
pSdb
->
cur
Config
=
config
;
if
(
pSdb
->
apply
Config
!=
config
)
{
mDebug
(
"mnode sync config set from %"
PRId64
" to %"
PRId64
,
pSdb
->
apply
Config
,
config
);
pSdb
->
apply
Config
=
config
;
}
}
int64_t
sdbGetApplyIndex
(
SSdb
*
pSdb
)
{
return
pSdb
->
curVer
;
}
int64_t
sdbGetApplyIndex
(
SSdb
*
pSdb
)
{
return
pSdb
->
applyIndex
;
}
int64_t
sdbGetApplyTerm
(
SSdb
*
pSdb
)
{
return
pSdb
->
cur
Term
;
}
int64_t
sdbGetApplyTerm
(
SSdb
*
pSdb
)
{
return
pSdb
->
apply
Term
;
}
int64_t
sdbGetCommitIndex
(
SSdb
*
pSdb
)
{
return
pSdb
->
lastCommitVer
;
}
int64_t
sdbGetCommitIndex
(
SSdb
*
pSdb
)
{
return
pSdb
->
commitIndex
;
}
int64_t
sdbGetCommitTerm
(
SSdb
*
pSdb
)
{
return
pSdb
->
lastC
ommitTerm
;
}
int64_t
sdbGetCommitTerm
(
SSdb
*
pSdb
)
{
return
pSdb
->
c
ommitTerm
;
}
int64_t
sdbGetCurConfig
(
SSdb
*
pSdb
)
{
return
pSdb
->
curConfig
;
}
\ No newline at end of file
int64_t
sdbGetCurConfig
(
SSdb
*
pSdb
)
{
return
pSdb
->
commitConfig
;
}
\ No newline at end of file
source/dnode/mnode/sdb/src/sdbFile.c
浏览文件 @
1c46b8d0
...
...
@@ -67,10 +67,12 @@ static void sdbResetData(SSdb *pSdb) {
mDebug
(
"sdb:%s is reset"
,
sdbTableName
(
i
));
}
pSdb
->
curVer
=
-
1
;
pSdb
->
curTerm
=
-
1
;
pSdb
->
lastCommitVer
=
-
1
;
pSdb
->
lastCommitTerm
=
-
1
;
pSdb
->
applyIndex
=
-
1
;
pSdb
->
applyTerm
=
-
1
;
pSdb
->
applyConfig
=
-
1
;
pSdb
->
commitIndex
=
-
1
;
pSdb
->
commitTerm
=
-
1
;
pSdb
->
commitConfig
=
-
1
;
mDebug
(
"sdb reset successfully"
);
}
...
...
@@ -90,7 +92,7 @@ static int32_t sdbReadFileHead(SSdb *pSdb, TdFilePtr pFile) {
return
-
1
;
}
ret
=
taosReadFile
(
pFile
,
&
pSdb
->
curVer
,
sizeof
(
int64_t
));
ret
=
taosReadFile
(
pFile
,
&
pSdb
->
applyIndex
,
sizeof
(
int64_t
));
if
(
ret
<
0
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
return
-
1
;
...
...
@@ -100,7 +102,7 @@ static int32_t sdbReadFileHead(SSdb *pSdb, TdFilePtr pFile) {
return
-
1
;
}
ret
=
taosReadFile
(
pFile
,
&
pSdb
->
cur
Term
,
sizeof
(
int64_t
));
ret
=
taosReadFile
(
pFile
,
&
pSdb
->
apply
Term
,
sizeof
(
int64_t
));
if
(
ret
<
0
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
return
-
1
;
...
...
@@ -110,7 +112,7 @@ static int32_t sdbReadFileHead(SSdb *pSdb, TdFilePtr pFile) {
return
-
1
;
}
ret
=
taosReadFile
(
pFile
,
&
pSdb
->
cur
Config
,
sizeof
(
int64_t
));
ret
=
taosReadFile
(
pFile
,
&
pSdb
->
apply
Config
,
sizeof
(
int64_t
));
if
(
ret
<
0
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
return
-
1
;
...
...
@@ -173,17 +175,17 @@ static int32_t sdbWriteFileHead(SSdb *pSdb, TdFilePtr pFile) {
return
-
1
;
}
if
(
taosWriteFile
(
pFile
,
&
pSdb
->
curVer
,
sizeof
(
int64_t
))
!=
sizeof
(
int64_t
))
{
if
(
taosWriteFile
(
pFile
,
&
pSdb
->
applyIndex
,
sizeof
(
int64_t
))
!=
sizeof
(
int64_t
))
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
return
-
1
;
}
if
(
taosWriteFile
(
pFile
,
&
pSdb
->
cur
Term
,
sizeof
(
int64_t
))
!=
sizeof
(
int64_t
))
{
if
(
taosWriteFile
(
pFile
,
&
pSdb
->
apply
Term
,
sizeof
(
int64_t
))
!=
sizeof
(
int64_t
))
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
return
-
1
;
}
if
(
taosWriteFile
(
pFile
,
&
pSdb
->
cur
Config
,
sizeof
(
int64_t
))
!=
sizeof
(
int64_t
))
{
if
(
taosWriteFile
(
pFile
,
&
pSdb
->
apply
Config
,
sizeof
(
int64_t
))
!=
sizeof
(
int64_t
))
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
return
-
1
;
}
...
...
@@ -300,11 +302,12 @@ static int32_t sdbReadFileImp(SSdb *pSdb) {
}
code
=
0
;
pSdb
->
lastCommitVer
=
pSdb
->
curVer
;
pSdb
->
lastCommitTerm
=
pSdb
->
curTerm
;
pSdb
->
commitIndex
=
pSdb
->
applyIndex
;
pSdb
->
commitTerm
=
pSdb
->
applyTerm
;
pSdb
->
commitConfig
=
pSdb
->
applyConfig
;
memcpy
(
pSdb
->
tableVer
,
tableVer
,
sizeof
(
tableVer
));
mDebug
(
"read sdb file:%s successfully,
index:%"
PRId64
" term:%"
PRId64
" config:%"
PRId64
,
file
,
pSdb
->
lastCommitVer
,
pSdb
->
lastCommitTerm
,
pSdb
->
cur
Config
);
mDebug
(
"read sdb file:%s successfully,
commit index:%"
PRId64
" term:%"
PRId64
" config:%"
PRId64
,
file
,
pSdb
->
commitIndex
,
pSdb
->
commitTerm
,
pSdb
->
commit
Config
);
_OVER:
taosCloseFile
(
&
pFile
);
...
...
@@ -336,9 +339,10 @@ static int32_t sdbWriteFileImp(SSdb *pSdb) {
char
curfile
[
PATH_MAX
]
=
{
0
};
snprintf
(
curfile
,
sizeof
(
curfile
),
"%s%ssdb.data"
,
pSdb
->
currDir
,
TD_DIRSEP
);
mDebug
(
"start to write sdb file, current ver:%"
PRId64
" term:%"
PRId64
", commit ver:%"
PRId64
" term:%"
PRId64
" file:%s"
,
pSdb
->
curVer
,
pSdb
->
curTerm
,
pSdb
->
lastCommitVer
,
pSdb
->
lastCommitTerm
,
curfile
);
mDebug
(
"start to write sdb file, apply index:%"
PRId64
" term:%"
PRId64
" config:%"
PRId64
", commit index:%"
PRId64
" term:%"
PRId64
" config:%"
PRId64
", file:%s"
,
pSdb
->
applyIndex
,
pSdb
->
applyTerm
,
pSdb
->
applyConfig
,
pSdb
->
commitIndex
,
pSdb
->
commitTerm
,
pSdb
->
commitConfig
,
curfile
);
TdFilePtr
pFile
=
taosOpenFile
(
tmpfile
,
TD_FILE_CREATE
|
TD_FILE_WRITE
|
TD_FILE_TRUNC
);
if
(
pFile
==
NULL
)
{
...
...
@@ -430,10 +434,11 @@ static int32_t sdbWriteFileImp(SSdb *pSdb) {
if
(
code
!=
0
)
{
mError
(
"failed to write sdb file:%s since %s"
,
curfile
,
tstrerror
(
code
));
}
else
{
pSdb
->
lastCommitVer
=
pSdb
->
curVer
;
pSdb
->
lastCommitTerm
=
pSdb
->
curTerm
;
mDebug
(
"write sdb file successfully, index:%"
PRId64
" term:%"
PRId64
" config:%"
PRId64
" file:%s"
,
pSdb
->
lastCommitVer
,
pSdb
->
lastCommitTerm
,
pSdb
->
curConfig
,
curfile
);
pSdb
->
commitIndex
=
pSdb
->
applyIndex
;
pSdb
->
commitTerm
=
pSdb
->
applyTerm
;
pSdb
->
commitConfig
=
pSdb
->
applyConfig
;
mDebug
(
"write sdb file successfully, commit index:%"
PRId64
" term:%"
PRId64
" config:%"
PRId64
" file:%s"
,
pSdb
->
commitIndex
,
pSdb
->
commitTerm
,
pSdb
->
commitConfig
,
curfile
);
}
terrno
=
code
;
...
...
@@ -442,13 +447,13 @@ static int32_t sdbWriteFileImp(SSdb *pSdb) {
int32_t
sdbWriteFile
(
SSdb
*
pSdb
)
{
int32_t
code
=
0
;
if
(
pSdb
->
curVer
==
pSdb
->
lastCommitVer
)
{
if
(
pSdb
->
applyIndex
==
pSdb
->
commitIndex
)
{
return
0
;
}
taosThreadMutexLock
(
&
pSdb
->
filelock
);
if
(
pSdb
->
pWal
!=
NULL
)
{
code
=
walBeginSnapshot
(
pSdb
->
pWal
,
pSdb
->
curVer
);
code
=
walBeginSnapshot
(
pSdb
->
pWal
,
pSdb
->
applyIndex
);
}
if
(
code
==
0
)
{
code
=
sdbWriteFileImp
(
pSdb
);
...
...
@@ -522,9 +527,9 @@ int32_t sdbStartRead(SSdb *pSdb, SSdbIter **ppIter) {
snprintf
(
datafile
,
sizeof
(
datafile
),
"%s%ssdb.data"
,
pSdb
->
currDir
,
TD_DIRSEP
);
taosThreadMutexLock
(
&
pSdb
->
filelock
);
int64_t
commitIndex
=
pSdb
->
lastCommitVer
;
int64_t
commitTerm
=
pSdb
->
lastC
ommitTerm
;
int64_t
c
urConfig
=
pSdb
->
cur
Config
;
int64_t
commitIndex
=
pSdb
->
commitIndex
;
int64_t
commitTerm
=
pSdb
->
c
ommitTerm
;
int64_t
c
ommitConfig
=
pSdb
->
commit
Config
;
if
(
taosCopyFile
(
datafile
,
pIter
->
name
)
<
0
)
{
taosThreadMutexUnlock
(
&
pSdb
->
filelock
);
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
...
...
@@ -543,8 +548,8 @@ int32_t sdbStartRead(SSdb *pSdb, SSdbIter **ppIter) {
}
*
ppIter
=
pIter
;
mInfo
(
"sdbiter:%p, is created to read snapshot,
index:%"
PRId64
" term:%"
PRId64
" config:%"
PRId64
" file:%s"
,
pIter
,
commitIndex
,
commitTerm
,
cur
Config
,
pIter
->
name
);
mInfo
(
"sdbiter:%p, is created to read snapshot,
commit index:%"
PRId64
" term:%"
PRId64
" config:%"
PRId64
" file:%s"
,
pIter
,
commitIndex
,
commitTerm
,
commit
Config
,
pIter
->
name
);
return
0
;
}
...
...
tests/test/c/sdbDump.c
浏览文件 @
1c46b8d0
...
...
@@ -295,8 +295,9 @@ void dumpTrans(SSdb *pSdb, SJson *json) {
void
dumpHeader
(
SSdb
*
pSdb
,
SJson
*
json
)
{
tjsonAddIntegerToObject
(
json
,
"sver"
,
1
);
tjsonAddStringToObject
(
json
,
"curVer"
,
i642str
(
pSdb
->
curVer
));
tjsonAddStringToObject
(
json
,
"curTerm"
,
i642str
(
pSdb
->
curTerm
));
tjsonAddStringToObject
(
json
,
"applyIndex"
,
i642str
(
pSdb
->
applyIndex
));
tjsonAddStringToObject
(
json
,
"applyTerm"
,
i642str
(
pSdb
->
applyTerm
));
tjsonAddStringToObject
(
json
,
"applyConfig"
,
i642str
(
pSdb
->
applyConfig
));
SJson
*
maxIdsJson
=
tjsonCreateObject
();
tjsonAddItemToObject
(
json
,
"maxIds"
,
maxIdsJson
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录