Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
kvdb
rocksdb
提交
84992d64
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,发现更多精彩内容 >>
提交
84992d64
编写于
10月 30, 2015
作者:
S
SherlockNoMad
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Option Helper Refactoring
上级
335e4ce8
变更
8
显示空白变更内容
内联
并排
Showing
8 changed file
with
83 addition
and
173 deletion
+83
-173
table/block_based_table_factory.cc
table/block_based_table_factory.cc
+1
-1
table/block_based_table_factory.h
table/block_based_table_factory.h
+1
-1
table/plain_table_factory.cc
table/plain_table_factory.cc
+1
-1
table/plain_table_factory.h
table/plain_table_factory.h
+1
-1
util/options_helper.cc
util/options_helper.cc
+45
-165
util/options_helper.h
util/options_helper.h
+30
-0
util/options_parser.cc
util/options_parser.cc
+2
-2
util/options_test.cc
util/options_test.cc
+2
-2
未找到文件。
table/block_based_table_factory.cc
浏览文件 @
84992d64
...
...
@@ -158,7 +158,7 @@ std::string BlockBasedTableFactory::GetPrintableTableOptions() const {
return
ret
;
}
const
BlockBasedTableOptions
&
BlockBasedTableFactory
::
GetTableO
ptions
()
const
{
const
BlockBasedTableOptions
&
BlockBasedTableFactory
::
table_o
ptions
()
const
{
return
table_options_
;
}
...
...
table/block_based_table_factory.h
浏览文件 @
84992d64
...
...
@@ -56,7 +56,7 @@ class BlockBasedTableFactory : public TableFactory {
std
::
string
GetPrintableTableOptions
()
const
override
;
const
BlockBasedTableOptions
&
GetTableO
ptions
()
const
;
const
BlockBasedTableOptions
&
table_o
ptions
()
const
;
private:
BlockBasedTableOptions
table_options_
;
...
...
table/plain_table_factory.cc
浏览文件 @
84992d64
...
...
@@ -75,7 +75,7 @@ std::string PlainTableFactory::GetPrintableTableOptions() const {
return
ret
;
}
const
PlainTableOptions
&
PlainTableFactory
::
GetTableO
ptions
()
const
{
const
PlainTableOptions
&
PlainTableFactory
::
table_o
ptions
()
const
{
return
table_options_
;
}
...
...
table/plain_table_factory.h
浏览文件 @
84992d64
...
...
@@ -158,7 +158,7 @@ class PlainTableFactory : public TableFactory {
std
::
string
GetPrintableTableOptions
()
const
override
;
const
PlainTableOptions
&
GetTableO
ptions
()
const
;
const
PlainTableOptions
&
table_o
ptions
()
const
;
static
const
char
kValueTypeSeqId0
=
0xFF
;
...
...
util/options_helper.cc
浏览文件 @
84992d64
...
...
@@ -106,32 +106,28 @@ std::string trim(const std::string& str) {
return
std
::
string
();
}
bool
SerializeCompressionType
(
const
CompressionType
&
type
,
std
::
string
*
value
)
{
switch
(
type
)
{
case
kNoCompression
:
*
value
=
"kNoCompression"
;
return
true
;
case
kSnappyCompression
:
*
value
=
"kSnappyCompression"
;
return
true
;
case
kZlibCompression
:
*
value
=
"kZlibCompression"
;
return
true
;
case
kBZip2Compression
:
*
value
=
"kBZip2Compression"
;
return
true
;
case
kLZ4Compression
:
*
value
=
"kLZ4Compression"
;
return
true
;
case
kLZ4HCCompression
:
*
value
=
"kLZ4HCCompression"
;
return
true
;
case
kZSTDNotFinalCompression
:
*
value
=
"kZSTDNotFinalCompression"
;
template
<
typename
T
>
bool
ParseEnum
(
const
std
::
unordered_map
<
std
::
string
,
T
>&
type_map
,
const
std
::
string
&
type
,
T
*
value
)
{
auto
iter
=
type_map
.
find
(
type
);
if
(
iter
!=
type_map
.
end
())
{
*
value
=
iter
->
second
;
return
true
;
default:
}
return
false
;
}
template
<
typename
T
>
bool
SerializeEnum
(
const
std
::
unordered_map
<
std
::
string
,
T
>&
type_map
,
const
T
&
type
,
std
::
string
*
value
)
{
for
(
const
auto
&
pair
:
type_map
)
{
if
(
pair
.
second
==
type
)
{
*
value
=
pair
.
first
;
return
true
;
}
}
return
false
;
}
bool
SerializeVectorCompressionType
(
const
std
::
vector
<
CompressionType
>&
types
,
...
...
@@ -143,7 +139,8 @@ bool SerializeVectorCompressionType(const std::vector<CompressionType>& types,
ss
<<
':'
;
}
std
::
string
string_type
;
result
=
SerializeCompressionType
(
types
[
i
],
&
string_type
);
result
=
SerializeEnum
<
CompressionType
>
(
compression_type_string_map
,
types
[
i
],
&
string_type
);
if
(
result
==
false
)
{
return
result
;
}
...
...
@@ -153,101 +150,6 @@ bool SerializeVectorCompressionType(const std::vector<CompressionType>& types,
return
true
;
}
bool
ParseCompressionType
(
const
std
::
string
&
string_value
,
CompressionType
*
type
)
{
if
(
string_value
==
"kNoCompression"
)
{
*
type
=
kNoCompression
;
}
else
if
(
string_value
==
"kSnappyCompression"
)
{
*
type
=
kSnappyCompression
;
}
else
if
(
string_value
==
"kZlibCompression"
)
{
*
type
=
kZlibCompression
;
}
else
if
(
string_value
==
"kBZip2Compression"
)
{
*
type
=
kBZip2Compression
;
}
else
if
(
string_value
==
"kLZ4Compression"
)
{
*
type
=
kLZ4Compression
;
}
else
if
(
string_value
==
"kLZ4HCCompression"
)
{
*
type
=
kLZ4HCCompression
;
}
else
if
(
string_value
==
"kZSTDNotFinalCompression"
)
{
*
type
=
kZSTDNotFinalCompression
;
}
else
{
return
false
;
}
return
true
;
}
bool
SerializeBlockBasedTableIndexType
(
const
BlockBasedTableOptions
::
IndexType
&
type
,
std
::
string
*
value
)
{
switch
(
type
)
{
case
BlockBasedTableOptions
::
kBinarySearch
:
*
value
=
"kBinarySearch"
;
return
true
;
case
BlockBasedTableOptions
::
kHashSearch
:
*
value
=
"kHashSearch"
;
return
true
;
default:
return
false
;
}
}
bool
ParseBlockBasedTableIndexType
(
const
std
::
string
&
type
,
BlockBasedTableOptions
::
IndexType
*
value
)
{
if
(
type
==
"kBinarySearch"
)
{
*
value
=
BlockBasedTableOptions
::
kBinarySearch
;
}
else
if
(
type
==
"kHashSearch"
)
{
*
value
=
BlockBasedTableOptions
::
kHashSearch
;
}
else
{
return
false
;
}
return
true
;
}
bool
SerializeEncodingType
(
const
EncodingType
&
type
,
std
::
string
*
value
)
{
switch
(
type
)
{
case
EncodingType
::
kPlain
:
*
value
=
"kPlain"
;
return
true
;
case
EncodingType
::
kPrefix
:
*
value
=
"kPrefix"
;
return
true
;
default:
return
false
;
}
}
bool
PraseEncodingType
(
const
std
::
string
&
type
,
EncodingType
*
value
)
{
if
(
type
==
"kPlain"
)
{
*
value
=
EncodingType
::
kPlain
;
}
else
if
(
type
==
"kPrefix"
)
{
*
value
=
EncodingType
::
kPrefix
;
}
else
{
return
false
;
}
return
true
;
}
static
std
::
unordered_map
<
std
::
string
,
ChecksumType
>
checksum_type_map
=
{
{
"kNoChecksum"
,
kNoChecksum
},
{
"kCRC32c"
,
kCRC32c
},
{
"kxxHash"
,
kxxHash
}};
bool
ParseChecksumType
(
const
std
::
string
&
type
,
ChecksumType
*
value
)
{
auto
iter
=
checksum_type_map
.
find
(
type
);
if
(
iter
!=
checksum_type_map
.
end
())
{
*
value
=
iter
->
second
;
return
true
;
}
return
false
;
}
bool
SerializeChecksumType
(
const
ChecksumType
&
type
,
std
::
string
*
value
)
{
for
(
const
auto
&
pair
:
checksum_type_map
)
{
if
(
pair
.
second
==
type
)
{
*
value
=
pair
.
first
;
return
true
;
}
}
return
false
;
}
bool
ParseBoolean
(
const
std
::
string
&
type
,
const
std
::
string
&
value
)
{
if
(
value
==
"true"
||
value
==
"1"
)
{
return
true
;
...
...
@@ -325,28 +227,6 @@ double ParseDouble(const std::string& value) {
return
std
::
strtod
(
value
.
c_str
(),
0
);
#endif
}
static
const
std
::
unordered_map
<
char
,
std
::
string
>
compaction_style_to_string_map
=
{
{
kCompactionStyleLevel
,
"kCompactionStyleLevel"
},
{
kCompactionStyleUniversal
,
"kCompactionStyleUniversal"
},
{
kCompactionStyleFIFO
,
"kCompactionStyleFIFO"
},
{
kCompactionStyleNone
,
"kCompactionStyleNone"
}};
CompactionStyle
ParseCompactionStyle
(
const
std
::
string
&
type
)
{
for
(
auto
const
&
entry
:
compaction_style_to_string_map
)
{
if
(
entry
.
second
==
type
)
{
return
static_cast
<
CompactionStyle
>
(
entry
.
first
);
}
}
throw
std
::
invalid_argument
(
"unknown compaction style: "
+
type
);
return
kCompactionStyleLevel
;
}
std
::
string
CompactionStyleToString
(
const
CompactionStyle
style
)
{
auto
iter
=
compaction_style_to_string_map
.
find
(
style
);
assert
(
iter
!=
compaction_style_to_string_map
.
end
());
return
iter
->
second
;
}
bool
ParseVectorCompressionType
(
const
std
::
string
&
value
,
...
...
@@ -358,14 +238,16 @@ bool ParseVectorCompressionType(
bool
is_ok
;
CompressionType
type
;
if
(
end
==
std
::
string
::
npos
)
{
is_ok
=
ParseCompressionType
(
value
.
substr
(
start
),
&
type
);
is_ok
=
ParseEnum
<
CompressionType
>
(
compression_type_string_map
,
value
.
substr
(
start
),
&
type
);
if
(
!
is_ok
)
{
return
false
;
}
compression_per_level
->
emplace_back
(
type
);
break
;
}
else
{
is_ok
=
ParseCompressionType
(
value
.
substr
(
start
,
end
-
start
),
&
type
);
is_ok
=
ParseEnum
<
CompressionType
>
(
compression_type_string_map
,
value
.
substr
(
start
,
end
-
start
),
&
type
);
if
(
!
is_ok
)
{
return
false
;
}
...
...
@@ -454,11 +336,10 @@ bool ParseOptionHelper(char* opt_address, const OptionType& opt_type,
*
reinterpret_cast
<
double
*>
(
opt_address
)
=
ParseDouble
(
value
);
break
;
case
OptionType
::
kCompactionStyle
:
*
reinterpret_cast
<
CompactionStyle
*>
(
opt_address
)
=
ParseCompactionStyle
(
value
);
break
;
return
ParseEnum
<
CompactionStyle
>
(
compaction_style_string_map
,
value
,
reinterpret_cast
<
CompactionStyle
*>
(
opt_address
));
case
OptionType
::
kCompressionType
:
return
Parse
CompressionType
(
return
Parse
Enum
<
CompressionType
>
(
compression_type_string_map
,
value
,
reinterpret_cast
<
CompressionType
*>
(
opt_address
));
case
OptionType
::
kVectorCompressionType
:
return
ParseVectorCompressionType
(
...
...
@@ -468,15 +349,14 @@ bool ParseOptionHelper(char* opt_address, const OptionType& opt_type,
value
,
reinterpret_cast
<
std
::
shared_ptr
<
const
SliceTransform
>*>
(
opt_address
));
case
OptionType
::
kChecksumType
:
return
Parse
ChecksumType
(
value
,
return
Parse
Enum
<
ChecksumType
>
(
checksum_type_string_map
,
value
,
reinterpret_cast
<
ChecksumType
*>
(
opt_address
));
case
OptionType
::
kBlockBasedTableIndexType
:
return
Parse
BlockBasedTableIndexType
(
value
,
return
Parse
Enum
<
BlockBasedTableOptions
::
IndexType
>
(
block_base_table_index_type_string_map
,
value
,
reinterpret_cast
<
BlockBasedTableOptions
::
IndexType
*>
(
opt_address
));
case
OptionType
::
kEncodingType
:
return
PraseEncodingType
(
value
,
return
ParseEnum
<
EncodingType
>
(
encoding_type_string_map
,
value
,
reinterpret_cast
<
EncodingType
*>
(
opt_address
));
default:
return
false
;
...
...
@@ -518,11 +398,10 @@ bool SerializeSingleOptionHelper(const char* opt_address,
*
(
reinterpret_cast
<
const
std
::
string
*>
(
opt_address
)));
break
;
case
OptionType
::
kCompactionStyle
:
*
value
=
CompactionStyleToString
(
*
(
reinterpret_cast
<
const
CompactionStyle
*>
(
opt_address
)));
break
;
return
SerializeEnum
<
CompactionStyle
>
(
compaction_style_string_map
,
*
(
reinterpret_cast
<
const
CompactionStyle
*>
(
opt_address
)),
value
);
case
OptionType
::
kCompressionType
:
return
Serialize
CompressionType
(
return
Serialize
Enum
<
CompressionType
>
(
compression_type_string_map
,
*
(
reinterpret_cast
<
const
CompressionType
*>
(
opt_address
)),
value
);
case
OptionType
::
kVectorCompressionType
:
return
SerializeVectorCompressionType
(
...
...
@@ -585,10 +464,11 @@ bool SerializeSingleOptionHelper(const char* opt_address,
break
;
}
case
OptionType
::
kChecksumType
:
return
Serialize
ChecksumType
(
return
Serialize
Enum
<
ChecksumType
>
(
checksum_type_string_map
,
*
reinterpret_cast
<
const
ChecksumType
*>
(
opt_address
),
value
);
case
OptionType
::
kBlockBasedTableIndexType
:
return
SerializeBlockBasedTableIndexType
(
return
SerializeEnum
<
BlockBasedTableOptions
::
IndexType
>
(
block_base_table_index_type_string_map
,
*
reinterpret_cast
<
const
BlockBasedTableOptions
::
IndexType
*>
(
opt_address
),
value
);
...
...
@@ -600,7 +480,7 @@ bool SerializeSingleOptionHelper(const char* opt_address,
break
;
}
case
OptionType
::
kEncodingType
:
return
SerializeEn
codingType
(
return
SerializeEn
um
<
EncodingType
>
(
encoding_type_string_map
,
*
reinterpret_cast
<
const
EncodingType
*>
(
opt_address
),
value
);
default:
return
false
;
...
...
@@ -832,7 +712,7 @@ bool ParseColumnFamilyOption(const std::string& name,
auto
block_based_table_factory
=
dynamic_cast
<
BlockBasedTableFactory
*>
(
new_options
->
table_factory
.
get
());
if
(
block_based_table_factory
!=
nullptr
)
{
base_table_options
=
block_based_table_factory
->
GetTableO
ptions
();
base_table_options
=
block_based_table_factory
->
table_o
ptions
();
}
Status
table_opt_s
=
GetBlockBasedTableOptionsFromString
(
base_table_options
,
value
,
&
table_opt
);
...
...
@@ -846,7 +726,7 @@ bool ParseColumnFamilyOption(const std::string& name,
auto
plain_table_factory
=
dynamic_cast
<
PlainTableFactory
*>
(
new_options
->
table_factory
.
get
());
if
(
plain_table_factory
!=
nullptr
)
{
base_table_options
=
plain_table_factory
->
GetTableO
ptions
();
base_table_options
=
plain_table_factory
->
table_o
ptions
();
}
Status
table_opt_s
=
GetPlainTableOptionsFromString
(
base_table_options
,
value
,
&
table_opt
);
...
...
@@ -1031,7 +911,7 @@ Status GetStringFromTableFactory(std::string* opts_str, const TableFactory* tf,
opts_str
->
clear
();
if
(
bbtf
!=
nullptr
)
{
return
GetStringFromBlockBasedTableOptions
(
opts_str
,
bbtf
->
GetTableO
ptions
(),
delimiter
);
opts_str
,
bbtf
->
table_o
ptions
(),
delimiter
);
}
return
Status
::
OK
();
...
...
util/options_helper.h
浏览文件 @
84992d64
...
...
@@ -491,6 +491,36 @@ static std::unordered_map<std::string,
{
offsetof
(
struct
PlainTableOptions
,
store_index_in_file
),
OptionType
::
kBoolean
,
OptionVerificationType
::
kNormal
}}};
static
std
::
unordered_map
<
std
::
string
,
CompressionType
>
compression_type_string_map
=
{
{
"kNoCompression"
,
kNoCompression
},
{
"kSnappyCompression"
,
kSnappyCompression
},
{
"kZlibCompression"
,
kZlibCompression
},
{
"kBZip2Compression"
,
kBZip2Compression
},
{
"kLZ4Compression"
,
kLZ4Compression
},
{
"kLZ4HCCompression"
,
kLZ4HCCompression
},
{
"kZSTDNotFinalCompression"
,
kZSTDNotFinalCompression
}
};
static
std
::
unordered_map
<
std
::
string
,
BlockBasedTableOptions
::
IndexType
>
block_base_table_index_type_string_map
=
{
{
"kBinarySearch"
,
BlockBasedTableOptions
::
IndexType
::
kBinarySearch
},
{
"kHashSearch"
,
BlockBasedTableOptions
::
IndexType
::
kHashSearch
}};
static
std
::
unordered_map
<
std
::
string
,
EncodingType
>
encoding_type_string_map
=
{{
"kPlain"
,
kPlain
},
{
"kPrefix"
,
kPrefix
}};
static
std
::
unordered_map
<
std
::
string
,
ChecksumType
>
checksum_type_string_map
=
{
{
"kNoChecksum"
,
kNoChecksum
},
{
"kCRC32c"
,
kCRC32c
},
{
"kxxHash"
,
kxxHash
}};
static
std
::
unordered_map
<
std
::
string
,
CompactionStyle
>
compaction_style_string_map
=
{
{
"kCompactionStyleLevel"
,
kCompactionStyleLevel
},
{
"kCompactionStyleUniversal"
,
kCompactionStyleUniversal
},
{
"kCompactionStyleFIFO"
,
kCompactionStyleFIFO
},
{
"kCompactionStyleNone"
,
kCompactionStyleNone
}};
}
// namespace rocksdb
#endif // !ROCKSDB_LITE
util/options_parser.cc
浏览文件 @
84992d64
...
...
@@ -685,8 +685,8 @@ Status RocksDBOptionsParser::VerifyBlockBasedTableFactory(
return
Status
::
OK
();
}
const
auto
&
base_opt
=
base_tf
->
GetTableO
ptions
();
const
auto
&
file_opt
=
file_tf
->
GetTableO
ptions
();
const
auto
&
base_opt
=
base_tf
->
table_o
ptions
();
const
auto
&
file_opt
=
file_tf
->
table_o
ptions
();
for
(
auto
&
pair
:
block_based_table_type_info
)
{
if
(
pair
.
second
.
verification
==
OptionVerificationType
::
kDeprecated
)
{
...
...
util/options_test.cc
浏览文件 @
84992d64
...
...
@@ -720,7 +720,7 @@ TEST_F(OptionsTest, GetOptionsFromStringTest) {
ASSERT_EQ
(
new_options
.
max_write_buffer_number
,
16
);
BlockBasedTableOptions
new_block_based_table_options
=
dynamic_cast
<
BlockBasedTableFactory
*>
(
new_options
.
table_factory
.
get
())
->
GetTableO
ptions
();
->
table_o
ptions
();
ASSERT_EQ
(
new_block_based_table_options
.
block_cache
->
GetCapacity
(),
1U
<<
20
);
ASSERT_EQ
(
new_block_based_table_options
.
block_size
,
4U
);
// don't overwrite block based table options
...
...
@@ -1221,7 +1221,7 @@ TEST_F(OptionsTest, ConvertOptionsTest) {
ASSERT_TRUE
(
table_factory
.
get
()
!=
nullptr
);
const
BlockBasedTableOptions
table_opt
=
table_factory
->
GetTableO
ptions
();
const
BlockBasedTableOptions
table_opt
=
table_factory
->
table_o
ptions
();
ASSERT_EQ
(
table_opt
.
block_cache
->
GetCapacity
(),
8UL
<<
20
);
ASSERT_EQ
(
table_opt
.
block_size
,
leveldb_opt
.
block_size
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录