Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
576a7ee0
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,发现更多精彩内容 >>
提交
576a7ee0
编写于
5月 28, 2022
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
enh: sdb snapshot
上级
b5a1131c
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
33 addition
and
27 deletion
+33
-27
source/dnode/mnode/impl/src/mndSync.c
source/dnode/mnode/impl/src/mndSync.c
+1
-1
source/dnode/mnode/impl/test/sdb/sdbTest.cpp
source/dnode/mnode/impl/test/sdb/sdbTest.cpp
+23
-2
source/dnode/mnode/sdb/inc/sdb.h
source/dnode/mnode/sdb/inc/sdb.h
+2
-2
source/dnode/mnode/sdb/src/sdbFile.c
source/dnode/mnode/sdb/src/sdbFile.c
+7
-22
未找到文件。
source/dnode/mnode/impl/src/mndSync.c
浏览文件 @
576a7ee0
...
...
@@ -71,7 +71,7 @@ int32_t mndSnapshotRead(struct SSyncFSM *pFsm, const SSnapshot *pSnapshot, void
SMnode
*
pMnode
=
pFsm
->
data
;
mInfo
(
"start to read snapshot from sdb"
);
int32_t
code
=
sdbReadSnapshot
(
pMnode
->
pSdb
,
(
SSdbIter
**
)
ppIter
,
ppBuf
,
len
);
int32_t
code
=
sdbReadSnapshot
(
pMnode
->
pSdb
,
(
SSdbIter
**
)
ppIter
,
(
void
**
)
ppBuf
,
len
);
if
(
code
!=
0
)
{
mError
(
"failed to read snapshot from sdb since %s"
,
terrstr
());
}
else
{
...
...
source/dnode/mnode/impl/test/sdb/sdbTest.cpp
浏览文件 @
576a7ee0
...
...
@@ -895,7 +895,28 @@ TEST_F(MndTestSdb, 01_Read_Str) {
ASSERT_EQ
(
code
,
TSDB_CODE_SDB_OBJ_CREATING
);
}
{
void
*
sdbbuf
=
taosMemoryMalloc
(
1024
*
1024
);
int32_t
total
=
0
;
void
*
pBuf
=
NULL
;
int32_t
len
=
0
;
SSdbIter
*
pIter
=
NULL
;
while
(
sdbReadSnapshot
(
pSdb
,
&
pIter
,
&
pBuf
,
&
len
)
==
0
)
{
if
(
pBuf
!=
NULL
&&
len
!=
0
)
{
memcpy
((
char
*
)
sdbbuf
+
total
,
pBuf
,
len
);
total
+=
len
;
taosMemoryFree
(
pBuf
);
}
else
{
break
;
}
}
sdbApplySnapshot
(
pSdb
,
sdbbuf
,
total
);
}
ASSERT_EQ
(
sdbGetSize
(
pSdb
,
SDB_CONSUMER
),
1
);
ASSERT_EQ
(
sdbGetTableVer
(
pSdb
,
SDB_CONSUMER
),
4
);
sdbCleanup
(
pSdb
);
ASSERT_EQ
(
mnode
.
insertTimes
,
5
);
ASSERT_EQ
(
mnode
.
deleteTimes
,
5
);
ASSERT_EQ
(
mnode
.
insertTimes
,
9
);
ASSERT_EQ
(
mnode
.
deleteTimes
,
9
);
}
\ No newline at end of file
source/dnode/mnode/sdb/inc/sdb.h
浏览文件 @
576a7ee0
...
...
@@ -380,8 +380,8 @@ SSdbRow *sdbAllocRow(int32_t objSize);
void
*
sdbGetRowObj
(
SSdbRow
*
pRow
);
void
sdbFreeRow
(
SSdb
*
pSdb
,
SSdbRow
*
pRow
,
bool
callFunc
);
int32_t
sdbReadSnapshot
(
SSdb
*
pSdb
,
SSdbIter
**
ppIter
,
char
**
ppBuf
,
int32_t
*
len
);
int32_t
sdbApplySnapshot
(
SSdb
*
pSdb
,
char
*
pBuf
,
int32_t
len
);
int32_t
sdbReadSnapshot
(
SSdb
*
pSdb
,
SSdbIter
**
ppIter
,
void
**
ppBuf
,
int32_t
*
len
);
int32_t
sdbApplySnapshot
(
SSdb
*
pSdb
,
void
*
pBuf
,
int32_t
len
);
const
char
*
sdbTableName
(
ESdbType
type
);
void
sdbPrintOper
(
SSdb
*
pSdb
,
SSdbRow
*
pRow
,
const
char
*
oper
);
...
...
source/dnode/mnode/sdb/src/sdbFile.c
浏览文件 @
576a7ee0
...
...
@@ -452,7 +452,7 @@ static SSdbIter *sdbOpenIter(SSdb *pSdb) {
snprintf
(
tmpfile
,
sizeof
(
tmpfile
),
"%s%ssdb.data"
,
pSdb
->
tmpDir
,
TD_DIRSEP
);
taosThreadMutexLock
(
&
pSdb
->
filelock
);
if
(
taosCopyFile
(
datafile
,
tmpfile
)
!=
0
)
{
if
(
taosCopyFile
(
datafile
,
tmpfile
)
<
0
)
{
taosThreadMutexUnlock
(
&
pSdb
->
filelock
);
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
mError
(
"failed to copy file %s to %s since %s"
,
datafile
,
tmpfile
,
terrstr
());
...
...
@@ -512,12 +512,12 @@ static SSdbIter *sdbGetIter(SSdb *pSdb, SSdbIter **ppIter) {
return
pIter
;
}
int32_t
sdbReadSnapshot
(
SSdb
*
pSdb
,
SSdbIter
**
ppIter
,
char
**
ppBuf
,
int32_t
*
len
)
{
int32_t
sdbReadSnapshot
(
SSdb
*
pSdb
,
SSdbIter
**
ppIter
,
void
**
ppBuf
,
int32_t
*
len
)
{
SSdbIter
*
pIter
=
sdbGetIter
(
pSdb
,
ppIter
);
if
(
pIter
==
NULL
)
return
-
1
;
int32_t
maxlen
=
100
;
char
*
pBuf
=
taosMemoryCalloc
(
1
,
maxlen
);
void
*
pBuf
=
taosMemoryCalloc
(
1
,
maxlen
);
if
(
pBuf
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
sdbCloseIter
(
pSdb
,
pIter
);
...
...
@@ -525,7 +525,7 @@ int32_t sdbReadSnapshot(SSdb *pSdb, SSdbIter **ppIter, char **ppBuf, int32_t *le
}
int32_t
readlen
=
taosReadFile
(
pIter
->
file
,
pBuf
,
maxlen
);
if
(
readlen
<
0
||
(
readlen
==
0
&&
errno
!=
0
)
)
{
if
(
readlen
<
0
||
readlen
>
maxlen
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
mError
(
"sdbiter:%p, failed to read snapshot since %s, total:%"
PRId64
,
pIter
,
terrstr
(),
pIter
->
total
);
*
ppBuf
=
NULL
;
...
...
@@ -539,35 +539,20 @@ int32_t sdbReadSnapshot(SSdb *pSdb, SSdbIter **ppIter, char **ppBuf, int32_t *le
*
ppBuf
=
NULL
;
*
len
=
0
;
*
ppIter
=
NULL
;
*
ppIter
=
NULL
;
sdbCloseIter
(
pSdb
,
pIter
);
taosMemoryFree
(
pBuf
);
return
0
;
}
else
if
((
readlen
<
maxlen
&&
errno
!=
0
)
||
readlen
==
maxlen
)
{
}
else
{
// (readlen <= maxlen)
pIter
->
total
+=
readlen
;
mInfo
(
"sdbiter:%p, read:%d bytes from snapshot, total:%"
PRId64
,
pIter
,
readlen
,
pIter
->
total
);
*
ppBuf
=
pBuf
;
*
len
=
readlen
;
return
0
;
}
else
if
(
readlen
<
maxlen
&&
errno
==
0
)
{
mInfo
(
"sdbiter:%p, read snapshot to the end, total:%"
PRId64
,
pIter
,
pIter
->
total
);
*
ppBuf
=
pBuf
;
*
len
=
readlen
;
*
ppIter
=
NULL
;
sdbCloseIter
(
pSdb
,
pIter
);
return
0
;
}
else
{
// impossible
mError
(
"sdbiter:%p, read:%d bytes from snapshot, total:%"
PRId64
,
pIter
,
readlen
,
pIter
->
total
);
*
ppBuf
=
NULL
;
*
len
=
0
;
*
ppIter
=
NULL
;
sdbCloseIter
(
pSdb
,
pIter
);
taosMemoryFree
(
pBuf
);
return
-
1
;
}
}
int32_t
sdbApplySnapshot
(
SSdb
*
pSdb
,
char
*
pBuf
,
int32_t
len
)
{
int32_t
sdbApplySnapshot
(
SSdb
*
pSdb
,
void
*
pBuf
,
int32_t
len
)
{
char
datafile
[
PATH_MAX
]
=
{
0
};
char
tmpfile
[
PATH_MAX
]
=
{
0
};
snprintf
(
datafile
,
sizeof
(
datafile
),
"%s%ssdb.data"
,
pSdb
->
currDir
,
TD_DIRSEP
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录