Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
kvdb
rocksdb
提交
b5750790
R
rocksdb
项目概览
kvdb
/
rocksdb
12 个月 前同步成功
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rocksdb
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b5750790
编写于
2月 01, 2016
作者:
S
Siying Dong
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #968 from yuslepukhin/one_shot_buffer
Enable per-request buffer allocation in RandomAccessFile
上级
1ad81829
36300fbb
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
77 addition
and
41 deletion
+77
-41
include/rocksdb/options.h
include/rocksdb/options.h
+3
-0
port/win/env_win.cc
port/win/env_win.cc
+74
-41
未找到文件。
include/rocksdb/options.h
浏览文件 @
b5750790
...
...
@@ -1121,6 +1121,9 @@ struct DBOptions {
// This option is currently honored only on Windows
//
// Default: 1 Mb
//
// Special value: 0 - means do not maintain per instance buffer. Allocate
// per request buffer and avoid locking.
size_t
random_access_max_buffer_size
;
// This is the maximum buffer size that is used by WritableFileWriter.
...
...
port/win/env_win.cc
浏览文件 @
b5750790
...
...
@@ -766,6 +766,18 @@ class WinRandomAccessFile : public RandomAccessFile {
return
read
;
}
void
CalculateReadParameters
(
uint64_t
offset
,
size_t
bytes_requested
,
size_t
&
actual_bytes_toread
,
uint64_t
&
first_page_start
)
const
{
const
size_t
alignment
=
buffer_
.
Alignment
();
first_page_start
=
TruncateToPageBoundary
(
alignment
,
offset
);
const
uint64_t
last_page_start
=
TruncateToPageBoundary
(
alignment
,
offset
+
bytes_requested
-
1
);
actual_bytes_toread
=
(
last_page_start
-
first_page_start
)
+
alignment
;
}
public:
WinRandomAccessFile
(
const
std
::
string
&
fname
,
HANDLE
hFile
,
size_t
alignment
,
const
EnvOptions
&
options
)
...
...
@@ -797,66 +809,87 @@ class WinRandomAccessFile : public RandomAccessFile {
virtual
Status
Read
(
uint64_t
offset
,
size_t
n
,
Slice
*
result
,
char
*
scratch
)
const
override
{
Status
s
;
SSIZE_T
r
=
-
1
;
size_t
left
=
n
;
char
*
dest
=
scratch
;
if
(
n
==
0
)
{
*
result
=
Slice
(
scratch
,
0
);
return
s
;
}
// When in unbuffered mode we need to do the following changes:
// - use our own aligned buffer
// - always read at the offset of that is a multiple of alignment
if
(
!
use_os_buffer_
)
{
std
::
unique_lock
<
std
::
mutex
>
lock
(
buffer_mut_
);
// Let's see if at least some of the requested data is already
// in the buffer
if
(
offset
>=
buffered_start_
&&
offset
<
(
buffered_start_
+
buffer_
.
CurrentSize
()))
{
size_t
buffer_offset
=
offset
-
buffered_start_
;
r
=
buffer_
.
Read
(
dest
,
buffer_offset
,
left
);
assert
(
r
>=
0
);
uint64_t
first_page_start
=
0
;
size_t
actual_bytes_toread
=
0
;
size_t
bytes_requested
=
left
;
left
-=
size_t
(
r
);
offset
+=
r
;
dest
+=
r
;
}
if
(
!
read_ahead_
&&
random_access_max_buffer_size_
==
0
)
{
CalculateReadParameters
(
offset
,
bytes_requested
,
actual_bytes_toread
,
first_page_start
);
assert
(
actual_bytes_toread
>
0
);
// Still some left or none was buffered
if
(
left
>
0
)
{
// Figure out the start/end offset for reading and amount to read
const
size_t
alignment
=
buffer_
.
Alignment
();
const
size_t
first_page_start
=
TruncateToPageBoundary
(
alignment
,
offset
);
r
=
ReadIntoOneShotBuffer
(
offset
,
first_page_start
,
actual_bytes_toread
,
left
,
dest
);
}
else
{
std
::
unique_lock
<
std
::
mutex
>
lock
(
buffer_mut_
);
size_t
bytes_requested
=
left
;
if
(
read_ahead_
&&
bytes_requested
<
compaction_readahead_size_
)
{
bytes_requested
=
compaction_readahead_size_
;
// Let's see if at least some of the requested data is already
// in the buffer
if
(
offset
>=
buffered_start_
&&
offset
<
(
buffered_start_
+
buffer_
.
CurrentSize
()))
{
size_t
buffer_offset
=
offset
-
buffered_start_
;
r
=
buffer_
.
Read
(
dest
,
buffer_offset
,
left
);
assert
(
r
>=
0
);
left
-=
size_t
(
r
);
offset
+=
r
;
dest
+=
r
;
}
const
size_t
last_page_start
=
TruncateToPageBoundary
(
alignment
,
offset
+
bytes_requested
-
1
);
const
size_t
actual_bytes_toread
=
(
last_page_start
-
first_page_start
)
+
alignment
;
// Still some left or none was buffered
if
(
left
>
0
)
{
// Figure out the start/end offset for reading and amount to read
bytes_requested
=
left
;
if
(
read_ahead_
&&
bytes_requested
<
compaction_readahead_size_
)
{
bytes_requested
=
compaction_readahead_size_
;
}
CalculateReadParameters
(
offset
,
bytes_requested
,
actual_bytes_toread
,
first_page_start
);
assert
(
actual_bytes_toread
>
0
);
if
(
buffer_
.
Capacity
()
<
actual_bytes_toread
)
{
// If we are in read-ahead mode or the requested size
// exceeds max buffer size then use one-shot
// big buffer otherwise reallocate main buffer
if
(
read_ahead_
||
if
(
buffer_
.
Capacity
()
<
actual_bytes_toread
)
{
// If we are in read-ahead mode or the requested size
// exceeds max buffer size then use one-shot
// big buffer otherwise reallocate main buffer
if
(
read_ahead_
||
(
actual_bytes_toread
>
random_access_max_buffer_size_
))
{
// Unlock the mutex since we are not using instance buffer
lock
.
unlock
();
r
=
ReadIntoOneShotBuffer
(
offset
,
first_page_start
,
actual_bytes_toread
,
left
,
dest
);
}
else
{
buffer_
.
AllocateNewBuffer
(
actual_bytes_toread
);
// Unlock the mutex since we are not using instance buffer
lock
.
unlock
();
r
=
ReadIntoOneShotBuffer
(
offset
,
first_page_start
,
actual_bytes_toread
,
left
,
dest
);
}
else
{
buffer_
.
AllocateNewBuffer
(
actual_bytes_toread
);
r
=
ReadIntoInstanceBuffer
(
offset
,
first_page_start
,
actual_bytes_toread
,
left
,
dest
);
}
}
else
{
buffer_
.
Clear
();
r
=
ReadIntoInstanceBuffer
(
offset
,
first_page_start
,
actual_bytes_toread
,
left
,
dest
);
actual_bytes_toread
,
left
,
dest
);
}
}
else
{
buffer_
.
Clear
();
r
=
ReadIntoInstanceBuffer
(
offset
,
first_page_start
,
actual_bytes_toread
,
left
,
dest
);
}
}
}
else
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录