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
91e7dd74
Commit
91e7dd74
authored
Nov 24, 2014
by
Tyler Neely
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove some debugging cruft
parent
1a02679f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
11 deletions
+50
-11
main.rs
src/main.rs
+6
-2
rocksdb.rs
src/rocksdb.rs
+44
-9
No files found.
src/main.rs
View file @
91e7dd74
...
@@ -21,12 +21,16 @@ fn writes(b: &mut Bencher) {
...
@@ -21,12 +21,16 @@ fn writes(b: &mut Bencher) {
db
.close
();
db
.close
();
}
}
#[bench]
#[b
b
ench]
fn
reads
(
b
:
&
mut
Bencher
)
{
fn
reads
(
b
:
&
mut
Bencher
)
{
let
db
=
open
(
"testdb"
.to_string
(),
true
)
.unwrap
();
let
db
=
open
(
"testdb"
.to_string
(),
true
)
.unwrap
();
let
mut
i
=
0
as
u64
;
let
mut
i
=
0
as
u64
;
b
.iter
(||
{
b
.iter
(||
{
db
.get
(
i
.to_string
()
.as_bytes
());
db
.get
(
i
.to_string
()
.as_bytes
())
.on_error
(
|
e
|
{
println!
(
"error: {}"
,
e
);
e
});
i
+=
1
;
i
+=
1
;
});
});
db
.close
();
db
.close
();
...
...
src/rocksdb.rs
View file @
91e7dd74
...
@@ -47,6 +47,27 @@ impl <T,E> RocksdbResult<T,E> {
...
@@ -47,6 +47,27 @@ impl <T,E> RocksdbResult<T,E> {
}
}
}
}
#[unstable
=
"waiting for unboxed closures"
]
pub
fn
on_error
<
U
>
(
self
,
f
:
|
E
|
->
U
)
->
RocksdbResult
<
T
,
U
>
{
match
self
{
RocksdbResult
::
Some
(
x
)
=>
RocksdbResult
::
Some
(
x
),
RocksdbResult
::
None
=>
RocksdbResult
::
None
,
RocksdbResult
::
Error
(
e
)
=>
RocksdbResult
::
Error
(
f
(
e
)),
}
}
#[unstable
=
"waiting for unboxed closures"
]
pub
fn
on_absent
<
U
>
(
self
,
f
:
||
->
())
->
RocksdbResult
<
T
,
E
>
{
match
self
{
RocksdbResult
::
Some
(
x
)
=>
RocksdbResult
::
Some
(
x
),
RocksdbResult
::
None
=>
{
f
();
RocksdbResult
::
None
},
RocksdbResult
::
Error
(
e
)
=>
RocksdbResult
::
Error
(
e
),
}
}
pub
fn
is_some
(
self
)
->
bool
{
pub
fn
is_some
(
self
)
->
bool
{
match
self
{
match
self
{
RocksdbResult
::
Some
(
T
)
=>
true
,
RocksdbResult
::
Some
(
T
)
=>
true
,
...
@@ -76,7 +97,7 @@ pub struct Rocksdb {
...
@@ -76,7 +97,7 @@ pub struct Rocksdb {
}
}
impl
Rocksdb
{
impl
Rocksdb
{
pub
fn
put
(
&
self
,
key
:
&
[
u8
],
value
:
&
[
u8
])
->
IoResult
<
bool
>
{
pub
fn
put
(
&
self
,
key
:
&
[
u8
],
value
:
&
[
u8
])
->
Result
<
bool
,
String
>
{
unsafe
{
unsafe
{
let
writeopts
=
ffi
::
rocksdb_writeoptions_create
();
let
writeopts
=
ffi
::
rocksdb_writeoptions_create
();
let
err
=
0
as
*
mut
i8
;
let
err
=
0
as
*
mut
i8
;
...
@@ -84,10 +105,20 @@ impl Rocksdb {
...
@@ -84,10 +105,20 @@ impl Rocksdb {
key
.len
()
as
size_t
,
value
.as_ptr
(),
key
.len
()
as
size_t
,
value
.as_ptr
(),
value
.len
()
as
size_t
,
err
);
value
.len
()
as
size_t
,
err
);
if
err
.is_not_null
()
{
if
err
.is_not_null
()
{
libc
::
free
(
err
as
*
mut
c_void
);
let
cs
=
CString
::
new
(
err
as
*
const
i8
,
true
);
return
Err
(
IoError
::
last_error
());
match
cs
.as_str
()
{
Some
(
error_string
)
=>
return
Err
(
error_string
.to_string
()),
None
=>
{
let
ie
=
IoError
::
last_error
();
return
Err
(
format!
(
"ERROR: desc:{}, details:{}"
,
ie
.desc
,
ie
.detail
.unwrap_or_else
(
||
{
"none provided by OS"
.to_string
()})))
}
}
}
}
libc
::
free
(
err
as
*
mut
c_void
);
return
Ok
(
true
)
return
Ok
(
true
)
}
}
}
}
...
@@ -142,8 +173,8 @@ pub fn open(path: String, create_if_missing: bool) -> Result<Rocksdb, String> {
...
@@ -142,8 +173,8 @@ pub fn open(path: String, create_if_missing: bool) -> Result<Rocksdb, String> {
return
Err
(
"Could not create options"
.to_string
());
return
Err
(
"Could not create options"
.to_string
());
}
}
ffi
::
rocksdb_options_increase_parallelism
(
opts
,
0
);
ffi
::
rocksdb_options_increase_parallelism
(
opts
,
2
);
ffi
::
rocksdb_options_optimize_level_style_compaction
(
opts
,
0
);
//
ffi::rocksdb_options_optimize_level_style_compaction(opts, 0);
match
create_if_missing
{
match
create_if_missing
{
true
=>
ffi
::
rocksdb_options_set_create_if_missing
(
opts
,
1
),
true
=>
ffi
::
rocksdb_options_set_create_if_missing
(
opts
,
1
),
...
@@ -157,10 +188,14 @@ pub fn open(path: String, create_if_missing: bool) -> Result<Rocksdb, String> {
...
@@ -157,10 +188,14 @@ pub fn open(path: String, create_if_missing: bool) -> Result<Rocksdb, String> {
let
db
=
ffi
::
rocksdb_open
(
opts
,
cpath_ptr
,
err
);
let
db
=
ffi
::
rocksdb_open
(
opts
,
cpath_ptr
,
err
);
let
ffi
::
RocksdbInstance
(
db_ptr
)
=
db
;
let
ffi
::
RocksdbInstance
(
db_ptr
)
=
db
;
if
err
.is_not_null
()
{
if
err
.is_not_null
()
{
libc
::
free
(
err
as
*
mut
c_void
);
let
cs
=
CString
::
new
(
err
as
*
const
i8
,
true
);
return
Err
(
"Could not initialize database."
.to_string
());
match
cs
.as_str
()
{
Some
(
error_string
)
=>
return
Err
(
error_string
.to_string
()),
None
=>
return
Err
(
"Could not initialize database."
.to_string
()),
}
}
}
libc
::
free
(
err
as
*
mut
c_void
);
if
db_ptr
.is_null
()
{
if
db_ptr
.is_null
()
{
return
Err
(
"Could not initialize database."
.to_string
());
return
Err
(
"Could not initialize database."
.to_string
());
}
}
...
...
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