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
e074eb90
Commit
e074eb90
authored
Dec 01, 2017
by
zhangjinpeng1987
Browse files
Options
Browse Files
Download
Plain Diff
Merge commit '
ddfc79ac
' into zhangjinpeng/update-rocksdb
parents
fbee9afd
ddfc79ac
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
138 additions
and
7 deletions
+138
-7
db_iter.cc
librocksdb_sys/rocksdb/db/db_iter.cc
+22
-5
db_iter_test.cc
librocksdb_sys/rocksdb/db/db_iter_test.cc
+102
-0
options.h
librocksdb_sys/rocksdb/include/rocksdb/options.h
+12
-2
options.cc
librocksdb_sys/rocksdb/options/options.cc
+2
-0
No files found.
librocksdb_sys/rocksdb/db/db_iter.cc
View file @
e074eb90
...
...
@@ -117,6 +117,7 @@ class DBIter: public Iterator {
current_entry_is_merged_
(
false
),
statistics_
(
cf_options
.
statistics
),
version_number_
(
version_number
),
iterate_lower_bound_
(
read_options
.
iterate_lower_bound
),
iterate_upper_bound_
(
read_options
.
iterate_upper_bound
),
prefix_same_as_start_
(
read_options
.
prefix_same_as_start
),
pin_thru_lifetime_
(
read_options
.
pin_data
),
...
...
@@ -275,6 +276,7 @@ class DBIter: public Iterator {
uint64_t
max_skippable_internal_keys_
;
uint64_t
num_internal_keys_skipped_
;
uint64_t
version_number_
;
const
Slice
*
iterate_lower_bound_
;
const
Slice
*
iterate_upper_bound_
;
IterKey
prefix_start_buf_
;
Slice
prefix_start_key_
;
...
...
@@ -678,6 +680,22 @@ void DBIter::PrevInternal() {
ExtractUserKey
(
iter_
->
key
()),
!
iter_
->
IsKeyPinned
()
||
!
pin_thru_lifetime_
/* copy */
);
if
(
prefix_extractor_
&&
prefix_same_as_start_
&&
prefix_extractor_
->
Transform
(
saved_key_
.
GetUserKey
())
.
compare
(
prefix_start_key_
)
!=
0
)
{
// Current key does not have the same prefix as start
valid_
=
false
;
return
;
}
if
(
iterate_lower_bound_
!=
nullptr
&&
user_comparator_
->
Compare
(
saved_key_
.
GetUserKey
(),
*
iterate_lower_bound_
)
<
0
)
{
// We've iterated earlier than the user-specified lower bound.
valid_
=
false
;
return
;
}
if
(
FindValueForCurrentKey
())
{
valid_
=
true
;
if
(
!
iter_
->
Valid
())
{
...
...
@@ -687,11 +705,6 @@ void DBIter::PrevInternal() {
if
(
user_comparator_
->
Equal
(
ikey
.
user_key
,
saved_key_
.
GetUserKey
()))
{
FindPrevUserKey
();
}
if
(
valid_
&&
prefix_extractor_
&&
prefix_same_as_start_
&&
prefix_extractor_
->
Transform
(
saved_key_
.
GetUserKey
())
.
compare
(
prefix_start_key_
)
!=
0
)
{
valid_
=
false
;
}
return
;
}
...
...
@@ -1075,6 +1088,10 @@ void DBIter::SeekToFirst() {
if
(
prefix_extractor_
!=
nullptr
)
{
max_skip_
=
std
::
numeric_limits
<
uint64_t
>::
max
();
}
if
(
iterate_lower_bound_
!=
nullptr
)
{
Seek
(
*
iterate_lower_bound_
);
return
;
}
direction_
=
kForward
;
ReleaseTempPinnedData
();
ResetInternalKeysSkippedCounter
();
...
...
librocksdb_sys/rocksdb/db/db_iter_test.cc
View file @
e074eb90
...
...
@@ -2796,6 +2796,108 @@ TEST_F(DBIterWithMergeIterTest, InnerMergeIteratorDataRace8) {
rocksdb
::
SyncPoint
::
GetInstance
()
->
DisableProcessing
();
}
TEST_F
(
DBIteratorTest
,
SeekPrefixTombstones
)
{
ReadOptions
ro
;
Options
options
;
options
.
prefix_extractor
.
reset
(
NewNoopTransform
());
TestIterator
*
internal_iter
=
new
TestIterator
(
BytewiseComparator
());
internal_iter
->
AddDeletion
(
"b"
);
internal_iter
->
AddDeletion
(
"c"
);
internal_iter
->
AddDeletion
(
"d"
);
internal_iter
->
AddDeletion
(
"e"
);
internal_iter
->
AddDeletion
(
"f"
);
internal_iter
->
AddDeletion
(
"g"
);
internal_iter
->
Finish
();
ro
.
prefix_same_as_start
=
true
;
std
::
unique_ptr
<
Iterator
>
db_iter
(
NewDBIterator
(
env_
,
ro
,
ImmutableCFOptions
(
options
),
BytewiseComparator
(),
internal_iter
,
10
,
options
.
max_sequential_skip_in_iterations
,
0
));
int
skipped_keys
=
0
;
get_perf_context
()
->
Reset
();
db_iter
->
SeekForPrev
(
"z"
);
skipped_keys
=
static_cast
<
int
>
(
get_perf_context
()
->
internal_key_skipped_count
);
ASSERT_EQ
(
skipped_keys
,
0
);
get_perf_context
()
->
Reset
();
db_iter
->
Seek
(
"a"
);
skipped_keys
=
static_cast
<
int
>
(
get_perf_context
()
->
internal_key_skipped_count
);
ASSERT_EQ
(
skipped_keys
,
0
);
}
TEST_F
(
DBIteratorTest
,
SeekToFirstLowerBound
)
{
const
int
kNumKeys
=
3
;
for
(
int
i
=
0
;
i
<
kNumKeys
+
2
;
++
i
)
{
// + 2 for two special cases: lower bound before and lower bound after the
// internal iterator's keys
TestIterator
*
internal_iter
=
new
TestIterator
(
BytewiseComparator
());
for
(
int
j
=
1
;
j
<=
kNumKeys
;
++
j
)
{
internal_iter
->
AddPut
(
std
::
to_string
(
j
),
"val"
);
}
internal_iter
->
Finish
();
ReadOptions
ro
;
auto
lower_bound_str
=
std
::
to_string
(
i
);
Slice
lower_bound
(
lower_bound_str
);
ro
.
iterate_lower_bound
=
&
lower_bound
;
Options
options
;
std
::
unique_ptr
<
Iterator
>
db_iter
(
NewDBIterator
(
env_
,
ro
,
ImmutableCFOptions
(
options
),
BytewiseComparator
(),
internal_iter
,
10
/* sequence */
,
options
.
max_sequential_skip_in_iterations
,
0
));
db_iter
->
SeekToFirst
();
if
(
i
==
kNumKeys
+
1
)
{
// lower bound was beyond the last key
ASSERT_FALSE
(
db_iter
->
Valid
());
}
else
{
ASSERT_TRUE
(
db_iter
->
Valid
());
int
expected
;
if
(
i
==
0
)
{
// lower bound was before the first key
expected
=
1
;
}
else
{
// lower bound was at the ith key
expected
=
i
;
}
ASSERT_EQ
(
std
::
to_string
(
expected
),
db_iter
->
key
().
ToString
());
}
}
}
TEST_F
(
DBIteratorTest
,
PrevLowerBound
)
{
const
int
kNumKeys
=
3
;
const
int
kLowerBound
=
2
;
TestIterator
*
internal_iter
=
new
TestIterator
(
BytewiseComparator
());
for
(
int
j
=
1
;
j
<=
kNumKeys
;
++
j
)
{
internal_iter
->
AddPut
(
std
::
to_string
(
j
),
"val"
);
}
internal_iter
->
Finish
();
ReadOptions
ro
;
auto
lower_bound_str
=
std
::
to_string
(
kLowerBound
);
Slice
lower_bound
(
lower_bound_str
);
ro
.
iterate_lower_bound
=
&
lower_bound
;
Options
options
;
std
::
unique_ptr
<
Iterator
>
db_iter
(
NewDBIterator
(
env_
,
ro
,
ImmutableCFOptions
(
options
),
BytewiseComparator
(),
internal_iter
,
10
/* sequence */
,
options
.
max_sequential_skip_in_iterations
,
0
));
db_iter
->
SeekToLast
();
for
(
int
i
=
kNumKeys
;
i
>=
kLowerBound
;
--
i
)
{
ASSERT_TRUE
(
db_iter
->
Valid
());
ASSERT_EQ
(
std
::
to_string
(
i
),
db_iter
->
key
().
ToString
());
db_iter
->
Prev
();
}
ASSERT_FALSE
(
db_iter
->
Valid
());
}
}
// namespace rocksdb
int
main
(
int
argc
,
char
**
argv
)
{
...
...
librocksdb_sys/rocksdb/include/rocksdb/options.h
View file @
e074eb90
...
...
@@ -961,14 +961,24 @@ struct ReadOptions {
// Default: nullptr
const
Snapshot
*
snapshot
;
// `iterate_lower_bound` defines the smallest key at which the backward
// iterator can return an entry. Once the bound is passed, Valid() will be
// false. `iterate_lower_bound` is inclusive ie the bound value is a valid
// entry.
//
// If prefix_extractor is not null, the Seek target and `iterate_lower_bound`
// need to have the same prefix. This is because ordering is not guaranteed
// outside of prefix domain.
//
// Default: nullptr
const
Slice
*
iterate_lower_bound
;
// "iterate_upper_bound" defines the extent upto which the forward iterator
// can returns entries. Once the bound is reached, Valid() will be false.
// "iterate_upper_bound" is exclusive ie the bound value is
// not a valid entry. If iterator_extractor is not null, the Seek target
// and iterator_upper_bound need to have the same prefix.
// This is because ordering is not guaranteed outside of prefix domain.
// There is no lower bound on the iterator. If needed, that can be easily
// implemented.
//
// Default: nullptr
const
Slice
*
iterate_upper_bound
;
...
...
librocksdb_sys/rocksdb/options/options.cc
View file @
e074eb90
...
...
@@ -603,6 +603,7 @@ DBOptions* DBOptions::IncreaseParallelism(int total_threads) {
ReadOptions
::
ReadOptions
()
:
snapshot
(
nullptr
),
iterate_lower_bound
(
nullptr
),
iterate_upper_bound
(
nullptr
),
readahead_size
(
0
),
max_skippable_internal_keys
(
0
),
...
...
@@ -619,6 +620,7 @@ ReadOptions::ReadOptions()
ReadOptions
::
ReadOptions
(
bool
cksum
,
bool
cache
)
:
snapshot
(
nullptr
),
iterate_lower_bound
(
nullptr
),
iterate_upper_bound
(
nullptr
),
readahead_size
(
0
),
max_skippable_internal_keys
(
0
),
...
...
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