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
a22187df
Commit
a22187df
authored
Mar 05, 2016
by
Jay Lee
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'ngaut/master' into busyjay/fix-test-error
parents
3bac7489
46ac1b41
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
72 additions
and
76 deletions
+72
-76
Cargo.toml
Cargo.toml
+1
-0
ffi.rs
src/ffi.rs
+9
-9
lib.rs
src/lib.rs
+3
-0
main.rs
src/main.rs
+2
-2
merge_operator.rs
src/merge_operator.rs
+8
-10
rocksdb.rs
src/rocksdb.rs
+30
-32
rocksdb_options.rs
src/rocksdb_options.rs
+19
-23
No files found.
Cargo.toml
View file @
a22187df
...
...
@@ -26,3 +26,4 @@ path = "test/test.rs"
[dependencies]
libc
=
"0.1.8"
tempdir
=
"0.3.4"
clippy
=
"*"
src/ffi.rs
View file @
a22187df
...
...
@@ -66,19 +66,19 @@ pub fn new_cache(capacity: size_t) -> DBCache {
#[repr(C)]
pub
enum
DBCompressionType
{
DBNo
Compression
=
0
,
DBSnappy
Compression
=
1
,
DBZlib
Compression
=
2
,
DBBz2
Compression
=
3
,
DBLz4
Compression
=
4
,
DBLz4hc
Compression
=
5
,
DBNo
=
0
,
DBSnappy
=
1
,
DBZlib
=
2
,
DBBz2
=
3
,
DBLz4
=
4
,
DBLz4hc
=
5
,
}
#[repr(C)]
pub
enum
DBCompactionStyle
{
DBLevel
Compaction
=
0
,
DBUniversal
Compaction
=
1
,
DBFifo
Compaction
=
2
,
DBLevel
=
0
,
DBUniversal
=
1
,
DBFifo
=
2
,
}
#[repr(C)]
...
...
src/lib.rs
View file @
a22187df
...
...
@@ -12,6 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
#
!
[
feature
(
plugin
)]
#
!
[
plugin
(
clippy
)]
extern
crate
libc
;
#[cfg(test)]
...
...
src/main.rs
View file @
a22187df
...
...
@@ -144,7 +144,7 @@ fn main() {
#[cfg(test)]
mod
tests
{
use
rocksdb
::{
BlockBasedOptions
,
DB
,
Options
};
use
rocksdb
::
DBCompactionStyle
::
DBUniversal
Compaction
;
use
rocksdb
::
DBCompactionStyle
::
DBUniversal
;
#[allow(dead_code)]
fn
tuned_for_somebody_elses_disk
(
path
:
&
str
,
...
...
@@ -164,7 +164,7 @@ mod tests {
opts
.set_min_write_buffer_number_to_merge
(
4
);
opts
.set_level_zero_stop_writes_trigger
(
2000
);
opts
.set_level_zero_slowdown_writes_trigger
(
0
);
opts
.set_compaction_style
(
DBUniversal
Compaction
);
opts
.set_compaction_style
(
DBUniversal
);
opts
.set_max_background_compactions
(
4
);
opts
.set_max_background_flushes
(
4
);
opts
.set_filter_deletes
(
false
);
...
...
src/merge_operator.rs
View file @
a22187df
...
...
@@ -127,9 +127,10 @@ impl MergeOperands {
impl
<
'a
>
Iterator
for
&
'a
mut
MergeOperands
{
type
Item
=
&
'a
[
u8
];
fn
next
(
&
mut
self
)
->
Option
<&
'a
[
u8
]
>
{
match
self
.cursor
==
self
.num_operands
{
true
=>
None
,
false
=>
unsafe
{
if
self
.cursor
==
self
.num_operands
{
None
}
else
{
unsafe
{
let
base
=
self
.operands_list
as
usize
;
let
base_len
=
self
.operands_list_len
as
usize
;
let
spacing
=
mem
::
size_of
::
<*
const
*
const
u8
>
();
...
...
@@ -141,7 +142,7 @@ impl<'a> Iterator for &'a mut MergeOperands {
self
.cursor
+=
1
;
Some
(
mem
::
transmute
(
slice
::
from_raw_parts
(
*
(
ptr
as
*
const
*
const
u8
)
as
*
const
u8
,
len
)))
}
,
}
}
}
...
...
@@ -166,13 +167,10 @@ mod test {
->
Vec
<
u8
>
{
let
nops
=
operands
.size_hint
()
.
0
;
let
mut
result
:
Vec
<
u8
>
=
Vec
::
with_capacity
(
nops
);
match
existing_val
{
Some
(
v
)
=>
{
for
e
in
v
{
result
.push
(
*
e
);
}
if
let
Some
(
v
)
=
existing_val
{
for
e
in
v
{
result
.push
(
*
e
);
}
None
=>
(),
}
for
op
in
operands
{
for
e
in
op
{
...
...
src/rocksdb.rs
View file @
a22187df
...
...
@@ -108,10 +108,7 @@ pub enum IteratorMode<'a> {
impl
DBIterator
{
fn
new
<
'b
>
(
db
:
&
DB
,
readopts
:
&
'b
ReadOptions
,
mode
:
IteratorMode
)
->
DBIterator
{
fn
new
(
db
:
&
DB
,
readopts
:
&
ReadOptions
,
mode
:
IteratorMode
)
->
DBIterator
{
unsafe
{
let
iterator
=
rocksdb_ffi
::
rocksdb_create_iterator
(
db
.inner
,
readopts
.inner
);
...
...
@@ -246,19 +243,18 @@ impl DB {
Err
(
_
)
=>
{
return
Err
(
"Failed to convert path to CString when opening
\
rocksdb"
.to_
string
())
.to_
owned
())
}
};
let
cpath_ptr
=
cpath
.as_ptr
();
let
ospath
=
Path
::
new
(
path
);
match
fs
::
create_dir_all
(
&
ospath
)
{
Err
(
e
)
=>
{
return
Err
(
format!
(
"Failed to create rocksdb directory:
\
{:?}"
,
e
))
}
Ok
(
_
)
=>
(),
if
let
Err
(
e
)
=
fs
::
create_dir_all
(
&
ospath
)
{
return
Err
(
format!
(
"Failed to create rocksdb directory:
\
src/rocksdb.rs:
\
{:?}"
,
e
));
}
let
mut
err
:
*
const
i8
=
0
as
*
const
i8
;
...
...
@@ -315,15 +311,15 @@ impl DB {
copts
,
handles
,
err_ptr
);
}
for
handle
in
cfhandles
.iter
()
{
for
handle
in
&
cfhandles
{
if
handle
.
0
.is_null
()
{
return
Err
(
"Received null column family handle from DB."
.to_
string
());
.to_
owned
());
}
}
for
(
n
,
h
)
in
cfs_v
.iter
()
.zip
(
cfhandles
)
{
cf_map
.insert
(
n
.to_string
(),
h
);
cf_map
.insert
(
(
*
n
)
.to_owned
(),
h
);
}
}
...
...
@@ -331,7 +327,7 @@ impl DB {
return
Err
(
error_message
(
err
));
}
if
db
.
0
.is_null
()
{
return
Err
(
"Could not initialize database."
.to_
string
());
return
Err
(
"Could not initialize database."
.to_
owned
());
}
Ok
(
DB
{
...
...
@@ -389,7 +385,7 @@ impl DB {
if
!
err
.is_null
()
{
return
Err
(
error_message
(
err
));
}
return
Ok
(());
Ok
(())
}
pub
fn
write
(
&
self
,
batch
:
WriteBatch
)
->
Result
<
(),
String
>
{
...
...
@@ -404,7 +400,7 @@ impl DB {
a fairly trivial call, and its failure may be
\
indicative of a mis-compiled or mis-loaded
\
rocksdb library."
.to_
string
());
.to_
owned
());
}
let
val_len
:
size_t
=
0
;
...
...
@@ -413,7 +409,7 @@ impl DB {
let
err_ptr
:
*
mut
*
const
i8
=
&
mut
err
;
let
val
=
rocksdb_ffi
::
rocksdb_get
(
self
.inner
,
readopts
.clone
()
,
readopts
,
key
.as_ptr
(),
key
.len
()
as
size_t
,
val_len_ptr
,
...
...
@@ -422,9 +418,10 @@ impl DB {
if
!
err
.is_null
()
{
return
Err
(
error_message
(
err
));
}
match
val
.is_null
()
{
true
=>
Ok
(
None
),
false
=>
Ok
(
Some
(
DBVector
::
from_c
(
val
,
val_len
))),
if
val
.is_null
()
{
Ok
(
None
)
}
else
{
Ok
(
Some
(
DBVector
::
from_c
(
val
,
val_len
)))
}
}
}
...
...
@@ -440,7 +437,7 @@ impl DB {
a fairly trivial call, and its failure may be
\
indicative of a mis-compiled or mis-loaded
\
rocksdb library."
.to_
string
());
.to_
owned
());
}
let
val_len
:
size_t
=
0
;
...
...
@@ -449,7 +446,7 @@ impl DB {
let
err_ptr
:
*
mut
*
const
i8
=
&
mut
err
;
let
val
=
rocksdb_ffi
::
rocksdb_get_cf
(
self
.inner
,
readopts
.clone
()
,
readopts
,
cf
,
key
.as_ptr
(),
key
.len
()
as
size_t
,
...
...
@@ -459,9 +456,10 @@ impl DB {
if
!
err
.is_null
()
{
return
Err
(
error_message
(
err
));
}
match
val
.is_null
()
{
true
=>
Ok
(
None
),
false
=>
Ok
(
Some
(
DBVector
::
from_c
(
val
,
val_len
))),
if
val
.is_null
()
{
Ok
(
None
)
}
else
{
Ok
(
Some
(
DBVector
::
from_c
(
val
,
val_len
)))
}
}
}
...
...
@@ -475,7 +473,7 @@ impl DB {
Err
(
_
)
=>
{
return
Err
(
"Failed to convert path to CString when opening
\
rocksdb"
.to_
string
())
.to_
owned
())
}
};
let
cname_ptr
=
cname
.as_ptr
();
...
...
@@ -487,7 +485,7 @@ impl DB {
opts
.inner
,
cname_ptr
as
*
const
_
,
err_ptr
);
self
.cfs
.insert
(
name
.to_
string
(),
cf_handler
);
self
.cfs
.insert
(
name
.to_
owned
(),
cf_handler
);
cf_handler
};
if
!
err
.is_null
()
{
...
...
@@ -499,7 +497,7 @@ impl DB {
pub
fn
drop_cf
(
&
mut
self
,
name
:
&
str
)
->
Result
<
(),
String
>
{
let
cf
=
self
.cfs
.get
(
name
);
if
cf
.is_none
()
{
return
Err
(
format!
(
"Invalid column family: {}"
,
name
)
.
to_string
());
return
Err
(
format!
(
"Invalid column family: {}"
,
name
)
.
clone
());
}
let
mut
err
:
*
const
i8
=
0
as
*
const
i8
;
...
...
@@ -717,7 +715,7 @@ impl Drop for WriteBatch {
impl
Drop
for
DB
{
fn
drop
(
&
mut
self
)
{
unsafe
{
for
(
_
,
cf
)
in
self
.cfs
.iter
()
{
for
cf
in
self
.cfs
.values
()
{
rocksdb_ffi
::
rocksdb_column_family_handle_destroy
(
*
cf
);
}
rocksdb_ffi
::
rocksdb_close
(
self
.inner
);
...
...
@@ -858,7 +856,7 @@ impl DBVector {
}
}
pub
fn
to_utf8
<
'a
>
(
&
'a
self
)
->
Option
<&
'a
str
>
{
pub
fn
to_utf8
(
&
self
)
->
Option
<&
str
>
{
from_utf8
(
self
.deref
())
.ok
()
}
}
...
...
src/rocksdb_options.rs
View file @
a22187df
...
...
@@ -135,12 +135,12 @@ impl Options {
}
}
pub
fn
add_merge_operator
<
'a
>
(
&
mut
self
,
name
:
&
str
,
merge_fn
:
fn
(
&
[
u8
],
Option
<&
[
u8
]
>
,
&
mut
MergeOperands
)
->
Vec
<
u8
>
)
{
pub
fn
add_merge_operator
(
&
mut
self
,
name
:
&
str
,
merge_fn
:
fn
(
&
[
u8
],
Option
<&
[
u8
]
>
,
&
mut
MergeOperands
)
->
Vec
<
u8
>
)
{
let
cb
=
Box
::
new
(
MergeOperatorCallback
{
name
:
CString
::
new
(
name
.as_bytes
())
.unwrap
(),
merge_fn
:
merge_fn
,
...
...
@@ -158,9 +158,9 @@ impl Options {
}
}
pub
fn
add_comparator
<
'a
>
(
&
mut
self
,
name
:
&
str
,
compare_fn
:
fn
(
&
[
u8
],
&
[
u8
])
->
i32
)
{
pub
fn
add_comparator
(
&
mut
self
,
name
:
&
str
,
compare_fn
:
fn
(
&
[
u8
],
&
[
u8
])
->
i32
)
{
let
cb
=
Box
::
new
(
ComparatorCallback
{
name
:
CString
::
new
(
name
.as_bytes
())
.unwrap
(),
f
:
compare_fn
,
...
...
@@ -192,13 +192,10 @@ impl Options {
pub
fn
set_use_fsync
(
&
mut
self
,
useit
:
bool
)
{
unsafe
{
match
useit
{
true
=>
{
rocksdb_ffi
::
rocksdb_options_set_use_fsync
(
self
.inner
,
1
)
}
false
=>
{
rocksdb_ffi
::
rocksdb_options_set_use_fsync
(
self
.inner
,
0
)
}
if
useit
{
rocksdb_ffi
::
rocksdb_options_set_use_fsync
(
self
.inner
,
1
)
}
else
{
rocksdb_ffi
::
rocksdb_options_set_use_fsync
(
self
.inner
,
0
)
}
}
}
...
...
@@ -211,13 +208,12 @@ impl Options {
pub
fn
set_disable_data_sync
(
&
mut
self
,
disable
:
bool
)
{
unsafe
{
match
disable
{
true
=>
rocksdb_ffi
::
rocksdb_options_set_disable_data_sync
(
self
.inner
,
1
),
false
=>
rocksdb_ffi
::
rocksdb_options_set_disable_data_sync
(
self
.inner
,
0
),
if
disable
{
rocksdb_ffi
::
rocksdb_options_set_disable_data_sync
(
self
.inner
,
1
);
}
else
{
rocksdb_ffi
::
rocksdb_options_set_disable_data_sync
(
self
.inner
,
0
);
}
}
}
...
...
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