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
a7295735
Commit
a7295735
authored
Mar 23, 2016
by
goroutine
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4 from siddontang/siddontang/snapshot_get
support snapshot get/get_cf
parents
a22a722c
bde37b67
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
78 additions
and
27 deletions
+78
-27
rocksdb.rs
src/rocksdb.rs
+78
-27
No files found.
src/rocksdb.rs
View file @
a7295735
...
...
@@ -197,6 +197,21 @@ impl<'a> Snapshot<'a> {
readopts
.set_snapshot
(
self
);
DBIterator
::
new
(
self
.db
,
&
readopts
,
mode
)
}
pub
fn
get
(
&
self
,
key
:
&
[
u8
])
->
Result
<
Option
<
DBVector
>
,
String
>
{
let
mut
readopts
=
ReadOptions
::
new
();
readopts
.set_snapshot
(
self
);
self
.db
.get_opt
(
key
,
&
readopts
)
}
pub
fn
get_cf
(
&
self
,
cf
:
DBCFHandle
,
key
:
&
[
u8
])
->
Result
<
Option
<
DBVector
>
,
String
>
{
let
mut
readopts
=
ReadOptions
::
new
();
readopts
.set_snapshot
(
self
);
self
.db
.get_cf_opt
(
cf
,
key
,
&
readopts
)
}
}
impl
<
'a
>
Drop
for
Snapshot
<
'a
>
{
...
...
@@ -412,29 +427,30 @@ impl DB {
self
.write_opt
(
batch
,
&
WriteOptions
::
new
())
}
pub
fn
get
(
&
self
,
key
:
&
[
u8
])
->
Result
<
Option
<
DBVector
>
,
String
>
{
unsafe
{
let
readopts
=
rocksdb_ffi
::
rocksdb_readoptions_create
();
if
readopts
.
0
.is_null
()
{
return
Err
(
"Unable to create rocksdb read options. This is
\
a fairly trivial call, and its failure may be
\
indicative of a mis-compiled or mis-loaded
\
rocksdb library."
.to_owned
());
}
pub
fn
get_opt
(
&
self
,
key
:
&
[
u8
],
readopts
:
&
ReadOptions
)
->
Result
<
Option
<
DBVector
>
,
String
>
{
if
readopts
.inner
.
0
.is_null
()
{
return
Err
(
"Unable to create rocksdb read options. This is a
\
fairly trivial call, and its failure may be
\
indicative of a mis-compiled or mis-loaded rocksdb
\
library."
.to_owned
());
}
unsafe
{
let
val_len
:
size_t
=
0
;
let
val_len_ptr
=
&
val_len
as
*
const
size_t
;
let
mut
err
:
*
const
i8
=
0
as
*
const
i8
;
let
err_ptr
:
*
mut
*
const
i8
=
&
mut
err
;
let
val
=
rocksdb_ffi
::
rocksdb_get
(
self
.inner
,
readopts
,
readopts
.inner
,
key
.as_ptr
(),
key
.len
()
as
size_t
,
val_len_ptr
,
err_ptr
)
as
*
mut
u8
;
rocksdb_ffi
::
rocksdb_readoptions_destroy
(
readopts
);
if
!
err
.is_null
()
{
return
Err
(
error_message
(
err
));
}
...
...
@@ -446,33 +462,36 @@ impl DB {
}
}
pub
fn
get_cf
(
&
self
,
cf
:
DBCFHandle
,
key
:
&
[
u8
])
->
Result
<
Option
<
DBVector
>
,
String
>
{
unsafe
{
let
readopts
=
rocksdb_ffi
::
rocksdb_readoptions_create
();
if
readopts
.
0
.is_null
()
{
return
Err
(
"Unable to create rocksdb read options. This is
\
a fairly trivial call, and its failure may be
\
indicative of a mis-compiled or mis-loaded
\
rocksdb library."
.to_owned
());
}
pub
fn
get
(
&
self
,
key
:
&
[
u8
])
->
Result
<
Option
<
DBVector
>
,
String
>
{
self
.get_opt
(
key
,
&
ReadOptions
::
new
())
}
pub
fn
get_cf_opt
(
&
self
,
cf
:
DBCFHandle
,
key
:
&
[
u8
],
readopts
:
&
ReadOptions
)
->
Result
<
Option
<
DBVector
>
,
String
>
{
if
readopts
.inner
.
0
.is_null
()
{
return
Err
(
"Unable to create rocksdb read options. This is a
\
fairly trivial call, and its failure may be
\
indicative of a mis-compiled or mis-loaded rocksdb
\
library."
.to_owned
());
}
unsafe
{
let
val_len
:
size_t
=
0
;
let
val_len_ptr
=
&
val_len
as
*
const
size_t
;
let
mut
err
:
*
const
i8
=
0
as
*
const
i8
;
let
err_ptr
:
*
mut
*
const
i8
=
&
mut
err
;
let
val
=
rocksdb_ffi
::
rocksdb_get_cf
(
self
.inner
,
readopts
,
readopts
.inner
,
cf
,
key
.as_ptr
(),
key
.len
()
as
size_t
,
val_len_ptr
,
err_ptr
)
as
*
mut
u8
;
rocksdb_ffi
::
rocksdb_readoptions_destroy
(
readopts
);
if
!
err
.is_null
()
{
return
Err
(
error_message
(
err
));
}
...
...
@@ -484,6 +503,13 @@ impl DB {
}
}
pub
fn
get_cf
(
&
self
,
cf
:
DBCFHandle
,
key
:
&
[
u8
])
->
Result
<
Option
<
DBVector
>
,
String
>
{
self
.get_cf_opt
(
cf
,
key
,
&
ReadOptions
::
new
())
}
pub
fn
create_cf
(
&
mut
self
,
name
:
&
str
,
opts
:
&
Options
)
...
...
@@ -1062,3 +1088,28 @@ mod test {
assert_eq!
(
sizes
[
4
],
0
);
}
}
#[test]
fn
snapshot_test
()
{
let
path
=
"_rust_rocksdb_snapshottest"
;
{
let
db
=
DB
::
open_default
(
path
)
.unwrap
();
let
p
=
db
.put
(
b
"k1"
,
b
"v1111"
);
assert
!
(
p
.is_ok
());
let
snap
=
db
.snapshot
();
let
mut
r
:
Result
<
Option
<
DBVector
>
,
String
>
=
snap
.get
(
b
"k1"
);
assert
!
(
r
.unwrap
()
.unwrap
()
.to_utf8
()
.unwrap
()
==
"v1111"
);
r
=
db
.get
(
b
"k1"
);
assert
!
(
r
.unwrap
()
.unwrap
()
.to_utf8
()
.unwrap
()
==
"v1111"
);
let
p
=
db
.put
(
b
"k2"
,
b
"v2222"
);
assert
!
(
p
.is_ok
());
assert
!
(
db
.get
(
b
"k2"
)
.unwrap
()
.is_some
());
assert
!
(
snap
.get
(
b
"k2"
)
.unwrap
()
.is_none
());
}
let
opts
=
Options
::
new
();
assert
!
(
DB
::
destroy
(
&
opts
,
path
)
.is_ok
());
}
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