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
bc77ce17
Commit
bc77ce17
authored
Aug 02, 2015
by
Tyler Neely
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #26 from spacejam/tyler_stable
Now friendly with 1.1 stable!
parents
6ca40b78
8be7b68e
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
32 additions
and
32 deletions
+32
-32
.travis.yml
.travis.yml
+6
-1
Cargo.toml
Cargo.toml
+3
-0
lib.rs
src/lib.rs
+0
-4
main.rs
src/main.rs
+8
-6
merge_operator.rs
src/merge_operator.rs
+10
-5
rocksdb.rs
src/rocksdb.rs
+5
-16
No files found.
.travis.yml
View file @
bc77ce17
...
@@ -2,6 +2,11 @@ language: rust
...
@@ -2,6 +2,11 @@ language: rust
rust
:
rust
:
-
nightly
-
nightly
-
1.1.0
os
:
-
linux
-
osx
script
:
script
:
-
rustc src/lib.rs
-
rustc
-Z parse-only
src/lib.rs
Cargo.toml
View file @
bc77ce17
...
@@ -20,3 +20,6 @@ valgrind=[]
...
@@ -20,3 +20,6 @@ valgrind=[]
name
=
"test"
name
=
"test"
path
=
"test/test.rs"
path
=
"test/test.rs"
[dependencies]
libc
=
"0.1.8"
src/lib.rs
View file @
bc77ce17
...
@@ -15,10 +15,6 @@
...
@@ -15,10 +15,6 @@
*/
*/
#
!
[
crate_id
=
"rocksdb"
]
#
!
[
crate_id
=
"rocksdb"
]
#
!
[
crate_type
=
"lib"
]
#
!
[
crate_type
=
"lib"
]
#
!
[
feature
(
libc
)]
#
!
[
feature
(
unique
)]
#
!
[
feature
(
path_ext
)]
#
!
[
feature
(
raw
)]
pub
use
ffi
as
rocksdb_ffi
;
pub
use
ffi
as
rocksdb_ffi
;
pub
use
ffi
::{
new_bloom_filter
,
RocksDBCompactionStyle
,
RocksDBComparator
};
pub
use
ffi
::{
new_bloom_filter
,
RocksDBCompactionStyle
,
RocksDBComparator
};
...
...
src/main.rs
View file @
bc77ce17
...
@@ -13,10 +13,7 @@
...
@@ -13,10 +13,7 @@
See the License for the specific language governing permissions and
See the License for the specific language governing permissions and
limitations under the License.
limitations under the License.
*/
*/
#
!
[
feature
(
test
)]
extern
crate
rocksdb
;
extern
crate
rocksdb
;
extern
crate
test
;
use
rocksdb
::{
Options
,
RocksDB
,
MergeOperands
,
new_bloom_filter
,
Writable
,
};
use
rocksdb
::{
Options
,
RocksDB
,
MergeOperands
,
new_bloom_filter
,
Writable
,
};
use
rocksdb
::
RocksDBCompactionStyle
::
RocksDBUniversalCompaction
;
use
rocksdb
::
RocksDBCompactionStyle
::
RocksDBUniversalCompaction
;
...
@@ -72,11 +69,15 @@ fn concat_merge(new_key: &[u8], existing_val: Option<&[u8]>,
...
@@ -72,11 +69,15 @@ fn concat_merge(new_key: &[u8], existing_val: Option<&[u8]>,
mut
operands
:
&
mut
MergeOperands
)
->
Vec
<
u8
>
{
mut
operands
:
&
mut
MergeOperands
)
->
Vec
<
u8
>
{
let
mut
result
:
Vec
<
u8
>
=
Vec
::
with_capacity
(
operands
.size_hint
()
.
0
);
let
mut
result
:
Vec
<
u8
>
=
Vec
::
with_capacity
(
operands
.size_hint
()
.
0
);
match
existing_val
{
match
existing_val
{
Some
(
v
)
=>
result
.extend
(
v
),
Some
(
v
)
=>
for
e
in
v
{
result
.push
(
*
e
)
},
None
=>
(),
None
=>
(),
}
}
for
op
in
operands
{
for
op
in
operands
{
result
.extend
(
op
);
for
e
in
op
{
result
.push
(
*
e
);
}
}
}
result
result
}
}
...
@@ -138,7 +139,6 @@ fn main() {
...
@@ -138,7 +139,6 @@ fn main() {
#[cfg(test)]
#[cfg(test)]
mod
tests
{
mod
tests
{
use
test
::
Bencher
;
use
std
::
thread
::
sleep_ms
;
use
std
::
thread
::
sleep_ms
;
use
rocksdb
::{
BlockBasedOptions
,
Options
,
RocksDB
,
MergeOperands
,
new_bloom_filter
,
Writable
};
use
rocksdb
::{
BlockBasedOptions
,
Options
,
RocksDB
,
MergeOperands
,
new_bloom_filter
,
Writable
};
...
@@ -172,6 +172,7 @@ mod tests {
...
@@ -172,6 +172,7 @@ mod tests {
RocksDB
::
open
(
&
opts
,
path
)
.unwrap
()
RocksDB
::
open
(
&
opts
,
path
)
.unwrap
()
}
}
/* TODO(tyler) unstable
#[bench]
#[bench]
fn a_writes(b: &mut Bencher) {
fn a_writes(b: &mut Bencher) {
// dirty hack due to parallel tests causing contention.
// dirty hack due to parallel tests causing contention.
...
@@ -205,4 +206,5 @@ mod tests {
...
@@ -205,4 +206,5 @@ mod tests {
}
}
RocksDB::destroy(&opts, path).is_ok();
RocksDB::destroy(&opts, path).is_ok();
}
}
*/
}
}
src/merge_operator.rs
View file @
bc77ce17
...
@@ -131,7 +131,6 @@ impl MergeOperands {
...
@@ -131,7 +131,6 @@ impl MergeOperands {
impl
<
'a
>
Iterator
for
&
'a
mut
MergeOperands
{
impl
<
'a
>
Iterator
for
&
'a
mut
MergeOperands
{
type
Item
=
&
'a
[
u8
];
type
Item
=
&
'a
[
u8
];
fn
next
(
&
mut
self
)
->
Option
<&
'a
[
u8
]
>
{
fn
next
(
&
mut
self
)
->
Option
<&
'a
[
u8
]
>
{
use
std
::
raw
::
Slice
;
match
self
.cursor
==
self
.num_operands
{
match
self
.cursor
==
self
.num_operands
{
true
=>
None
,
true
=>
None
,
false
=>
{
false
=>
{
...
@@ -145,8 +144,8 @@ impl<'a> Iterator for &'a mut MergeOperands {
...
@@ -145,8 +144,8 @@ impl<'a> Iterator for &'a mut MergeOperands {
let
len
=
*
len_ptr
as
usize
;
let
len
=
*
len_ptr
as
usize
;
let
ptr
=
base
+
(
spacing
*
self
.cursor
);
let
ptr
=
base
+
(
spacing
*
self
.cursor
);
self
.cursor
+=
1
;
self
.cursor
+=
1
;
Some
(
mem
::
transmute
(
Slice
{
data
:
*
(
ptr
as
*
const
*
const
u8
)
Some
(
mem
::
transmute
(
slice
::
from_raw_parts
(
*
(
ptr
as
*
const
*
const
u8
)
as
*
const
u8
,
len
:
len
}
))
as
*
const
u8
,
len
)
))
}
}
}
}
}
}
...
@@ -165,11 +164,17 @@ fn test_provided_merge(new_key: &[u8],
...
@@ -165,11 +164,17 @@ fn test_provided_merge(new_key: &[u8],
let
nops
=
operands
.size_hint
()
.
0
;
let
nops
=
operands
.size_hint
()
.
0
;
let
mut
result
:
Vec
<
u8
>
=
Vec
::
with_capacity
(
nops
);
let
mut
result
:
Vec
<
u8
>
=
Vec
::
with_capacity
(
nops
);
match
existing_val
{
match
existing_val
{
Some
(
v
)
=>
result
.extend
(
v
),
Some
(
v
)
=>
{
for
e
in
v
{
result
.push
(
*
e
);
}
},
None
=>
(),
None
=>
(),
}
}
for
op
in
operands
{
for
op
in
operands
{
result
.extend
(
op
);
for
e
in
op
{
result
.push
(
*
e
);
}
}
}
result
result
}
}
...
...
src/rocksdb.rs
View file @
bc77ce17
...
@@ -17,10 +17,9 @@
...
@@ -17,10 +17,9 @@
extern
crate
libc
;
extern
crate
libc
;
use
self
::
libc
::{
c_void
,
size_t
};
use
self
::
libc
::{
c_void
,
size_t
};
use
std
::
ffi
::{
CString
,
CStr
};
use
std
::
ffi
::{
CString
,
CStr
};
use
std
::
fs
::{
self
,
PathExt
}
;
use
std
::
fs
;
use
std
::
ops
::
Deref
;
use
std
::
ops
::
Deref
;
use
std
::
path
::
Path
;
use
std
::
path
::
Path
;
use
std
::
ptr
::
Unique
;
use
std
::
slice
;
use
std
::
slice
;
use
std
::
str
::
from_utf8
;
use
std
::
str
::
from_utf8
;
use
std
::
marker
::
PhantomData
;
use
std
::
marker
::
PhantomData
;
...
@@ -192,12 +191,10 @@ impl RocksDB {
...
@@ -192,12 +191,10 @@ impl RocksDB {
let
cpath_ptr
=
cpath
.as_ptr
();
let
cpath_ptr
=
cpath
.as_ptr
();
let
ospath
=
Path
::
new
(
path
);
let
ospath
=
Path
::
new
(
path
);
if
!
ospath
.exists
()
{
match
fs
::
create_dir_all
(
&
ospath
)
{
match
fs
::
create_dir_all
(
&
ospath
)
{
Err
(
e
)
=>
return
Err
(
"Failed to create rocksdb directory."
.to_string
()),
Err
(
e
)
=>
return
Err
(
"Failed to create rocksdb directory."
.to_string
()),
Ok
(
_
)
=>
(),
Ok
(
_
)
=>
(),
}
}
}
let
mut
err
:
*
const
i8
=
0
as
*
const
i8
;
let
mut
err
:
*
const
i8
=
0
as
*
const
i8
;
let
err_ptr
:
*
mut
*
const
i8
=
&
mut
err
;
let
err_ptr
:
*
mut
*
const
i8
=
&
mut
err
;
...
@@ -222,10 +219,6 @@ impl RocksDB {
...
@@ -222,10 +219,6 @@ impl RocksDB {
let
cpath_ptr
=
cpath
.as_ptr
();
let
cpath_ptr
=
cpath
.as_ptr
();
let
ospath
=
Path
::
new
(
path
);
let
ospath
=
Path
::
new
(
path
);
if
!
ospath
.exists
()
{
return
Err
(
"path does not exist"
.to_string
());
}
let
mut
err
:
*
const
i8
=
0
as
*
const
i8
;
let
mut
err
:
*
const
i8
=
0
as
*
const
i8
;
let
err_ptr
:
*
mut
*
const
i8
=
&
mut
err
;
let
err_ptr
:
*
mut
*
const
i8
=
&
mut
err
;
unsafe
{
unsafe
{
...
@@ -242,10 +235,6 @@ impl RocksDB {
...
@@ -242,10 +235,6 @@ impl RocksDB {
let
cpath_ptr
=
cpath
.as_ptr
();
let
cpath_ptr
=
cpath
.as_ptr
();
let
ospath
=
Path
::
new
(
path
);
let
ospath
=
Path
::
new
(
path
);
if
!
ospath
.exists
()
{
return
Err
(
"path does not exist"
.to_string
());
}
let
mut
err
:
*
const
i8
=
0
as
*
const
i8
;
let
mut
err
:
*
const
i8
=
0
as
*
const
i8
;
let
err_ptr
:
*
mut
*
const
i8
=
&
mut
err
;
let
err_ptr
:
*
mut
*
const
i8
=
&
mut
err
;
unsafe
{
unsafe
{
...
@@ -442,21 +431,21 @@ impl ReadOptions {
...
@@ -442,21 +431,21 @@ impl ReadOptions {
}
}
pub
struct
RocksDBVector
{
pub
struct
RocksDBVector
{
base
:
Unique
<
u8
>
,
base
:
*
mut
u8
,
len
:
usize
,
len
:
usize
,
}
}
impl
Deref
for
RocksDBVector
{
impl
Deref
for
RocksDBVector
{
type
Target
=
[
u8
];
type
Target
=
[
u8
];
fn
deref
(
&
self
)
->
&
[
u8
]
{
fn
deref
(
&
self
)
->
&
[
u8
]
{
unsafe
{
slice
::
from_raw_parts
(
self
.base
.get
()
,
self
.len
)
}
unsafe
{
slice
::
from_raw_parts
(
self
.base
,
self
.len
)
}
}
}
}
}
impl
Drop
for
RocksDBVector
{
impl
Drop
for
RocksDBVector
{
fn
drop
(
&
mut
self
)
{
fn
drop
(
&
mut
self
)
{
unsafe
{
unsafe
{
libc
::
free
(
*
self
.base
.deref
()
as
*
mut
libc
::
c_void
);
libc
::
free
(
self
.base
as
*
mut
libc
::
c_void
);
}
}
}
}
}
}
...
@@ -465,7 +454,7 @@ impl RocksDBVector {
...
@@ -465,7 +454,7 @@ impl RocksDBVector {
pub
fn
from_c
(
val
:
*
mut
u8
,
val_len
:
size_t
)
->
RocksDBVector
{
pub
fn
from_c
(
val
:
*
mut
u8
,
val_len
:
size_t
)
->
RocksDBVector
{
unsafe
{
unsafe
{
RocksDBVector
{
RocksDBVector
{
base
:
Unique
::
new
(
val
)
,
base
:
val
,
len
:
val_len
as
usize
,
len
:
val_len
as
usize
,
}
}
}
}
...
...
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