Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
94c3569a
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看板
未验证
提交
94c3569a
编写于
5月 29, 2023
作者:
D
dapan1121
提交者:
GitHub
5月 29, 2023
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #21512 from wangjiaming0909/fix/3.0/TS-3457
fix: page buffer cache flush wrong bytes of data into disk
上级
c2bb44b6
5e2d3939
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
74 addition
and
3 deletion
+74
-3
source/util/src/tpagedbuf.c
source/util/src/tpagedbuf.c
+1
-1
source/util/test/CMakeLists.txt
source/util/test/CMakeLists.txt
+9
-1
source/util/test/pageBufferTest.cpp
source/util/test/pageBufferTest.cpp
+64
-1
未找到文件。
source/util/src/tpagedbuf.c
浏览文件 @
94c3569a
...
...
@@ -166,7 +166,7 @@ static char* doFlushBufPage(SDiskbasedBuf* pBuf, SPageInfo* pg) {
char
*
t
=
NULL
;
if
((
!
HAS_DATA_IN_DISK
(
pg
))
||
pg
->
dirty
)
{
void
*
payload
=
GET_PAYLOAD_DATA
(
pg
);
t
=
doCompressData
(
payload
,
pBuf
->
pageSize
,
&
size
,
pBuf
);
t
=
doCompressData
(
payload
,
pBuf
->
pageSize
+
sizeof
(
SFilePage
)
,
&
size
,
pBuf
);
if
(
size
<
0
)
{
uError
(
"failed to compress data when flushing data to disk, %s"
,
pBuf
->
id
);
terrno
=
TSDB_CODE_INVALID_PARA
;
...
...
source/util/test/CMakeLists.txt
浏览文件 @
94c3569a
...
...
@@ -75,4 +75,12 @@ target_link_libraries(rbtreeTest os util gtest_main)
add_test
(
NAME rbtreeTest
COMMAND rbtreeTest
)
\ No newline at end of file
)
# pageBufferTest
add_executable
(
pageBufferTest
"pageBufferTest.cpp"
)
target_link_libraries
(
pageBufferTest os util gtest_main
)
add_test
(
NAME pageBufferTest
COMMAND pageBufferTest
)
source/util/test/pageBufferTest.cpp
浏览文件 @
94c3569a
...
...
@@ -157,6 +157,68 @@ void recyclePageTest() {
destroyDiskbasedBuf
(
pBuf
);
}
int
saveDataToPage
(
SFilePage
*
pPg
,
const
char
*
data
,
uint32_t
len
)
{
memcpy
(
pPg
->
data
+
pPg
->
num
,
data
,
len
);
pPg
->
num
+=
len
;
setBufPageDirty
(
pPg
,
true
);
return
0
;
}
bool
checkBufVarData
(
SFilePage
*
pPg
,
const
char
*
varData
,
uint32_t
varLen
)
{
const
char
*
start
=
pPg
->
data
+
sizeof
(
SFilePage
);
for
(
uint32_t
i
=
0
;
i
<
(
pPg
->
num
-
sizeof
(
SFilePage
))
/
varLen
;
++
i
)
{
if
(
0
!=
strncmp
(
start
+
6
*
i
+
3
,
varData
,
varLen
-
3
))
{
using
namespace
std
;
cout
<<
"pos: "
<<
sizeof
(
SFilePage
)
+
6
*
i
+
3
<<
" should be "
<<
varData
<<
" but is: "
<<
start
+
6
*
i
+
3
<<
endl
;
return
false
;
}
}
return
true
;
}
// SPageInfo.pData: | sizeof(void*) 8 bytes | sizeof(SFilePage) 4 bytes| 4096 bytes |
// ^
// |
// SFilePage: flush to disk from here
void
testFlushAndReadBackBuffer
()
{
SDiskbasedBuf
*
pBuf
=
NULL
;
uint32_t
totalLen
=
4096
;
auto
code
=
createDiskbasedBuf
(
&
pBuf
,
totalLen
,
totalLen
*
2
,
"1"
,
TD_TMP_DIR_PATH
);
int32_t
pageId
=
-
1
;
auto
*
pPg
=
(
SFilePage
*
)
getNewBufPage
(
pBuf
,
&
pageId
);
ASSERT_TRUE
(
pPg
!=
nullptr
);
pPg
->
num
=
sizeof
(
SFilePage
);
// save data into page
uint32_t
len
=
6
;
// sizeof(SFilePage) + 6 * 682 = 4096
// nullbitmap(1) + len(2) + AA\0(3)
char
*
rowData
=
(
char
*
)
taosMemoryCalloc
(
1
,
len
);
*
(
uint16_t
*
)(
rowData
+
2
)
=
(
uint16_t
)
2
;
rowData
[
3
]
=
'A'
;
rowData
[
4
]
=
'A'
;
while
(
pPg
->
num
+
len
<=
getBufPageSize
(
pBuf
))
{
saveDataToPage
(
pPg
,
rowData
,
len
);
}
ASSERT_EQ
(
pPg
->
num
,
totalLen
);
ASSERT_TRUE
(
checkBufVarData
(
pPg
,
rowData
+
3
,
len
));
releaseBufPage
(
pBuf
,
pPg
);
// flush to disk
int32_t
newPgId
=
-
1
;
pPg
=
(
SFilePage
*
)
getNewBufPage
(
pBuf
,
&
newPgId
);
releaseBufPage
(
pBuf
,
pPg
);
pPg
=
(
SFilePage
*
)
getNewBufPage
(
pBuf
,
&
newPgId
);
releaseBufPage
(
pBuf
,
pPg
);
// reload it from disk
pPg
=
(
SFilePage
*
)
getBufPage
(
pBuf
,
pageId
);
ASSERT_TRUE
(
checkBufVarData
(
pPg
,
rowData
+
3
,
len
));
destroyDiskbasedBuf
(
pBuf
);
}
}
// namespace
TEST
(
testCase
,
resultBufferTest
)
{
...
...
@@ -164,6 +226,7 @@ TEST(testCase, resultBufferTest) {
simpleTest
();
writeDownTest
();
recyclePageTest
();
testFlushAndReadBackBuffer
();
}
#pragma GCC diagnostic pop
\ No newline at end of file
#pragma GCC diagnostic pop
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录