Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
R
rust-rocksdb
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
fangzongwu
rust-rocksdb
Commits
e492691b
Commit
e492691b
authored
Jan 17, 2017
by
zhangjinpeng1987
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add test for prefix extractor compatibility
parent
240639b5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
77 additions
and
0 deletions
+77
-0
test.rs
test/test.rs
+1
-0
test_prefix_extractor.rs
test/test_prefix_extractor.rs
+76
-0
No files found.
test/test.rs
View file @
e492691b
...
...
@@ -9,3 +9,4 @@ mod test_compact_range;
mod
test_rocksdb_options
;
mod
test_ingest_external_file
;
mod
test_slice_transform
;
mod
test_prefix_extractor
;
test/test_prefix_extractor.rs
0 → 100644
View file @
e492691b
use
rocksdb
::
*
;
use
tempdir
::
TempDir
;
struct
FixedSuffixTransform
{
pub
suffix_len
:
usize
,
}
impl
SliceTransform
for
FixedSuffixTransform
{
fn
transform
<
'a
>
(
&
mut
self
,
key
:
&
'a
[
u8
])
->
&
'a
[
u8
]
{
&
key
[
..
self
.suffix_len
]
}
fn
in_domain
(
&
mut
self
,
key
:
&
[
u8
])
->
bool
{
key
.len
()
>=
self
.suffix_len
}
}
#[test]
fn
test_prefix_extractor_compatibility
()
{
let
path
=
TempDir
::
new
(
"_rust_rocksdb_prefix_extractor_compatibility"
)
.expect
(
""
);
let
keys
=
vec!
[
b
"k1-0"
,
b
"k1-1"
,
b
"k1-2"
,
b
"k1-3"
,
b
"k1-4"
,
b
"k1-5"
,
b
"k1-6"
,
b
"k1-7"
,
b
"k1-8"
];
// create db with no prefix extractor, and insert data
{
let
mut
opts
=
Options
::
new
();
opts
.create_if_missing
(
true
);
let
db
=
DB
::
open
(
opts
,
path
.path
()
.to_str
()
.unwrap
())
.unwrap
();
let
wopts
=
WriteOptions
::
new
();
// sst1 with no prefix bloom.
db
.put_opt
(
b
"k1-0"
,
b
"a"
,
&
wopts
)
.unwrap
();
db
.put_opt
(
b
"k1-1"
,
b
"b"
,
&
wopts
)
.unwrap
();
db
.put_opt
(
b
"k1-2"
,
b
"c"
,
&
wopts
)
.unwrap
();
db
.flush
(
true
/* sync */
)
.unwrap
();
// flush memtable to sst file.
}
// open db with prefix extractor, and insert data
{
let
mut
bbto
=
BlockBasedOptions
::
new
();
bbto
.set_bloom_filter
(
10
,
false
);
bbto
.set_whole_key_filtering
(
false
);
let
mut
opts
=
Options
::
new
();
opts
.create_if_missing
(
false
);
opts
.set_block_based_table_factory
(
&
bbto
);
opts
.set_prefix_extractor
(
"FixedSuffixTransform"
,
Box
::
new
(
FixedSuffixTransform
{
suffix_len
:
2
}))
.unwrap
();
// also create prefix bloom for memtable
opts
.set_memtable_prefix_bloom_size_ratio
(
0.1
as
f64
);
let
db
=
DB
::
open
(
opts
,
path
.path
()
.to_str
()
.unwrap
())
.unwrap
();
let
wopts
=
WriteOptions
::
new
();
// sst2 with prefix bloom.
db
.put_opt
(
b
"k1-3"
,
b
"a"
,
&
wopts
)
.unwrap
();
db
.put_opt
(
b
"k1-4"
,
b
"b"
,
&
wopts
)
.unwrap
();
db
.put_opt
(
b
"k1-5"
,
b
"c"
,
&
wopts
)
.unwrap
();
db
.flush
(
true
/* sync */
)
.unwrap
();
// flush memtable to sst file.
// memtable with prefix bloom.
db
.put_opt
(
b
"k1-6"
,
b
"a"
,
&
wopts
)
.unwrap
();
db
.put_opt
(
b
"k1-7"
,
b
"b"
,
&
wopts
)
.unwrap
();
db
.put_opt
(
b
"k1-8"
,
b
"c"
,
&
wopts
)
.unwrap
();
let
mut
iter
=
db
.iter
();
iter
.seek
(
SeekKey
::
Key
(
b
"k1-0"
));
let
mut
key_count
=
0
;
while
iter
.valid
()
{
// If sst file has no prefix bloom, don't use prefix seek model.
assert_eq!
(
keys
[
key_count
],
iter
.key
());
key_count
=
key_count
+
1
;
iter
.next
();
}
assert
!
(
key_count
==
9
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment