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
2e01cfd9
Commit
2e01cfd9
authored
Dec 04, 2017
by
zhangjinpeng1987
Committed by
Huachao Huang
Dec 04, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support lower bound for ReadOptions (#168)
parent
5753b968
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
55 additions
and
1 deletion
+55
-1
c.cc
librocksdb_sys/crocksdb/c.cc
+13
-1
c.h
librocksdb_sys/crocksdb/crocksdb/c.h
+2
-0
lib.rs
librocksdb_sys/src/lib.rs
+5
-0
rocksdb_options.rs
src/rocksdb_options.rs
+13
-0
test_rocksdb_options.rs
tests/test_rocksdb_options.rs
+22
-0
No files found.
librocksdb_sys/crocksdb/c.cc
View file @
2e01cfd9
...
...
@@ -127,6 +127,7 @@ struct crocksdb_fifo_compaction_options_t { CompactionOptionsFIFO rep; };
struct
crocksdb_readoptions_t
{
ReadOptions
rep
;
Slice
upper_bound
;
// stack variable to set pointer to in ReadOptions
Slice
lower_bound
;
};
struct
crocksdb_writeoptions_t
{
WriteOptions
rep
;
};
struct
crocksdb_options_t
{
Options
rep
;
};
...
...
@@ -2683,13 +2684,24 @@ void crocksdb_readoptions_set_snapshot(
opt
->
rep
.
snapshot
=
(
snap
?
snap
->
rep
:
nullptr
);
}
void
crocksdb_readoptions_set_iterate_lower_bound
(
crocksdb_readoptions_t
*
opt
,
const
char
*
key
,
size_t
keylen
)
{
if
(
key
==
nullptr
)
{
opt
->
lower_bound
=
Slice
();
opt
->
rep
.
iterate_lower_bound
=
nullptr
;
}
else
{
opt
->
lower_bound
=
Slice
(
key
,
keylen
);
opt
->
rep
.
iterate_lower_bound
=
&
opt
->
lower_bound
;
}
}
void
crocksdb_readoptions_set_iterate_upper_bound
(
crocksdb_readoptions_t
*
opt
,
const
char
*
key
,
size_t
keylen
)
{
if
(
key
==
nullptr
)
{
opt
->
upper_bound
=
Slice
();
opt
->
rep
.
iterate_upper_bound
=
nullptr
;
}
else
{
opt
->
upper_bound
=
Slice
(
key
,
keylen
);
opt
->
rep
.
iterate_upper_bound
=
&
opt
->
upper_bound
;
...
...
librocksdb_sys/crocksdb/crocksdb/c.h
View file @
2e01cfd9
...
...
@@ -1107,6 +1107,8 @@ extern C_ROCKSDB_LIBRARY_API void crocksdb_readoptions_set_fill_cache(
crocksdb_readoptions_t
*
,
unsigned
char
);
extern
C_ROCKSDB_LIBRARY_API
void
crocksdb_readoptions_set_snapshot
(
crocksdb_readoptions_t
*
,
const
crocksdb_snapshot_t
*
);
extern
C_ROCKSDB_LIBRARY_API
void
crocksdb_readoptions_set_iterate_lower_bound
(
crocksdb_readoptions_t
*
,
const
char
*
key
,
size_t
keylen
);
extern
C_ROCKSDB_LIBRARY_API
void
crocksdb_readoptions_set_iterate_upper_bound
(
crocksdb_readoptions_t
*
,
const
char
*
key
,
size_t
keylen
);
extern
C_ROCKSDB_LIBRARY_API
void
crocksdb_readoptions_set_read_tier
(
...
...
librocksdb_sys/src/lib.rs
View file @
2e01cfd9
...
...
@@ -596,6 +596,11 @@ extern "C" {
readopts
:
*
mut
DBReadOptions
,
snapshot
:
*
const
DBSnapshot
,
);
pub
fn
crocksdb_readoptions_set_iterate_lower_bound
(
readopts
:
*
mut
DBReadOptions
,
k
:
*
const
u8
,
kLen
:
size_t
,
);
pub
fn
crocksdb_readoptions_set_iterate_upper_bound
(
readopts
:
*
mut
DBReadOptions
,
k
:
*
const
u8
,
...
...
src/rocksdb_options.rs
View file @
2e01cfd9
...
...
@@ -231,6 +231,7 @@ impl UnsafeSnap {
pub
struct
ReadOptions
{
inner
:
*
mut
DBReadOptions
,
lower_bound
:
Vec
<
u8
>
,
upper_bound
:
Vec
<
u8
>
,
}
...
...
@@ -247,6 +248,7 @@ impl Default for ReadOptions {
assert
!
(
!
opts
.is_null
(),
"Unable to create rocksdb read options"
);
ReadOptions
{
inner
:
opts
,
lower_bound
:
vec!
[],
upper_bound
:
vec!
[],
}
}
...
...
@@ -279,6 +281,17 @@ impl ReadOptions {
crocksdb_ffi
::
crocksdb_readoptions_set_snapshot
(
self
.inner
,
snapshot
.inner
);
}
pub
fn
set_iterate_lower_bound
(
&
mut
self
,
key
:
&
[
u8
])
{
self
.lower_bound
=
Vec
::
from
(
key
);
unsafe
{
crocksdb_ffi
::
crocksdb_readoptions_set_iterate_lower_bound
(
self
.inner
,
self
.lower_bound
.as_ptr
(),
self
.lower_bound
.len
(),
);
}
}
pub
fn
set_iterate_upper_bound
(
&
mut
self
,
key
:
&
[
u8
])
{
self
.upper_bound
=
Vec
::
from
(
key
);
unsafe
{
...
...
tests/test_rocksdb_options.rs
View file @
2e01cfd9
...
...
@@ -584,6 +584,28 @@ fn test_read_options() {
assert
!
(
key_count
==
3
);
}
#[test]
fn
test_readoptions_lower_bound
()
{
let
path
=
TempDir
::
new
(
"_rust_rocksdb_readoptions_lower_bound"
)
.expect
(
""
);
let
db
=
DB
::
open_default
(
path
.path
()
.to_str
()
.unwrap
())
.unwrap
();
db
.put
(
b
"k1"
,
b
"b"
)
.unwrap
();
db
.put
(
b
"k2"
,
b
"a"
)
.unwrap
();
db
.put
(
b
"k3"
,
b
"a"
)
.unwrap
();
let
mut
read_opts
=
ReadOptions
::
new
();
let
lower_bound
=
b
"k2"
;
read_opts
.set_iterate_lower_bound
(
lower_bound
.as_ref
());
let
mut
iter
=
db
.iter_opt
(
read_opts
);
iter
.seek
(
SeekKey
::
Key
(
b
"k3"
));
let
mut
count
=
0
;
while
iter
.valid
()
{
count
+=
1
;
iter
.prev
();
}
assert_eq!
(
count
,
2
);
}
#[test]
fn
test_block_based_options
()
{
let
path
=
TempDir
::
new
(
"_rust_rocksdb_block_based_options"
)
.expect
(
""
);
...
...
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