Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
kvdb
rocksdb
提交
5c791323
R
rocksdb
项目概览
kvdb
/
rocksdb
11 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
5c791323
编写于
7月 08, 2015
作者:
U
unknown
提交者:
Dmitri Smirnov
7月 09, 2015
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Revert the changes related to Options, as requested to seperate them into
a different patch.
上级
d8586ab2
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
100 addition
and
255 deletion
+100
-255
include/rocksdb/utilities/convenience.h
include/rocksdb/utilities/convenience.h
+0
-14
table/plain_table_builder.cc
table/plain_table_builder.cc
+16
-15
table/plain_table_builder.h
table/plain_table_builder.h
+8
-4
table/plain_table_factory.cc
table/plain_table_factory.cc
+19
-19
table/plain_table_factory.h
table/plain_table_factory.h
+35
-11
table/plain_table_reader.cc
table/plain_table_reader.cc
+11
-11
table/plain_table_reader.h
table/plain_table_reader.h
+7
-5
util/options_helper.cc
util/options_helper.cc
+4
-97
util/options_test.cc
util/options_test.cc
+0
-79
未找到文件。
include/rocksdb/utilities/convenience.h
浏览文件 @
5c791323
...
...
@@ -30,11 +30,6 @@ Status GetBlockBasedTableOptionsFromMap(
const
std
::
unordered_map
<
std
::
string
,
std
::
string
>&
opts_map
,
BlockBasedTableOptions
*
new_table_options
);
Status
GetPlainTableOptionsFromMap
(
const
PlainTableOptions
&
table_options
,
const
std
::
unordered_map
<
std
::
string
,
std
::
string
>&
opts_map
,
PlainTableOptions
*
new_table_options
);
// Take a string representation of option names and values, apply them into the
// base_options, and return the new options as a result. The string has the
// following format:
...
...
@@ -53,20 +48,11 @@ Status GetDBOptionsFromString(
const
std
::
string
&
opts_str
,
DBOptions
*
new_options
);
Status
GetPlainTableOptionsFromString
(
const
PlainTableOptions
&
table_options
,
const
std
::
string
&
opts_str
,
PlainTableOptions
*
new_table_options
);
Status
GetBlockBasedTableOptionsFromString
(
const
BlockBasedTableOptions
&
table_options
,
const
std
::
string
&
opts_str
,
BlockBasedTableOptions
*
new_table_options
);
Status
GetMemTableRepFactoryFromString
(
const
std
::
string
&
opts_str
,
MemTableRepFactory
**
new_mem_factory
);
Status
GetOptionsFromString
(
const
Options
&
base_options
,
const
std
::
string
&
opts_str
,
Options
*
new_options
);
...
...
table/plain_table_builder.cc
浏览文件 @
5c791323
...
...
@@ -60,32 +60,33 @@ extern const uint64_t kLegacyPlainTableMagicNumber = 0x4f3418eb7a8f13b8ull;
PlainTableBuilder
::
PlainTableBuilder
(
const
ImmutableCFOptions
&
ioptions
,
const
std
::
vector
<
std
::
unique_ptr
<
IntTblPropCollectorFactory
>>*
int_tbl_prop_collector_factories
,
const
PlainTableOptions
&
table_options
,
WritableFile
*
file
,
uint32_t
num_probes
)
const
std
::
vector
<
std
::
unique_ptr
<
IntTblPropCollectorFactory
>>*
int_tbl_prop_collector_factories
,
WritableFile
*
file
,
uint32_t
user_key_len
,
EncodingType
encoding_type
,
size_t
index_sparseness
,
uint32_t
bloom_bits_per_key
,
uint32_t
num_probes
,
size_t
huge_page_tlb_size
,
double
hash_table_ratio
,
bool
store_index_in_file
)
:
ioptions_
(
ioptions
),
bloom_block_
(
num_probes
),
file_
(
file
),
bloom_bits_per_key_
(
table_options
.
bloom_bits_per_key
),
huge_page_tlb_size_
(
table_options
.
huge_page_tlb_size
),
encoder_
(
table_options
.
encoding_type
,
table_options
.
user_key_len
,
i
options
.
prefix_extractor
,
table_options
.
i
ndex_sparseness
),
store_index_in_file_
(
table_options
.
store_index_in_file
),
bloom_bits_per_key_
(
bloom_bits_per_key
),
huge_page_tlb_size_
(
huge_page_tlb_size
),
encoder_
(
encoding_type
,
user_key_len
,
ioptions
.
prefix_extractor
,
index_sparseness
),
store_index_in_file_
(
store_index_in_file
),
prefix_extractor_
(
ioptions
.
prefix_extractor
)
{
// Build index block and save it in the file if hash_table_ratio > 0
if
(
store_index_in_file_
)
{
assert
(
table_options
.
hash_table_ratio
>
0
||
IsTotalOrderMode
());
assert
(
hash_table_ratio
>
0
||
IsTotalOrderMode
());
index_builder_
.
reset
(
new
PlainTableIndexBuilder
(
&
arena_
,
ioptions
,
table_options
.
index_sparseness
,
table_options
.
hash_table_ratio
,
huge_page_tlb_size_
));
new
PlainTableIndexBuilder
(
&
arena_
,
ioptions
,
index_sparseness
,
hash_table_ratio
,
huge_page_tlb_size_
));
assert
(
bloom_bits_per_key_
>
0
);
properties_
.
user_collected_properties
[
PlainTablePropertyNames
::
kBloomVersion
]
=
"1"
;
// For future use
}
properties_
.
fixed_key_len
=
table_options
.
user_key_len
;
properties_
.
fixed_key_len
=
user_key_len
;
// for plain table, we put all the data in a big chuck.
properties_
.
num_data_blocks
=
1
;
...
...
@@ -94,7 +95,7 @@ PlainTableBuilder::PlainTableBuilder(
properties_
.
filter_size
=
0
;
// To support roll-back to previous version, now still use version 0 for
// plain encoding.
properties_
.
format_version
=
(
table_options
.
encoding_type
==
kPlain
)
?
0
:
1
;
properties_
.
format_version
=
(
encoding_type
==
kPlain
)
?
0
:
1
;
if
(
ioptions_
.
prefix_extractor
)
{
properties_
.
user_collected_properties
...
...
table/plain_table_builder.h
浏览文件 @
5c791323
...
...
@@ -30,10 +30,14 @@ class PlainTableBuilder: public TableBuilder {
// caller to close the file after calling Finish(). The output file
// will be part of level specified by 'level'. A value of -1 means
// that the caller does not know which level the output file will reside.
PlainTableBuilder
(
const
ImmutableCFOptions
&
ioptions
,
const
std
::
vector
<
std
::
unique_ptr
<
IntTblPropCollectorFactory
>>*
int_tbl_prop_collector_factories
,
const
PlainTableOptions
&
table_options
,
WritableFile
*
file
,
uint32_t
num_probes
=
6
);
PlainTableBuilder
(
const
ImmutableCFOptions
&
ioptions
,
const
std
::
vector
<
std
::
unique_ptr
<
IntTblPropCollectorFactory
>>*
int_tbl_prop_collector_factories
,
WritableFile
*
file
,
uint32_t
user_key_size
,
EncodingType
encoding_type
,
size_t
index_sparseness
,
uint32_t
bloom_bits_per_key
,
uint32_t
num_probes
=
6
,
size_t
huge_page_tlb_size
=
0
,
double
hash_table_ratio
=
0
,
bool
store_index_in_file
=
false
);
// REQUIRES: Either Finish() or Abandon() has been called.
~
PlainTableBuilder
();
...
...
table/plain_table_factory.cc
浏览文件 @
5c791323
...
...
@@ -17,11 +17,13 @@ namespace rocksdb {
Status
PlainTableFactory
::
NewTableReader
(
const
ImmutableCFOptions
&
ioptions
,
const
EnvOptions
&
env_options
,
const
InternalKeyComparator
&
icomp
,
std
::
unique_ptr
<
RandomAccessFile
>&&
file
,
unique_ptr
<
RandomAccessFile
>&&
file
,
uint64_t
file_size
,
std
::
unique_ptr
<
TableReader
>*
table
)
const
{
return
PlainTableReader
::
Open
(
ioptions
,
env_options
,
table_options_
,
icomp
,
std
::
move
(
file
),
file_size
,
table
);
unique_ptr
<
TableReader
>*
table
)
const
{
return
PlainTableReader
::
Open
(
ioptions
,
env_options
,
icomp
,
std
::
move
(
file
),
file_size
,
table
,
bloom_bits_per_key_
,
hash_table_ratio_
,
index_sparseness_
,
huge_page_tlb_size_
,
full_scan_mode_
);
}
TableBuilder
*
PlainTableFactory
::
NewTableBuilder
(
...
...
@@ -31,9 +33,11 @@ TableBuilder* PlainTableFactory::NewTableBuilder(
// in-memory dbs. The skip_filters optimization is not useful for plain
// tables
//
return
new
PlainTableBuilder
(
table_builder_options
.
ioptions
,
table_builder_options
.
int_tbl_prop_collector_factories
,
table_options_
,
file
,
6
);
return
new
PlainTableBuilder
(
table_builder_options
.
ioptions
,
table_builder_options
.
int_tbl_prop_collector_factories
,
file
,
user_key_len_
,
encoding_type_
,
index_sparseness_
,
bloom_bits_per_key_
,
6
,
huge_page_tlb_size_
,
hash_table_ratio_
,
store_index_in_file_
);
}
std
::
string
PlainTableFactory
::
GetPrintableTableOptions
()
const
{
...
...
@@ -43,36 +47,32 @@ std::string PlainTableFactory::GetPrintableTableOptions() const {
char
buffer
[
kBufferSize
];
snprintf
(
buffer
,
kBufferSize
,
" user_key_len: %u
\n
"
,
table_options_
.
user_key_len
);
user_key_len_
);
ret
.
append
(
buffer
);
snprintf
(
buffer
,
kBufferSize
,
" bloom_bits_per_key: %d
\n
"
,
table_options_
.
bloom_bits_per_key
);
bloom_bits_per_key_
);
ret
.
append
(
buffer
);
snprintf
(
buffer
,
kBufferSize
,
" hash_table_ratio: %lf
\n
"
,
table_options_
.
hash_table_ratio
);
hash_table_ratio_
);
ret
.
append
(
buffer
);
snprintf
(
buffer
,
kBufferSize
,
" index_sparseness: %"
ROCKSDB_PRIszt
"
\n
"
,
table_options_
.
index_sparseness
);
index_sparseness_
);
ret
.
append
(
buffer
);
snprintf
(
buffer
,
kBufferSize
,
" huge_page_tlb_size: %"
ROCKSDB_PRIszt
"
\n
"
,
table_options_
.
huge_page_tlb_size
);
huge_page_tlb_size_
);
ret
.
append
(
buffer
);
snprintf
(
buffer
,
kBufferSize
,
" encoding_type: %d
\n
"
,
table_options_
.
encoding_type
);
encoding_type_
);
ret
.
append
(
buffer
);
snprintf
(
buffer
,
kBufferSize
,
" full_scan_mode: %d
\n
"
,
table_options_
.
full_scan_mode
);
full_scan_mode_
);
ret
.
append
(
buffer
);
snprintf
(
buffer
,
kBufferSize
,
" store_index_in_file: %d
\n
"
,
table_options_
.
store_index_in_file
);
store_index_in_file_
);
ret
.
append
(
buffer
);
return
ret
;
}
const
PlainTableOptions
&
PlainTableFactory
::
GetTableOptions
()
const
{
return
table_options_
;
}
extern
TableFactory
*
NewPlainTableFactory
(
const
PlainTableOptions
&
options
)
{
return
new
PlainTableFactory
(
options
);
}
...
...
table/plain_table_factory.h
浏览文件 @
5c791323
...
...
@@ -127,18 +127,37 @@ class TableBuilder;
class
PlainTableFactory
:
public
TableFactory
{
public:
~
PlainTableFactory
()
{}
explicit
PlainTableFactory
(
const
PlainTableOptions
&
table_options
=
PlainTableOptions
())
:
table_options_
(
table_options
)
{}
// user_key_len is the length of the user key. If it is set to be
// kPlainTableVariableLength, then it means variable length. Otherwise, all
// the keys need to have the fix length of this value. bloom_bits_per_key is
// number of bits used for bloom filer per key. hash_table_ratio is
// the desired utilization of the hash table used for prefix hashing.
// hash_table_ratio = number of prefixes / #buckets in the hash table
// hash_table_ratio = 0 means skip hash table but only replying on binary
// search.
// index_sparseness determines index interval for keys
// inside the same prefix. It will be the maximum number of linear search
// required after hash and binary search.
// index_sparseness = 0 means index for every key.
// huge_page_tlb_size determines whether to allocate hash indexes from huge
// page TLB and the page size if allocating from there. See comments of
// Arena::AllocateAligned() for details.
explicit
PlainTableFactory
(
const
PlainTableOptions
&
options
=
PlainTableOptions
())
:
user_key_len_
(
options
.
user_key_len
),
bloom_bits_per_key_
(
options
.
bloom_bits_per_key
),
hash_table_ratio_
(
options
.
hash_table_ratio
),
index_sparseness_
(
options
.
index_sparseness
),
huge_page_tlb_size_
(
options
.
huge_page_tlb_size
),
encoding_type_
(
options
.
encoding_type
),
full_scan_mode_
(
options
.
full_scan_mode
),
store_index_in_file_
(
options
.
store_index_in_file
)
{}
const
char
*
Name
()
const
override
{
return
"PlainTable"
;
}
Status
NewTableReader
(
const
ImmutableCFOptions
&
options
,
const
EnvOptions
&
soptions
,
const
InternalKeyComparator
&
internal_comparator
,
std
::
unique_ptr
<
RandomAccessFile
>&&
file
,
uint64_t
file_size
,
std
::
unique_ptr
<
TableReader
>*
table
)
const
override
;
unique_ptr
<
RandomAccessFile
>&&
file
,
uint64_t
file_size
,
unique_ptr
<
TableReader
>*
table
)
const
override
;
TableBuilder
*
NewTableBuilder
(
const
TableBuilderOptions
&
table_builder_options
,
WritableFile
*
file
)
const
override
;
...
...
@@ -157,10 +176,15 @@ class PlainTableFactory : public TableFactory {
return
Status
::
OK
();
}
const
PlainTableOptions
&
GetTableOptions
()
const
;
private:
PlainTableOptions
table_options_
;
uint32_t
user_key_len_
;
int
bloom_bits_per_key_
;
double
hash_table_ratio_
;
size_t
index_sparseness_
;
size_t
huge_page_tlb_size_
;
EncodingType
encoding_type_
;
bool
full_scan_mode_
;
bool
store_index_in_file_
;
};
}
// namespace rocksdb
...
...
table/plain_table_reader.cc
浏览文件 @
5c791323
...
...
@@ -90,7 +90,7 @@ class PlainTableIterator : public Iterator {
extern
const
uint64_t
kPlainTableMagicNumber
;
PlainTableReader
::
PlainTableReader
(
const
ImmutableCFOptions
&
ioptions
,
std
::
unique_ptr
<
RandomAccessFile
>&&
file
,
unique_ptr
<
RandomAccessFile
>&&
file
,
const
EnvOptions
&
storage_options
,
const
InternalKeyComparator
&
icomparator
,
EncodingType
encoding_type
,
...
...
@@ -114,11 +114,13 @@ PlainTableReader::~PlainTableReader() {
Status
PlainTableReader
::
Open
(
const
ImmutableCFOptions
&
ioptions
,
const
EnvOptions
&
env_options
,
const
PlainTableOptions
&
table_options
,
const
InternalKeyComparator
&
internal_comparator
,
std
::
unique_ptr
<
RandomAccessFile
>&&
file
,
unique_ptr
<
RandomAccessFile
>&&
file
,
uint64_t
file_size
,
std
::
unique_ptr
<
TableReader
>*
table_reader
)
{
unique_ptr
<
TableReader
>*
table_reader
,
const
int
bloom_bits_per_key
,
double
hash_table_ratio
,
size_t
index_sparseness
,
size_t
huge_page_tlb_size
,
bool
full_scan_mode
)
{
assert
(
ioptions
.
allow_mmap_reads
);
if
(
file_size
>
PlainTableIndex
::
kMaxFileSize
)
{
return
Status
::
NotSupported
(
"File is too large for PlainTableReader!"
);
...
...
@@ -131,12 +133,12 @@ Status PlainTableReader::Open(const ImmutableCFOptions& ioptions,
return
s
;
}
assert
(
table_options
.
hash_table_ratio
>=
0.0
);
assert
(
hash_table_ratio
>=
0.0
);
auto
&
user_props
=
props
->
user_collected_properties
;
auto
prefix_extractor_in_file
=
user_props
.
find
(
PlainTablePropertyNames
::
kPrefixExtractorName
);
if
(
!
table_options
.
full_scan_mode
&&
prefix_extractor_in_file
!=
user_props
.
end
())
{
if
(
!
full_scan_mode
&&
prefix_extractor_in_file
!=
user_props
.
end
())
{
if
(
!
ioptions
.
prefix_extractor
)
{
return
Status
::
InvalidArgument
(
"Prefix extractor is missing when opening a PlainTable built "
...
...
@@ -166,11 +168,9 @@ Status PlainTableReader::Open(const ImmutableCFOptions& ioptions,
return
s
;
}
if
(
!
table_options
.
full_scan_mode
)
{
s
=
new_reader
->
PopulateIndex
(
props
,
table_options
.
bloom_bits_per_key
,
table_options
.
hash_table_ratio
,
table_options
.
index_sparseness
,
table_options
.
huge_page_tlb_size
);
if
(
!
full_scan_mode
)
{
s
=
new_reader
->
PopulateIndex
(
props
,
bloom_bits_per_key
,
hash_table_ratio
,
index_sparseness
,
huge_page_tlb_size
);
if
(
!
s
.
ok
())
{
return
s
;
}
...
...
table/plain_table_reader.h
浏览文件 @
5c791323
...
...
@@ -55,10 +55,12 @@ class PlainTableReader: public TableReader {
public:
static
Status
Open
(
const
ImmutableCFOptions
&
ioptions
,
const
EnvOptions
&
env_options
,
const
PlainTableOptions
&
table_options
,
const
InternalKeyComparator
&
internal_comparator
,
std
::
unique_ptr
<
RandomAccessFile
>&&
file
,
uint64_t
file_size
,
std
::
unique_ptr
<
TableReader
>*
table
);
unique_ptr
<
RandomAccessFile
>&&
file
,
uint64_t
file_size
,
unique_ptr
<
TableReader
>*
table
,
const
int
bloom_bits_per_key
,
double
hash_table_ratio
,
size_t
index_sparseness
,
size_t
huge_page_tlb_size
,
bool
full_scan_mode
);
Iterator
*
NewIterator
(
const
ReadOptions
&
,
Arena
*
arena
=
nullptr
)
override
;
...
...
@@ -81,7 +83,7 @@ class PlainTableReader: public TableReader {
}
PlainTableReader
(
const
ImmutableCFOptions
&
ioptions
,
std
::
unique_ptr
<
RandomAccessFile
>&&
file
,
unique_ptr
<
RandomAccessFile
>&&
file
,
const
EnvOptions
&
env_options
,
const
InternalKeyComparator
&
internal_comparator
,
EncodingType
encoding_type
,
uint64_t
file_size
,
...
...
@@ -132,7 +134,7 @@ class PlainTableReader: public TableReader {
Arena
arena_
;
const
ImmutableCFOptions
&
ioptions_
;
std
::
unique_ptr
<
RandomAccessFile
>
file_
;
unique_ptr
<
RandomAccessFile
>
file_
;
uint64_t
file_size_
;
std
::
shared_ptr
<
const
TableProperties
>
table_properties_
;
...
...
util/options_helper.cc
浏览文件 @
5c791323
...
...
@@ -10,16 +10,13 @@
#include "rocksdb/cache.h"
#include "rocksdb/filter_policy.h"
#include "rocksdb/options.h"
#include "rocksdb/memtablerep.h"
#include "rocksdb/rate_limiter.h"
#include "rocksdb/slice_transform.h"
#include "rocksdb/table.h"
#include "rocksdb/utilities/convenience.h"
#include "table/block_based_table_factory.h"
#include "table/plain_table_factory.h"
#include "util/logging.h"
#include "util/options_helper.h"
#include "util/string_util.h"
namespace
rocksdb
{
...
...
@@ -269,7 +266,7 @@ Status GetMutableOptionsFromStrings(
return
Status
::
InvalidArgument
(
"unsupported dynamic option: "
+
o
.
first
);
}
}
catch
(
const
std
::
exception
&
e
)
{
}
catch
(
std
::
exception
&
e
)
{
return
Status
::
InvalidArgument
(
"error parsing "
+
o
.
first
+
":"
+
std
::
string
(
e
.
what
()));
}
...
...
@@ -394,27 +391,6 @@ bool ParseColumnFamilyOption(const std::string& name, const std::string& value,
return
false
;
}
new_options
->
table_factory
.
reset
(
NewBlockBasedTableFactory
(
table_opt
));
}
else
if
(
name
==
"plain_table_factory"
)
{
PlainTableOptions
table_opt
,
base_table_options
;
auto
plain_table_factory
=
dynamic_cast
<
PlainTableFactory
*>
(
new_options
->
table_factory
.
get
());
if
(
plain_table_factory
!=
nullptr
)
{
base_table_options
=
plain_table_factory
->
GetTableOptions
();
}
Status
table_opt_s
=
GetPlainTableOptionsFromString
(
base_table_options
,
value
,
&
table_opt
);
if
(
!
table_opt_s
.
ok
())
{
return
false
;
}
new_options
->
table_factory
.
reset
(
NewPlainTableFactory
(
table_opt
));
}
else
if
(
name
==
"memtablerep"
)
{
MemTableRepFactory
*
new_mem_factory
;
Status
mem_factory_s
=
GetMemTableRepFactoryFromString
(
value
,
&
new_mem_factory
);
if
(
!
mem_factory_s
.
ok
())
{
return
false
;
}
new_options
->
memtable_factory
.
reset
(
new_mem_factory
);
}
else
if
(
name
==
"min_write_buffer_number_to_merge"
)
{
new_options
->
min_write_buffer_number_to_merge
=
ParseInt
(
value
);
}
else
if
(
name
==
"max_write_buffer_number_to_maintain"
)
{
...
...
@@ -505,7 +481,7 @@ bool ParseColumnFamilyOption(const std::string& name, const std::string& value,
return
false
;
}
}
catch
(
const
std
::
exception
&
e
)
{
catch
(
std
::
exception
&
e
)
{
return
false
;
}
return
true
;
...
...
@@ -653,7 +629,7 @@ Status GetBlockBasedTableOptionsFromMap(
}
else
{
return
Status
::
InvalidArgument
(
"Unrecognized option: "
+
o
.
first
);
}
}
catch
(
const
std
::
exception
&
e
)
{
}
catch
(
std
::
exception
&
e
)
{
return
Status
::
InvalidArgument
(
"error parsing "
+
o
.
first
+
":"
+
std
::
string
(
e
.
what
()));
}
...
...
@@ -708,7 +684,7 @@ Status GetPlainTableOptionsFromMap(
}
else
{
return
Status
::
InvalidArgument
(
"Unrecognized option: "
+
o
.
first
);
}
}
catch
(
const
std
::
exception
&
e
)
{
}
catch
(
std
::
exception
&
e
)
{
return
Status
::
InvalidArgument
(
"error parsing "
+
o
.
first
+
":"
+
std
::
string
(
e
.
what
()));
}
...
...
@@ -716,75 +692,6 @@ Status GetPlainTableOptionsFromMap(
return
Status
::
OK
();
}
Status
GetPlainTableOptionsFromString
(
const
PlainTableOptions
&
table_options
,
const
std
::
string
&
opts_str
,
PlainTableOptions
*
new_table_options
)
{
std
::
unordered_map
<
std
::
string
,
std
::
string
>
opts_map
;
Status
s
=
StringToMap
(
opts_str
,
&
opts_map
);
if
(
!
s
.
ok
())
{
return
s
;
}
return
GetPlainTableOptionsFromMap
(
table_options
,
opts_map
,
new_table_options
);
}
Status
GetMemTableRepFactoryFromString
(
const
std
::
string
&
opts_str
,
MemTableRepFactory
**
new_mem_factory
)
{
std
::
vector
<
std
::
string
>
opts_list
=
StringSplit
(
opts_str
,
':'
);
size_t
len
=
opts_list
.
size
();
if
(
opts_list
[
0
]
==
"skip_list"
)
{
// Expecting format
// skip_list:lookahead
if
(
2
==
len
)
{
size_t
lookahead
=
ParseSizeT
(
opts_list
[
1
]);
*
new_mem_factory
=
new
SkipListFactory
(
lookahead
);
}
else
if
(
1
==
len
)
{
*
new_mem_factory
=
new
SkipListFactory
();
}
else
{
return
Status
::
InvalidArgument
(
"Can't parse option "
,
opts_str
);
}
}
else
if
(
opts_list
[
0
]
==
"prefix_hash"
)
{
// Expecting format
// prfix_hash:hash_bucket_count
if
(
2
==
len
)
{
size_t
hash_bucket_count
=
ParseSizeT
(
opts_list
[
1
]);
*
new_mem_factory
=
NewHashSkipListRepFactory
(
hash_bucket_count
);
}
else
if
(
1
==
len
)
{
*
new_mem_factory
=
NewHashSkipListRepFactory
();
}
else
{
return
Status
::
InvalidArgument
(
"Can't parse option "
,
opts_str
);
}
}
else
if
(
opts_list
[
0
]
==
"hash_linkedlist"
)
{
// Expecting format
// hash_linkedlist:hash_bucket_count
if
(
2
==
len
)
{
size_t
hash_bucket_count
=
ParseSizeT
(
opts_list
[
1
]);
*
new_mem_factory
=
NewHashLinkListRepFactory
(
hash_bucket_count
);
}
else
if
(
1
==
len
)
{
*
new_mem_factory
=
NewHashLinkListRepFactory
();
}
else
{
return
Status
::
InvalidArgument
(
"Can't parse option "
,
opts_str
);
}
}
else
if
(
opts_list
[
0
]
==
"vector"
)
{
if
(
1
==
len
)
{
*
new_mem_factory
=
new
VectorRepFactory
;
}
else
{
return
Status
::
InvalidArgument
(
"Can't parse option "
,
opts_str
);
}
}
else
if
(
opts_list
[
0
]
==
"cuckoo"
)
{
return
Status
::
InvalidArgument
(
"cuckoo is not supported for now"
);
// TODO(bahuang): cuckoo is not supported for now
// *new_mem_factory = NewHashCuckooRepFactory(
// options.write_buffer_size, FLAGS_key_size + FLAGS_value_size));
}
else
{
return
Status
::
InvalidArgument
(
"Can't parse option "
+
opts_str
);
}
return
Status
::
OK
();
}
Status
GetColumnFamilyOptionsFromMap
(
const
ColumnFamilyOptions
&
base_options
,
const
std
::
unordered_map
<
std
::
string
,
std
::
string
>&
opts_map
,
...
...
util/options_test.cc
浏览文件 @
5c791323
...
...
@@ -16,12 +16,10 @@
#include "rocksdb/cache.h"
#include "rocksdb/options.h"
#include "rocksdb/memtablerep.h"
#include "rocksdb/table.h"
#include "rocksdb/utilities/convenience.h"
#include "rocksdb/utilities/leveldb_options.h"
#include "table/block_based_table_factory.h"
#include "table/plain_table_factory.h"
#include "util/random.h"
#include "util/testharness.h"
...
...
@@ -421,18 +419,6 @@ TEST_F(OptionsTest, GetColumnFamilyOptionsFromStringTest) {
ASSERT_NOK
(
GetColumnFamilyOptionsFromString
(
base_cf_opt
,
"optimize_filters_for_hits=junk"
,
&
new_cf_opt
));
// Parsing PlainTableOption
ASSERT_OK
(
GetColumnFamilyOptionsFromString
(
base_cf_opt
,
"plain_table_factory={user_key_len=16;bloom_bits_per_key=10;};"
,
&
new_cf_opt
));
// Paring Memtable Factory Options
ASSERT_OK
(
GetColumnFamilyOptionsFromString
(
base_cf_opt
,
"memtablerep=prefix_hash;"
,
&
new_cf_opt
));
}
#endif // !ROCKSDB_LITE
...
...
@@ -491,71 +477,6 @@ TEST_F(OptionsTest, GetBlockBasedTableOptionsFromString) {
}
#endif // !ROCKSDB_LITE
#ifndef ROCKSDB_LITE // GetPlainTableOptionsFromString is not supported
TEST_F
(
OptionsTest
,
GetPlainTableOptionsFromString
){
PlainTableOptions
table_opt
;
PlainTableOptions
new_opt
;
// make sure default values are overwritten by something else
ASSERT_OK
(
GetPlainTableOptionsFromString
(
table_opt
,
"user_key_len=16;bloom_bits_per_key=8;hash_table_ratio=0.5;"
"index_sparseness=8;huge_page_tlb_size=20;encoding_type=kPrefix;"
"full_scan_mode=1;store_index_in_file=1"
,
&
new_opt
));
ASSERT_EQ
(
new_opt
.
user_key_len
,
16
);
ASSERT_EQ
(
new_opt
.
bloom_bits_per_key
,
8
);
ASSERT_EQ
(
new_opt
.
hash_table_ratio
,
0.5
);
ASSERT_EQ
(
new_opt
.
index_sparseness
,
8
);
ASSERT_EQ
(
new_opt
.
huge_page_tlb_size
,
20
);
ASSERT_EQ
(
new_opt
.
encoding_type
,
kPrefix
);
ASSERT_TRUE
(
new_opt
.
full_scan_mode
);
ASSERT_TRUE
(
new_opt
.
store_index_in_file
);
// unknown options
ASSERT_NOK
(
GetPlainTableOptionsFromString
(
table_opt
,
"user_key_len=16;bloom_bits_per_key=8;bad_option=1"
,
&
new_opt
));
// unknown encoding type
ASSERT_NOK
(
GetPlainTableOptionsFromString
(
table_opt
,
"user_key_len=16;bloom_bits_per_key=8;encoding_type=kPrefixXX"
,
&
new_opt
));
}
#endif // !ROCKSDB_LITE
#ifndef ROCKSDB_LITE // GetMemTableRepFactoryFromString is not supported
TEST_F
(
OptionsTest
,
GetMemTableRepFactoryFromString
)
{
MemTableRepFactory
*
new_mem_factory
=
nullptr
;
ASSERT_OK
(
GetMemTableRepFactoryFromString
(
"skip_list"
,
&
new_mem_factory
));
ASSERT_OK
(
GetMemTableRepFactoryFromString
(
"skip_list:16"
,
&
new_mem_factory
));
ASSERT_EQ
(
std
::
string
(
new_mem_factory
->
Name
()),
"SkipListFactory"
);
ASSERT_OK
(
GetMemTableRepFactoryFromString
(
"prefix_hash"
,
&
new_mem_factory
));
ASSERT_OK
(
GetMemTableRepFactoryFromString
(
"prefix_hash:1000"
,
&
new_mem_factory
));
ASSERT_EQ
(
std
::
string
(
new_mem_factory
->
Name
()),
"HashSkipListRepFactory"
);
ASSERT_OK
(
GetMemTableRepFactoryFromString
(
"hash_linkedlist"
,
&
new_mem_factory
));
ASSERT_OK
(
GetMemTableRepFactoryFromString
(
"hash_linkedlist:1000"
,
&
new_mem_factory
));
ASSERT_EQ
(
std
::
string
(
new_mem_factory
->
Name
()),
"HashLinkListRepFactory"
);
ASSERT_OK
(
GetMemTableRepFactoryFromString
(
"vector"
,
&
new_mem_factory
));
ASSERT_EQ
(
std
::
string
(
new_mem_factory
->
Name
()),
"VectorRepFactory"
);
ASSERT_NOK
(
GetMemTableRepFactoryFromString
(
"invalid_factory"
,
&
new_mem_factory
));
ASSERT_NOK
(
GetMemTableRepFactoryFromString
(
"skip_list:16:invalid_opt"
,
&
new_mem_factory
));
}
#endif // !ROCKSDB_LITE
#ifndef ROCKSDB_LITE // GetOptionsFromString is not supported in RocksDB Lite
TEST_F
(
OptionsTest
,
GetOptionsFromStringTest
)
{
Options
base_options
,
new_options
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录