Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Metz
oceanbase
提交
3a827ef0
O
oceanbase
项目概览
Metz
/
oceanbase
与 Fork 源项目一致
Fork自
oceanbase / oceanbase
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
oceanbase
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
3a827ef0
编写于
7月 15, 2021
作者:
O
obdev
提交者:
wangzelin.wzl
7月 15, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add defense code for tmp file in case of misuse.
上级
09bc1e96
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
93 addition
and
29 deletion
+93
-29
src/storage/blocksstable/ob_tmp_file.cpp
src/storage/blocksstable/ob_tmp_file.cpp
+39
-29
src/storage/blocksstable/ob_tmp_file.h
src/storage/blocksstable/ob_tmp_file.h
+1
-0
unittest/storage/blocksstable/test_tmp_file.cpp
unittest/storage/blocksstable/test_tmp_file.cpp
+53
-0
未找到文件。
src/storage/blocksstable/ob_tmp_file.cpp
浏览文件 @
3a827ef0
...
@@ -40,14 +40,10 @@ bool ObTmpFileIOInfo::is_valid() const
...
@@ -40,14 +40,10 @@ bool ObTmpFileIOInfo::is_valid() const
}
}
ObTmpFileIOHandle
::
ObTmpFileIOHandle
()
ObTmpFileIOHandle
::
ObTmpFileIOHandle
()
:
tmp_file_
(
NULL
),
:
tmp_file_
(
NULL
),
io_handles_
(),
page_cache_handles_
(),
block_cache_handles_
(),
buf_
(
NULL
),
io_handles_
(),
size_
(
0
),
is_read_
(
false
),
has_wait_
(
false
)
page_cache_handles_
(),
{
block_cache_handles_
(),
}
buf_
(
NULL
),
size_
(
0
),
is_read_
(
false
)
{}
ObTmpFileIOHandle
::~
ObTmpFileIOHandle
()
ObTmpFileIOHandle
::~
ObTmpFileIOHandle
()
{
{
...
@@ -65,6 +61,7 @@ int ObTmpFileIOHandle::prepare_read(char* read_buf, ObTmpFile* file)
...
@@ -65,6 +61,7 @@ int ObTmpFileIOHandle::prepare_read(char* read_buf, ObTmpFile* file)
size_
=
0
;
size_
=
0
;
tmp_file_
=
file
;
tmp_file_
=
file
;
is_read_
=
true
;
is_read_
=
true
;
has_wait_
=
false
;
}
}
return
ret
;
return
ret
;
}
}
...
@@ -80,6 +77,7 @@ int ObTmpFileIOHandle::prepare_write(char* write_buf, const int64_t write_size,
...
@@ -80,6 +77,7 @@ int ObTmpFileIOHandle::prepare_write(char* write_buf, const int64_t write_size,
size_
=
write_size
;
size_
=
write_size
;
tmp_file_
=
file
;
tmp_file_
=
file
;
is_read_
=
false
;
is_read_
=
false
;
has_wait_
=
false
;
}
}
return
ret
;
return
ret
;
}
}
...
@@ -87,29 +85,35 @@ int ObTmpFileIOHandle::prepare_write(char* write_buf, const int64_t write_size,
...
@@ -87,29 +85,35 @@ int ObTmpFileIOHandle::prepare_write(char* write_buf, const int64_t write_size,
int
ObTmpFileIOHandle
::
wait
(
const
int64_t
timeout_ms
)
int
ObTmpFileIOHandle
::
wait
(
const
int64_t
timeout_ms
)
{
{
int
ret
=
OB_SUCCESS
;
int
ret
=
OB_SUCCESS
;
for
(
int32_t
i
=
0
;
OB_SUCC
(
ret
)
&&
i
<
block_cache_handles_
.
count
();
i
++
)
{
if
(
OB_UNLIKELY
(
has_wait_
&&
is_read_
))
{
ObBlockCacheHandle
&
tmp
=
block_cache_handles_
.
at
(
i
);
ret
=
OB_ERR_UNEXPECTED
;
MEMCPY
(
tmp
.
buf_
,
tmp
.
block_handle_
.
value_
->
get_buffer
()
+
tmp
.
offset_
,
tmp
.
size_
);
STORAGE_LOG
(
ERROR
,
"read wait() isn't reentrant interface, shouldn't call again"
,
K
(
ret
));
tmp
.
block_handle_
.
reset
();
}
else
{
}
for
(
int32_t
i
=
0
;
OB_SUCC
(
ret
)
&&
i
<
block_cache_handles_
.
count
();
i
++
)
{
for
(
int32_t
i
=
0
;
OB_SUCC
(
ret
)
&&
i
<
page_cache_handles_
.
count
();
i
++
)
{
ObBlockCacheHandle
&
tmp
=
block_cache_handles_
.
at
(
i
);
ObPageCacheHandle
&
tmp
=
page_cache_handles_
.
at
(
i
);
MEMCPY
(
tmp
.
buf_
,
tmp
.
block_handle_
.
value_
->
get_buffer
()
+
tmp
.
offset_
,
tmp
.
size_
);
MEMCPY
(
tmp
.
buf_
,
tmp
.
page_handle_
.
value_
->
get_buffer
()
+
tmp
.
offset_
,
tmp
.
size_
);
tmp
.
block_handle_
.
reset
();
tmp
.
page_handle_
.
reset
();
}
for
(
int32_t
i
=
0
;
OB_SUCC
(
ret
)
&&
i
<
io_handles_
.
count
();
i
++
)
{
ObIOReadHandle
&
tmp
=
io_handles_
.
at
(
i
);
if
(
OB_FAIL
(
tmp
.
macro_handle_
.
wait
(
timeout_ms
)))
{
STORAGE_LOG
(
WARN
,
"fail to wait tmp read io"
,
K
(
ret
));
}
else
{
MEMCPY
(
tmp
.
buf_
,
tmp
.
macro_handle_
.
get_buffer
()
+
tmp
.
offset_
,
tmp
.
size_
);
tmp
.
macro_handle_
.
reset
();
}
}
}
if
(
OB_SUCC
(
ret
))
{
io_handles_
.
reset
();
page_cache_handles_
.
reset
();
block_cache_handles_
.
reset
();
block_cache_handles_
.
reset
();
for
(
int32_t
i
=
0
;
OB_SUCC
(
ret
)
&&
i
<
page_cache_handles_
.
count
();
i
++
)
{
ObPageCacheHandle
&
tmp
=
page_cache_handles_
.
at
(
i
);
MEMCPY
(
tmp
.
buf_
,
tmp
.
page_handle_
.
value_
->
get_buffer
()
+
tmp
.
offset_
,
tmp
.
size_
);
tmp
.
page_handle_
.
reset
();
}
page_cache_handles_
.
reset
();
for
(
int32_t
i
=
0
;
OB_SUCC
(
ret
)
&&
i
<
io_handles_
.
count
();
i
++
)
{
ObIOReadHandle
&
tmp
=
io_handles_
.
at
(
i
);
if
(
OB_FAIL
(
tmp
.
macro_handle_
.
wait
(
timeout_ms
)))
{
STORAGE_LOG
(
WARN
,
"fail to wait tmp read io"
,
K
(
ret
));
}
else
{
MEMCPY
(
tmp
.
buf_
,
tmp
.
macro_handle_
.
get_buffer
()
+
tmp
.
offset_
,
tmp
.
size_
);
tmp
.
macro_handle_
.
reset
();
}
}
io_handles_
.
reset
();
has_wait_
=
true
;
}
}
return
ret
;
return
ret
;
}
}
...
@@ -132,6 +136,7 @@ void ObTmpFileIOHandle::reset()
...
@@ -132,6 +136,7 @@ void ObTmpFileIOHandle::reset()
size_
=
0
;
size_
=
0
;
tmp_file_
=
NULL
;
tmp_file_
=
NULL
;
is_read_
=
false
;
is_read_
=
false
;
has_wait_
=
false
;
}
}
bool
ObTmpFileIOHandle
::
is_valid
()
bool
ObTmpFileIOHandle
::
is_valid
()
...
@@ -1000,6 +1005,7 @@ int ObTmpFileManager::aio_read(const ObTmpFileIOInfo& io_info, ObTmpFileIOHandle
...
@@ -1000,6 +1005,7 @@ int ObTmpFileManager::aio_read(const ObTmpFileIOInfo& io_info, ObTmpFileIOHandle
{
{
int
ret
=
OB_SUCCESS
;
int
ret
=
OB_SUCCESS
;
ObTmpFileHandle
file_handle
;
ObTmpFileHandle
file_handle
;
handle
.
reset
();
if
(
OB_UNLIKELY
(
!
is_inited_
))
{
if
(
OB_UNLIKELY
(
!
is_inited_
))
{
ret
=
OB_NOT_INIT
;
ret
=
OB_NOT_INIT
;
STORAGE_LOG
(
WARN
,
"ObTmpFileManager has not been inited"
,
K
(
ret
));
STORAGE_LOG
(
WARN
,
"ObTmpFileManager has not been inited"
,
K
(
ret
));
...
@@ -1020,6 +1026,7 @@ int ObTmpFileManager::aio_pread(const ObTmpFileIOInfo& io_info, const int64_t of
...
@@ -1020,6 +1026,7 @@ int ObTmpFileManager::aio_pread(const ObTmpFileIOInfo& io_info, const int64_t of
{
{
int
ret
=
OB_SUCCESS
;
int
ret
=
OB_SUCCESS
;
ObTmpFileHandle
file_handle
;
ObTmpFileHandle
file_handle
;
handle
.
reset
();
if
(
OB_UNLIKELY
(
!
is_inited_
))
{
if
(
OB_UNLIKELY
(
!
is_inited_
))
{
ret
=
OB_NOT_INIT
;
ret
=
OB_NOT_INIT
;
STORAGE_LOG
(
WARN
,
"ObTmpFileManager has not been inited"
,
K
(
ret
));
STORAGE_LOG
(
WARN
,
"ObTmpFileManager has not been inited"
,
K
(
ret
));
...
@@ -1040,6 +1047,7 @@ int ObTmpFileManager::read(const ObTmpFileIOInfo& io_info, const int64_t timeout
...
@@ -1040,6 +1047,7 @@ int ObTmpFileManager::read(const ObTmpFileIOInfo& io_info, const int64_t timeout
{
{
int
ret
=
OB_SUCCESS
;
int
ret
=
OB_SUCCESS
;
ObTmpFileHandle
file_handle
;
ObTmpFileHandle
file_handle
;
handle
.
reset
();
if
(
OB_UNLIKELY
(
!
is_inited_
))
{
if
(
OB_UNLIKELY
(
!
is_inited_
))
{
ret
=
OB_NOT_INIT
;
ret
=
OB_NOT_INIT
;
STORAGE_LOG
(
WARN
,
"ObTmpFileManager has not been inited"
,
K
(
ret
));
STORAGE_LOG
(
WARN
,
"ObTmpFileManager has not been inited"
,
K
(
ret
));
...
@@ -1061,6 +1069,7 @@ int ObTmpFileManager::pread(
...
@@ -1061,6 +1069,7 @@ int ObTmpFileManager::pread(
{
{
int
ret
=
OB_SUCCESS
;
int
ret
=
OB_SUCCESS
;
ObTmpFileHandle
file_handle
;
ObTmpFileHandle
file_handle
;
handle
.
reset
();
if
(
OB_UNLIKELY
(
!
is_inited_
))
{
if
(
OB_UNLIKELY
(
!
is_inited_
))
{
ret
=
OB_NOT_INIT
;
ret
=
OB_NOT_INIT
;
STORAGE_LOG
(
WARN
,
"ObTmpFileManager has not been inited"
,
K
(
ret
));
STORAGE_LOG
(
WARN
,
"ObTmpFileManager has not been inited"
,
K
(
ret
));
...
@@ -1081,6 +1090,7 @@ int ObTmpFileManager::aio_write(const ObTmpFileIOInfo& io_info, ObTmpFileIOHandl
...
@@ -1081,6 +1090,7 @@ int ObTmpFileManager::aio_write(const ObTmpFileIOInfo& io_info, ObTmpFileIOHandl
{
{
int
ret
=
OB_SUCCESS
;
int
ret
=
OB_SUCCESS
;
ObTmpFileHandle
file_handle
;
ObTmpFileHandle
file_handle
;
handle
.
reset
();
if
(
OB_UNLIKELY
(
!
is_inited_
))
{
if
(
OB_UNLIKELY
(
!
is_inited_
))
{
ret
=
OB_NOT_INIT
;
ret
=
OB_NOT_INIT
;
STORAGE_LOG
(
WARN
,
"ObTmpFileManager has not been inited"
,
K
(
ret
));
STORAGE_LOG
(
WARN
,
"ObTmpFileManager has not been inited"
,
K
(
ret
));
...
...
src/storage/blocksstable/ob_tmp_file.h
浏览文件 @
3a827ef0
...
@@ -126,6 +126,7 @@ private:
...
@@ -126,6 +126,7 @@ private:
char
*
buf_
;
char
*
buf_
;
int64_t
size_
;
// has read or to write size.
int64_t
size_
;
// has read or to write size.
bool
is_read_
;
bool
is_read_
;
bool
has_wait_
;
DISALLOW_COPY_AND_ASSIGN
(
ObTmpFileIOHandle
);
DISALLOW_COPY_AND_ASSIGN
(
ObTmpFileIOHandle
);
};
};
...
...
unittest/storage/blocksstable/test_tmp_file.cpp
浏览文件 @
3a827ef0
...
@@ -1423,6 +1423,59 @@ TEST_F(TestTmpFile, test_drop_tenant_file)
...
@@ -1423,6 +1423,59 @@ TEST_F(TestTmpFile, test_drop_tenant_file)
ASSERT_EQ
(
0
,
ObTmpFileStore
::
get_instance
().
tenant_file_stores_
.
size
());
ASSERT_EQ
(
0
,
ObTmpFileStore
::
get_instance
().
tenant_file_stores_
.
size
());
}
}
TEST_F
(
TestTmpFile
,
test_handle_double_wait
)
{
int
ret
=
OB_SUCCESS
;
int64_t
dir
=
-
1
;
int64_t
fd
=
-
1
;
ObTmpFileIOInfo
io_info
;
ObTmpFileIOHandle
handle
;
ret
=
ObTmpFileManager
::
get_instance
().
alloc_dir
(
dir
);
ASSERT_EQ
(
OB_SUCCESS
,
ret
);
ret
=
ObTmpFileManager
::
get_instance
().
open
(
fd
,
dir
);
ASSERT_EQ
(
OB_SUCCESS
,
ret
);
char
*
write_buf
=
new
char
[
256
];
for
(
int
i
=
0
;
i
<
256
;
++
i
)
{
write_buf
[
i
]
=
static_cast
<
char
>
(
i
);
}
char
*
read_buf
=
new
char
[
256
];
io_info
.
fd_
=
fd
;
io_info
.
tenant_id_
=
1
;
io_info
.
io_desc_
.
category_
=
USER_IO
;
io_info
.
io_desc_
.
wait_event_no_
=
2
;
io_info
.
buf_
=
write_buf
;
io_info
.
size_
=
256
;
const
int64_t
timeout_ms
=
5000
;
int64_t
write_time
=
ObTimeUtility
::
current_time
();
ret
=
ObTmpFileManager
::
get_instance
().
write
(
io_info
,
timeout_ms
);
write_time
=
ObTimeUtility
::
current_time
()
-
write_time
;
ASSERT_EQ
(
OB_SUCCESS
,
ret
);
io_info
.
buf_
=
read_buf
;
int64_t
read_time
=
ObTimeUtility
::
current_time
();
ret
=
ObTmpFileManager
::
get_instance
().
pread
(
io_info
,
0
,
timeout_ms
,
handle
);
read_time
=
ObTimeUtility
::
current_time
()
-
read_time
;
ASSERT_EQ
(
OB_SUCCESS
,
ret
);
ASSERT_EQ
(
256
,
handle
.
get_data_size
());
int
cmp
=
memcmp
(
handle
.
get_buffer
(),
write_buf
,
256
);
ASSERT_EQ
(
0
,
cmp
);
ASSERT_EQ
(
OB_ERR_UNEXPECTED
,
handle
.
wait
(
timeout_ms
));
STORAGE_LOG
(
INFO
,
"test_handle_double_wait"
);
STORAGE_LOG
(
INFO
,
"io time"
,
K
(
write_time
),
K
(
read_time
));
ObTmpTenantFileStore
*
store
=
NULL
;
OB_TMP_FILE_STORE
.
get_store
(
1
,
store
);
store
->
print_block_usage
();
ObMallocAllocator
::
get_instance
()
->
print_tenant_memory_usage
(
1
);
ObMallocAllocator
::
get_instance
()
->
print_tenant_ctx_memory_usage
(
1
);
ObMallocAllocator
::
get_instance
()
->
print_tenant_memory_usage
(
500
);
ObMallocAllocator
::
get_instance
()
->
print_tenant_ctx_memory_usage
(
500
);
ObTmpFileManager
::
get_instance
().
remove
(
fd
);
}
}
// end namespace unittest
}
// end namespace unittest
}
// end namespace oceanbase
}
// end namespace oceanbase
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录