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
c84cccfe
Commit
c84cccfe
authored
Sep 12, 2016
by
goroutine
Committed by
GitHub
Sep 12, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #31 from zhangjinpeng1987/master
add set_iterate_upper_bound api for readoptions
parents
0d41f716
30463dab
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
8 deletions
+48
-8
main.rs
src/main.rs
+28
-1
rocksdb.rs
src/rocksdb.rs
+20
-7
No files found.
src/main.rs
View file @
c84cccfe
...
@@ -143,7 +143,7 @@ fn main() {
...
@@ -143,7 +143,7 @@ fn main() {
#[cfg(test)]
#[cfg(test)]
mod
tests
{
mod
tests
{
use
rocksdb
::{
BlockBasedOptions
,
DB
,
DBCompressionType
,
Options
};
use
rocksdb
::{
BlockBasedOptions
,
DB
,
DBCompressionType
,
Options
,
ReadOptions
,
WriteOptions
,
SeekKey
};
use
rocksdb
::
DBCompactionStyle
::
DBUniversal
;
use
rocksdb
::
DBCompactionStyle
::
DBUniversal
;
#[allow(dead_code)]
#[allow(dead_code)]
...
@@ -192,6 +192,33 @@ mod tests {
...
@@ -192,6 +192,33 @@ mod tests {
DB
::
open
(
&
opts
,
path
)
.unwrap
()
DB
::
open
(
&
opts
,
path
)
.unwrap
()
}
}
#[test]
fn
read_with_upper_bound
()
{
let
path
=
"_rust_rocksdb_read_with_upper_bound_test"
;
let
mut
opts
=
Options
::
new
();
opts
.create_if_missing
(
true
);
{
let
db
=
DB
::
open
(
&
opts
,
path
)
.unwrap
();
let
writeopts
=
WriteOptions
::
new
();
db
.put_opt
(
b
"k1-0"
,
b
"a"
,
&
writeopts
)
.unwrap
();
db
.put_opt
(
b
"k1-1"
,
b
"b"
,
&
writeopts
)
.unwrap
();
db
.put_opt
(
b
"k2-0"
,
b
"c"
,
&
writeopts
)
.unwrap
();
let
mut
readopts
=
ReadOptions
::
new
();
readopts
.set_iterate_upper_bound
(
b
"k2"
);
let
mut
iter
=
db
.iter_opt
(
readopts
);
iter
.seek
(
SeekKey
::
Start
);
let
mut
count
=
0
;
while
iter
.valid
()
{
count
+=
1
;
if
!
iter
.next
()
{
break
;
}
}
assert_eq!
(
count
,
2
);
}
}
// TODO(tyler) unstable
// TODO(tyler) unstable
// #[bench]
// #[bench]
// fn a_writes(b: &mut Bencher) {
// fn a_writes(b: &mut Bencher) {
...
...
src/rocksdb.rs
View file @
c84cccfe
...
@@ -42,6 +42,7 @@ pub struct WriteBatch {
...
@@ -42,6 +42,7 @@ pub struct WriteBatch {
pub
struct
ReadOptions
{
pub
struct
ReadOptions
{
inner
:
rocksdb_ffi
::
DBReadOptions
,
inner
:
rocksdb_ffi
::
DBReadOptions
,
upper_bound
:
Vec
<
u8
>
,
}
}
/// The UnsafeSnap must be destroyed by db, it maybe be leaked
/// The UnsafeSnap must be destroyed by db, it maybe be leaked
...
@@ -62,6 +63,7 @@ pub struct Snapshot<'a> {
...
@@ -62,6 +63,7 @@ pub struct Snapshot<'a> {
#[allow(dead_code)]
#[allow(dead_code)]
pub
struct
DBIterator
<
'a
>
{
pub
struct
DBIterator
<
'a
>
{
db
:
&
'a
DB
,
db
:
&
'a
DB
,
readopts
:
ReadOptions
,
inner
:
rocksdb_ffi
::
DBIterator
,
inner
:
rocksdb_ffi
::
DBIterator
,
}
}
...
@@ -78,13 +80,14 @@ impl<'a> From<&'a [u8]> for SeekKey<'a> {
...
@@ -78,13 +80,14 @@ impl<'a> From<&'a [u8]> for SeekKey<'a> {
}
}
impl
<
'a
>
DBIterator
<
'a
>
{
impl
<
'a
>
DBIterator
<
'a
>
{
pub
fn
new
(
db
:
&
'a
DB
,
readopts
:
&
ReadOptions
)
->
DBIterator
<
'a
>
{
pub
fn
new
(
db
:
&
'a
DB
,
readopts
:
ReadOptions
)
->
DBIterator
<
'a
>
{
unsafe
{
unsafe
{
let
iterator
=
rocksdb_ffi
::
rocksdb_create_iterator
(
db
.inner
,
let
iterator
=
rocksdb_ffi
::
rocksdb_create_iterator
(
db
.inner
,
readopts
.inner
);
readopts
.inner
);
DBIterator
{
DBIterator
{
db
:
db
,
db
:
db
,
readopts
:
readopts
,
inner
:
iterator
,
inner
:
iterator
,
}
}
}
}
...
@@ -159,7 +162,7 @@ impl<'a> DBIterator<'a> {
...
@@ -159,7 +162,7 @@ impl<'a> DBIterator<'a> {
pub
fn
new_cf
(
db
:
&
'a
DB
,
pub
fn
new_cf
(
db
:
&
'a
DB
,
cf_handle
:
DBCFHandle
,
cf_handle
:
DBCFHandle
,
readopts
:
&
ReadOptions
)
readopts
:
ReadOptions
)
->
DBIterator
<
'a
>
{
->
DBIterator
<
'a
>
{
unsafe
{
unsafe
{
let
iterator
=
let
iterator
=
...
@@ -168,6 +171,7 @@ impl<'a> DBIterator<'a> {
...
@@ -168,6 +171,7 @@ impl<'a> DBIterator<'a> {
cf_handle
);
cf_handle
);
DBIterator
{
DBIterator
{
db
:
db
,
db
:
db
,
readopts
:
readopts
,
inner
:
iterator
,
inner
:
iterator
,
}
}
}
}
...
@@ -215,7 +219,7 @@ impl<'a> Snapshot<'a> {
...
@@ -215,7 +219,7 @@ impl<'a> Snapshot<'a> {
unsafe
{
unsafe
{
opt
.set_snapshot
(
&
self
.snap
);
opt
.set_snapshot
(
&
self
.snap
);
}
}
DBIterator
::
new
(
self
.db
,
&
opt
)
DBIterator
::
new
(
self
.db
,
opt
)
}
}
pub
fn
get
(
&
self
,
key
:
&
[
u8
])
->
Result
<
Option
<
DBVector
>
,
String
>
{
pub
fn
get
(
&
self
,
key
:
&
[
u8
])
->
Result
<
Option
<
DBVector
>
,
String
>
{
...
@@ -590,16 +594,16 @@ impl DB {
...
@@ -590,16 +594,16 @@ impl DB {
pub
fn
iter
(
&
self
)
->
DBIterator
{
pub
fn
iter
(
&
self
)
->
DBIterator
{
let
opts
=
ReadOptions
::
new
();
let
opts
=
ReadOptions
::
new
();
self
.iter_opt
(
&
opts
)
self
.iter_opt
(
opts
)
}
}
pub
fn
iter_opt
(
&
self
,
opt
:
&
ReadOptions
)
->
DBIterator
{
pub
fn
iter_opt
(
&
self
,
opt
:
ReadOptions
)
->
DBIterator
{
DBIterator
::
new
(
&
self
,
opt
)
DBIterator
::
new
(
&
self
,
opt
)
}
}
pub
fn
iter_cf
(
&
self
,
cf_handle
:
DBCFHandle
)
->
DBIterator
{
pub
fn
iter_cf
(
&
self
,
cf_handle
:
DBCFHandle
)
->
DBIterator
{
let
opts
=
ReadOptions
::
new
();
let
opts
=
ReadOptions
::
new
();
DBIterator
::
new_cf
(
&
self
,
cf_handle
,
&
opts
)
DBIterator
::
new_cf
(
&
self
,
cf_handle
,
opts
)
}
}
pub
fn
snapshot
(
&
self
)
->
Snapshot
{
pub
fn
snapshot
(
&
self
)
->
Snapshot
{
...
@@ -1100,7 +1104,7 @@ impl Drop for ReadOptions {
...
@@ -1100,7 +1104,7 @@ impl Drop for ReadOptions {
impl
Default
for
ReadOptions
{
impl
Default
for
ReadOptions
{
fn
default
()
->
ReadOptions
{
fn
default
()
->
ReadOptions
{
unsafe
{
unsafe
{
ReadOptions
{
inner
:
rocksdb_ffi
::
rocksdb_readoptions_create
()
}
ReadOptions
{
inner
:
rocksdb_ffi
::
rocksdb_readoptions_create
()
,
upper_bound
:
vec!
[]
}
}
}
}
}
}
}
...
@@ -1123,6 +1127,15 @@ impl ReadOptions {
...
@@ -1123,6 +1127,15 @@ impl ReadOptions {
rocksdb_ffi
::
rocksdb_readoptions_set_snapshot
(
self
.inner
,
rocksdb_ffi
::
rocksdb_readoptions_set_snapshot
(
self
.inner
,
snapshot
.inner
);
snapshot
.inner
);
}
}
pub
fn
set_iterate_upper_bound
(
&
mut
self
,
key
:
&
[
u8
])
{
self
.upper_bound
=
Vec
::
from
(
key
);
unsafe
{
rocksdb_ffi
::
rocksdb_readoptions_set_iterate_upper_bound
(
self
.inner
,
self
.upper_bound
.as_ptr
(),
self
.upper_bound
.len
()
as
size_t
);
}
}
}
}
pub
struct
DBVector
{
pub
struct
DBVector
{
...
...
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