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
2d35e4de
Commit
2d35e4de
authored
Dec 06, 2014
by
Tyler Neely
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add destroy db so that we can clean up after tests
parent
423f90a4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
5 deletions
+35
-5
ffi.rs
src/ffi.rs
+3
-2
rocksdb.rs
src/rocksdb.rs
+32
-3
No files found.
src/ffi.rs
View file @
2d35e4de
...
@@ -112,7 +112,6 @@ extern {
...
@@ -112,7 +112,6 @@ extern {
options
:
RocksDBOptions
,
path
:
*
const
i8
,
err
:
*
mut
i8
);
options
:
RocksDBOptions
,
path
:
*
const
i8
,
err
:
*
mut
i8
);
pub
fn
rocksdb_repair_db
(
pub
fn
rocksdb_repair_db
(
options
:
RocksDBOptions
,
path
:
*
const
i8
,
err
:
*
mut
i8
);
options
:
RocksDBOptions
,
path
:
*
const
i8
,
err
:
*
mut
i8
);
// Merge
// Merge
pub
fn
rocksdb_merge
(
db
:
RocksDBInstance
,
writeopts
:
RocksDBWriteOptions
,
pub
fn
rocksdb_merge
(
db
:
RocksDBInstance
,
writeopts
:
RocksDBWriteOptions
,
k
:
*
const
u8
,
kLen
:
size_t
,
k
:
*
const
u8
,
kLen
:
size_t
,
...
@@ -155,7 +154,7 @@ fn internal() {
...
@@ -155,7 +154,7 @@ fn internal() {
rocksdb_options_optimize_level_style_compaction
(
opts
,
0
);
rocksdb_options_optimize_level_style_compaction
(
opts
,
0
);
rocksdb_options_set_create_if_missing
(
opts
,
1
);
rocksdb_options_set_create_if_missing
(
opts
,
1
);
let
rustpath
=
"internaltest"
;
let
rustpath
=
"
_rust_rocksdb_
internaltest"
;
let
cpath
=
rustpath
.to_c_str
();
let
cpath
=
rustpath
.to_c_str
();
let
cpath_ptr
=
cpath
.as_ptr
();
let
cpath_ptr
=
cpath
.as_ptr
();
...
@@ -182,5 +181,7 @@ fn internal() {
...
@@ -182,5 +181,7 @@ fn internal() {
rocksdb_get
(
db
,
readopts
,
key
.as_ptr
(),
4
,
val_len_ptr
,
err
);
rocksdb_get
(
db
,
readopts
,
key
.as_ptr
(),
4
,
val_len_ptr
,
err
);
assert
!
(
err
.is_null
());
assert
!
(
err
.is_null
());
rocksdb_close
(
db
);
rocksdb_close
(
db
);
rocksdb_destroy_db
(
opts
,
cpath_ptr
,
err
);
assert
!
(
err
.is_null
());
}
}
}
}
src/rocksdb.rs
View file @
2d35e4de
...
@@ -99,6 +99,29 @@ impl RocksDB {
...
@@ -99,6 +99,29 @@ impl RocksDB {
Ok
(
RocksDB
{
inner
:
db
})
Ok
(
RocksDB
{
inner
:
db
})
}
}
}
}
pub
fn
destroy
(
opts
:
RocksDBOptions
,
path
:
&
str
)
->
Result
<
(),
String
>
{
unsafe
{
let
cpath
=
path
.to_c_str
();
let
cpath_ptr
=
cpath
.as_ptr
();
//TODO test path here, as if rocksdb fails it will just crash the
// process currently
let
err
=
0
as
*
mut
i8
;
let
result
=
rocksdb_ffi
::
rocksdb_destroy_db
(
opts
.inner
,
cpath_ptr
,
err
);
if
err
.is_not_null
()
{
let
cs
=
CString
::
new
(
err
as
*
const
i8
,
true
);
match
cs
.as_str
()
{
Some
(
error_string
)
=>
return
Err
(
error_string
.to_string
()),
None
=>
return
Err
(
"Could not initialize database."
.to_string
()),
}
}
Ok
(())
}
}
pub
fn
put
(
&
self
,
key
:
&
[
u8
],
value
:
&
[
u8
])
->
Result
<
(),
String
>
{
pub
fn
put
(
&
self
,
key
:
&
[
u8
],
value
:
&
[
u8
])
->
Result
<
(),
String
>
{
unsafe
{
unsafe
{
...
@@ -320,7 +343,8 @@ impl <'a,T,E> RocksDBResult<'a,T,E> {
...
@@ -320,7 +343,8 @@ impl <'a,T,E> RocksDBResult<'a,T,E> {
#[allow(dead_code)]
#[allow(dead_code)]
#[test]
#[test]
fn
external
()
{
fn
external
()
{
let
db
=
RocksDB
::
open_default
(
"externaltest"
)
.unwrap
();
let
path
=
"_rust_rocksdb_externaltest"
;
let
db
=
RocksDB
::
open_default
(
path
)
.unwrap
();
let
p
=
db
.put
(
b
"k1"
,
b
"v1111"
);
let
p
=
db
.put
(
b
"k1"
,
b
"v1111"
);
assert
!
(
p
.is_ok
());
assert
!
(
p
.is_ok
());
let
r
:
RocksDBResult
<
RocksDBVector
,
String
>
=
db
.get
(
b
"k1"
);
let
r
:
RocksDBResult
<
RocksDBVector
,
String
>
=
db
.get
(
b
"k1"
);
...
@@ -328,6 +352,8 @@ fn external() {
...
@@ -328,6 +352,8 @@ fn external() {
assert
!
(
db
.delete
(
b
"k1"
)
.is_ok
());
assert
!
(
db
.delete
(
b
"k1"
)
.is_ok
());
assert
!
(
db
.get
(
b
"k1"
)
.is_none
());
assert
!
(
db
.get
(
b
"k1"
)
.is_none
());
db
.close
();
db
.close
();
let
opts
=
RocksDBOptions
::
new
();
assert
!
(
RocksDB
::
destroy
(
opts
,
path
)
.is_ok
());
}
}
extern
"C"
fn
null_destructor
(
args
:
*
mut
c_void
)
{
extern
"C"
fn
null_destructor
(
args
:
*
mut
c_void
)
{
...
@@ -452,8 +478,9 @@ extern "C" fn partial_merge(
...
@@ -452,8 +478,9 @@ extern "C" fn partial_merge(
#[allow(dead_code)]
#[allow(dead_code)]
#[
z
est]
#[
t
est]
fn
mergetest
()
{
fn
mergetest
()
{
let
path
=
"_rust_rocksdb_mergetest"
;
unsafe
{
unsafe
{
let
opts
=
RocksDBOptions
::
new
();
let
opts
=
RocksDBOptions
::
new
();
let
mo
=
rocksdb_ffi
::
rocksdb_mergeoperator_create
(
let
mo
=
rocksdb_ffi
::
rocksdb_mergeoperator_create
(
...
@@ -465,7 +492,8 @@ fn mergetest() {
...
@@ -465,7 +492,8 @@ fn mergetest() {
mo_name
);
mo_name
);
opts
.create_if_missing
(
true
);
opts
.create_if_missing
(
true
);
opts
.set_merge_operator
(
mo
);
opts
.set_merge_operator
(
mo
);
let
db
=
RocksDB
::
open
(
opts
,
"externaltest"
)
.unwrap
();
let
db
=
RocksDB
::
open
(
opts
,
path
)
.unwrap
();
println!
(
"here!"
);
let
p
=
db
.put
(
b
"k1"
,
b
"1"
);
let
p
=
db
.put
(
b
"k1"
,
b
"1"
);
assert
!
(
p
.is_ok
());
assert
!
(
p
.is_ok
());
db
.merge
(
b
"k1"
,
b
"10"
);
db
.merge
(
b
"k1"
,
b
"10"
);
...
@@ -491,5 +519,6 @@ fn mergetest() {
...
@@ -491,5 +519,6 @@ fn mergetest() {
assert
!
(
db
.delete
(
b
"k1"
)
.is_ok
());
assert
!
(
db
.delete
(
b
"k1"
)
.is_ok
());
assert
!
(
db
.get
(
b
"k1"
)
.is_none
());
assert
!
(
db
.get
(
b
"k1"
)
.is_none
());
db
.close
();
db
.close
();
assert
!
(
RocksDB
::
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