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
6ca22c66
Commit
6ca22c66
authored
Mar 21, 2015
by
Tyler Neely
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5 from AndreyG/master
Cosmetic changes, warning fixes
parents
7459362e
6948c2d7
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
65 additions
and
74 deletions
+65
-74
ffi.rs
src/ffi.rs
+0
-1
lib.rs
src/lib.rs
+3
-4
merge_operator.rs
src/merge_operator.rs
+2
-6
rocksdb.rs
src/rocksdb.rs
+59
-60
rocksdb_options.rs
src/rocksdb_options.rs
+1
-3
No files found.
src/ffi.rs
View file @
6ca22c66
...
...
@@ -15,7 +15,6 @@
*/
extern
crate
libc
;
use
self
::
libc
::{
c_char
,
c_int
,
c_void
,
size_t
};
use
std
::
ffi
::
CString
;
#[repr(C)]
pub
struct
RocksDBOptions
(
pub
*
const
c_void
);
...
...
src/lib.rs
View file @
6ca22c66
...
...
@@ -17,11 +17,10 @@
#
!
[
crate_type
=
"lib"
]
#
!
[
feature
(
collections
)]
#
!
[
feature
(
core
)]
#
!
[
feature
(
fs
)]
#
!
[
feature
(
io
)]
#
!
[
feature
(
libc
)]
#
!
[
feature
(
path
)]
#
!
[
feature
(
std_misc
)]
#
!
[
feature
(
unique
)]
#
!
[
feature
(
path_ext
)]
pub
use
ffi
as
rocksdb_ffi
;
pub
use
ffi
::{
...
...
src/merge_operator.rs
View file @
6ca22c66
...
...
@@ -13,8 +13,6 @@
See the License for the specific language governing permissions and
limitations under the License.
*/
#
!
[
allow
(
unstable
)]
extern
crate
libc
;
use
self
::
libc
::{
c_char
,
c_int
,
c_void
,
size_t
};
use
std
::
ffi
::
CString
;
...
...
@@ -69,8 +67,7 @@ pub extern "C" fn full_merge_callback(
assert
!
(
!
buf
.is_null
());
*
new_value_length
=
result
.len
()
as
size_t
;
*
success
=
1
as
u8
;
ptr
::
copy_memory
(
&
mut
*
buf
,
result
.as_ptr
()
as
*
const
c_void
,
result
.len
());
ptr
::
copy
(
&
mut
*
buf
,
result
.as_ptr
()
as
*
const
c_void
,
result
.len
());
buf
as
*
const
c_char
}
}
...
...
@@ -94,8 +91,7 @@ pub extern "C" fn partial_merge_callback(
assert
!
(
!
buf
.is_null
());
*
new_value_length
=
1
as
size_t
;
*
success
=
1
as
u8
;
ptr
::
copy_memory
(
&
mut
*
buf
,
result
.as_ptr
()
as
*
const
c_void
,
result
.len
());
ptr
::
copy
(
&
mut
*
buf
,
result
.as_ptr
()
as
*
const
c_void
,
result
.len
());
buf
as
*
const
c_char
}
}
...
...
src/rocksdb.rs
View file @
6ca22c66
...
...
@@ -16,13 +16,12 @@
extern
crate
libc
;
use
self
::
libc
::{
c_void
,
size_t
};
use
std
::
ffi
::
CString
;
use
std
::
ffi
::
{
CString
,
CStr
}
;
use
std
::
fs
::{
self
,
PathExt
};
use
std
::
ops
::
Deref
;
use
std
::
path
::
Path
;
use
std
::
ptr
::
Unique
;
use
std
::
slice
;
use
std
::
str
::
from_c_str
;
use
std
::
str
::
from_utf8
;
use
rocksdb_ffi
;
...
...
@@ -33,6 +32,12 @@ pub struct RocksDB {
inner
:
rocksdb_ffi
::
RocksDBInstance
,
}
fn
error_message
<
'a
>
(
ptr
:
*
const
i8
)
->
&
'a
str
{
unsafe
{
return
from_utf8
(
CStr
::
from_ptr
(
ptr
)
.to_bytes
())
.unwrap
();
}
}
impl
RocksDB
{
pub
fn
open_default
(
path
:
&
str
)
->
Result
<
RocksDB
,
&
str
>
{
let
opts
=
RocksDBOptions
::
new
();
...
...
@@ -41,71 +46,69 @@ impl RocksDB {
}
pub
fn
open
(
opts
:
RocksDBOptions
,
path
:
&
str
)
->
Result
<
RocksDB
,
&
str
>
{
unsafe
{
let
cpath
=
CString
::
from_slice
(
path
.as_bytes
());
let
cpath_ptr
=
cpath
.as_ptr
();
let
ospath
=
Path
::
new
(
path
);
if
!
ospath
.exists
()
{
match
fs
::
create_dir_all
(
&
ospath
)
{
Err
(
e
)
=>
return
Err
(
""
),
Ok
(
_
)
=>
(),
}
let
cpath
=
CString
::
new
(
path
.as_bytes
())
.unwrap
();
let
cpath_ptr
=
cpath
.as_ptr
();
let
ospath
=
Path
::
new
(
path
);
if
!
ospath
.exists
()
{
match
fs
::
create_dir_all
(
&
ospath
)
{
Err
(
_
)
=>
return
Err
(
""
),
Ok
(
_
)
=>
(),
}
}
let
err
=
0
as
*
mut
i8
;
let
db
=
rocksdb_ffi
::
rocksdb_open
(
opts
.inner
,
cpath_ptr
,
err
);
if
!
err
.is_null
()
{
let
cs
=
from_c_str
(
err
as
*
const
i8
);
return
Err
(
cs
);
}
if
db
.
0
.is_null
()
{
return
Err
(
"Could not initialize database."
);
}
Ok
(
RocksDB
{
inner
:
db
})
let
err
=
0
as
*
mut
i8
;
let
db
:
rocksdb_ffi
::
RocksDBInstance
;
unsafe
{
db
=
rocksdb_ffi
::
rocksdb_open
(
opts
.inner
,
cpath_ptr
,
err
);
}
if
!
err
.is_null
()
{
return
Err
(
error_message
(
err
));
}
if
db
.
0
.is_null
()
{
return
Err
(
"Could not initialize database."
);
}
Ok
(
RocksDB
{
inner
:
db
})
}
pub
fn
destroy
(
opts
:
RocksDBOptions
,
path
:
&
str
)
->
Result
<
(),
&
str
>
{
unsafe
{
let
cpath
=
CString
::
from_slice
(
path
.as_bytes
());
let
cpath_ptr
=
cpath
.as_ptr
();
let
cpath
=
CString
::
new
(
path
.as_bytes
())
.unwrap
();
let
cpath_ptr
=
cpath
.as_ptr
();
let
ospath
=
Path
::
new
(
path
);
if
!
ospath
.exists
()
{
return
Err
(
"path does not exist"
);
}
let
ospath
=
Path
::
new
(
path
);
if
!
ospath
.exists
()
{
return
Err
(
"path does not exist"
);
}
let
err
=
0
as
*
mut
i8
;
let
result
=
rocksdb_ffi
::
rocksdb_destroy_db
(
opts
.inner
,
cpath_ptr
,
err
);
if
!
err
.is_null
()
{
let
cs
=
from_c_str
(
err
as
*
const
i8
);
return
Err
(
cs
);
}
Ok
(())
let
err
=
0
as
*
mut
i8
;
unsafe
{
rocksdb_ffi
::
rocksdb_destroy_db
(
opts
.inner
,
cpath_ptr
,
err
);
}
if
!
err
.is_null
()
{
return
Err
(
error_message
(
err
));
}
Ok
(())
}
pub
fn
repair
(
opts
:
RocksDBOptions
,
path
:
&
str
)
->
Result
<
(),
&
str
>
{
unsafe
{
let
cpath
=
CString
::
from_slice
(
path
.as_bytes
());
let
cpath_ptr
=
cpath
.as_ptr
();
let
cpath
=
CString
::
new
(
path
.as_bytes
())
.unwrap
();
let
cpath_ptr
=
cpath
.as_ptr
();
let
ospath
=
Path
::
new
(
path
);
if
!
ospath
.exists
()
{
return
Err
(
"path does not exist"
);
}
let
ospath
=
Path
::
new
(
path
);
if
!
ospath
.exists
()
{
return
Err
(
"path does not exist"
);
}
let
err
=
0
as
*
mut
i8
;
let
result
=
rocksdb_ffi
::
rocksdb_repair_db
(
opts
.inner
,
cpath_ptr
,
err
);
if
!
err
.is_null
()
{
let
cs
=
from_c_str
(
err
as
*
const
i8
);
return
Err
(
cs
);
}
Ok
(())
let
err
=
0
as
*
mut
i8
;
unsafe
{
rocksdb_ffi
::
rocksdb_repair_db
(
opts
.inner
,
cpath_ptr
,
err
);
}
if
!
err
.is_null
()
{
return
Err
(
error_message
(
err
));
}
Ok
(())
}
pub
fn
create_snapshot
(
self
)
->
RocksDBSnapshot
{
...
...
@@ -122,8 +125,7 @@ impl RocksDB {
key
.len
()
as
size_t
,
value
.as_ptr
(),
value
.len
()
as
size_t
,
err
);
if
!
err
.is_null
()
{
let
cs
=
from_c_str
(
err
as
*
const
i8
);
return
Err
(
cs
);
return
Err
(
error_message
(
err
));
}
return
Ok
(())
}
...
...
@@ -137,8 +139,7 @@ impl RocksDB {
key
.len
()
as
size_t
,
value
.as_ptr
(),
value
.len
()
as
size_t
,
err
);
if
!
err
.is_null
()
{
let
cs
=
from_c_str
(
err
as
*
const
i8
);
return
Err
(
cs
);
return
Err
(
error_message
(
err
));
}
return
Ok
(())
}
...
...
@@ -160,8 +161,7 @@ impl RocksDB {
let
val
=
rocksdb_ffi
::
rocksdb_get
(
self
.inner
,
readopts
,
key
.as_ptr
(),
key
.len
()
as
size_t
,
val_len_ptr
,
err
)
as
*
mut
u8
;
if
!
err
.is_null
()
{
let
cs
=
from_c_str
(
err
as
*
const
i8
);
return
RocksDBResult
::
Error
(
cs
);
return
RocksDBResult
::
Error
(
error_message
(
err
));
}
match
val
.is_null
()
{
true
=>
RocksDBResult
::
None
,
...
...
@@ -179,8 +179,7 @@ impl RocksDB {
rocksdb_ffi
::
rocksdb_delete
(
self
.inner
,
writeopts
,
key
.as_ptr
(),
key
.len
()
as
size_t
,
err
);
if
!
err
.is_null
()
{
let
cs
=
from_c_str
(
err
as
*
const
i8
);
return
Err
(
cs
);
return
Err
(
error_message
(
err
));
}
return
Ok
(())
}
...
...
src/rocksdb_options.rs
View file @
6ca22c66
...
...
@@ -13,8 +13,6 @@
See the License for the specific language governing permissions and
limitations under the License.
*/
#
!
[
allow
(
unstable
)]
extern
crate
libc
;
use
self
::
libc
::{
c_int
,
size_t
};
use
std
::
ffi
::
CString
;
...
...
@@ -73,7 +71,7 @@ impl RocksDBOptions {
pub
fn
add_merge_operator
<
'a
>
(
&
self
,
name
:
&
str
,
merge_fn
:
fn
(
&
[
u8
],
Option
<&
[
u8
]
>
,
&
mut
MergeOperands
)
->
Vec
<
u8
>
)
{
let
cb
=
Box
::
new
(
MergeOperatorCallback
{
name
:
CString
::
from_slice
(
name
.as_bytes
()
),
name
:
CString
::
new
(
name
.as_bytes
())
.unwrap
(
),
merge_fn
:
merge_fn
,
});
...
...
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