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
95c21ea1
Commit
95c21ea1
authored
May 18, 2015
by
Tyler Neely
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
get some basics working, still need to fix merge operators for post-1.0
parent
d725d6df
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
32 additions
and
27 deletions
+32
-27
ffi.rs
src/ffi.rs
+14
-17
main.rs
src/main.rs
+11
-2
merge_operator.rs
src/merge_operator.rs
+5
-5
rocksdb.rs
src/rocksdb.rs
+1
-1
rocksdb_options.rs
src/rocksdb_options.rs
+1
-2
No files found.
src/ffi.rs
View file @
95c21ea1
...
@@ -15,48 +15,45 @@
...
@@ -15,48 +15,45 @@
*/
*/
extern
crate
libc
;
extern
crate
libc
;
use
self
::
libc
::{
c_char
,
c_int
,
c_void
,
size_t
};
use
self
::
libc
::{
c_char
,
c_int
,
c_void
,
size_t
};
use
std
::
ffi
::
CString
;
#[derive(Copy,
Clone)]
#[repr(C)]
#[repr(C)]
pub
struct
RocksDBOptions
(
pub
*
const
c_void
);
pub
struct
RocksDBOptions
(
pub
*
const
c_void
);
#[derive(Copy,
Clone)]
#[repr(C)]
#[repr(C)]
pub
struct
RocksDBInstance
(
pub
*
const
c_void
);
pub
struct
RocksDBInstance
(
pub
*
const
c_void
);
#[derive(Copy,
Clone)]
#[repr(C)]
#[repr(C)]
pub
struct
RocksDBWriteOptions
(
pub
*
const
c_void
);
pub
struct
RocksDBWriteOptions
(
pub
*
const
c_void
);
#[derive(Copy,
Clone)]
#[repr(C)]
#[repr(C)]
pub
struct
RocksDBReadOptions
(
pub
*
const
c_void
);
pub
struct
RocksDBReadOptions
(
pub
*
const
c_void
);
#[derive(Copy,
Clone)]
#[repr(C)]
#[repr(C)]
pub
struct
RocksDBMergeOperator
(
pub
*
const
c_void
);
pub
struct
RocksDBMergeOperator
(
pub
*
const
c_void
);
#[derive(Copy,
Clone)]
#[repr(C)]
#[repr(C)]
pub
struct
RocksDBBlockBasedTableOptions
(
pub
*
const
c_void
);
pub
struct
RocksDBBlockBasedTableOptions
(
pub
*
const
c_void
);
#[derive(Copy,
Clone)]
#[repr(C)]
#[repr(C)]
pub
struct
RocksDBCache
(
pub
*
const
c_void
);
pub
struct
RocksDBCache
(
pub
*
const
c_void
);
#[derive(Copy,
Clone)]
#[repr(C)]
#[repr(C)]
pub
struct
RocksDBFilterPolicy
(
pub
*
const
c_void
);
pub
struct
RocksDBFilterPolicy
(
pub
*
const
c_void
);
#[derive(Copy,
Clone)]
#[repr(C)]
#[repr(C)]
pub
struct
RocksDBSnapshot
(
pub
*
const
c_void
);
pub
struct
RocksDBSnapshot
(
pub
*
const
c_void
);
#[derive(Copy,
Clone)]
#[repr(C)]
#[repr(C)]
pub
struct
RocksDBIterator
(
pub
*
const
c_void
);
pub
struct
RocksDBIterator
(
pub
*
const
c_void
);
#[derive(Copy,
Clone)]
#[repr(C)]
#[repr(C)]
pub
struct
RocksDBCFHandle
(
pub
*
const
c_void
);
pub
struct
RocksDBCFHandle
(
pub
*
const
c_void
);
#[derive(Copy,
Clone)]
#[repr(C)]
#[repr(C)]
pub
struct
RocksDBWriteBatch
(
pub
*
const
c_void
);
pub
struct
RocksDBWriteBatch
(
pub
*
const
c_void
);
impl
Copy
for
RocksDBOptions
{}
impl
Copy
for
RocksDBInstance
{}
impl
Copy
for
RocksDBWriteOptions
{}
impl
Copy
for
RocksDBReadOptions
{}
impl
Copy
for
RocksDBMergeOperator
{}
impl
Copy
for
RocksDBBlockBasedTableOptions
{}
impl
Copy
for
RocksDBCache
{}
impl
Copy
for
RocksDBFilterPolicy
{}
impl
Copy
for
RocksDBCompactionStyle
{}
impl
Copy
for
RocksDBCompressionType
{}
impl
Copy
for
RocksDBUniversalCompactionStyle
{}
impl
Copy
for
RocksDBSnapshot
{}
impl
Copy
for
RocksDBIterator
{}
impl
Copy
for
RocksDBCFHandle
{}
impl
Copy
for
RocksDBWriteBatch
{}
pub
fn
new_bloom_filter
(
bits
:
c_int
)
->
RocksDBFilterPolicy
{
pub
fn
new_bloom_filter
(
bits
:
c_int
)
->
RocksDBFilterPolicy
{
unsafe
{
unsafe
{
rocksdb_filterpolicy_create_bloom
(
bits
)
rocksdb_filterpolicy_create_bloom
(
bits
)
...
@@ -329,7 +326,7 @@ fn internal() {
...
@@ -329,7 +326,7 @@ fn internal() {
rocksdb_options_set_create_if_missing
(
opts
,
true
);
rocksdb_options_set_create_if_missing
(
opts
,
true
);
let
rustpath
=
"_rust_rocksdb_internaltest"
;
let
rustpath
=
"_rust_rocksdb_internaltest"
;
let
cpath
=
CString
::
from_slice
(
rustpath
.as_bytes
()
);
let
cpath
=
CString
::
new
(
rustpath
)
.unwrap
(
);
let
cpath_ptr
=
cpath
.as_ptr
();
let
cpath_ptr
=
cpath
.as_ptr
();
let
err
=
0
as
*
mut
i8
;
let
err
=
0
as
*
mut
i8
;
...
...
src/main.rs
View file @
95c21ea1
...
@@ -71,8 +71,17 @@ fn custom_merge() {
...
@@ -71,8 +71,17 @@ fn custom_merge() {
db
.merge
(
b
"k1"
,
b
"d"
);
db
.merge
(
b
"k1"
,
b
"d"
);
db
.merge
(
b
"k1"
,
b
"efg"
);
db
.merge
(
b
"k1"
,
b
"efg"
);
let
m
=
db
.merge
(
b
"k1"
,
b
"h"
);
let
m
=
db
.merge
(
b
"k1"
,
b
"h"
);
let
r
=
db
.get
(
b
"k1"
);
db
.get
(
b
"k1"
)
.map
(
|
value
|
{
assert
!
(
r
.unwrap
()
.to_utf8
()
.unwrap
()
==
"abcdefgh"
);
match
value
.to_utf8
()
{
Some
(
v
)
=>
println!
(
"retrieved utf8 value: {}"
,
v
),
None
=>
println!
(
"did not read valid utf-8 out of the db"
),
}
})
.on_absent
(
||
{
println!
(
"value not found"
)
})
.on_error
(
|
e
|
{
println!
(
"error retrieving value: {}"
,
e
)
});
db
.close
();
db
.close
();
RocksDB
::
destroy
(
opts
,
path
)
.is_ok
();
RocksDB
::
destroy
(
opts
,
path
)
.is_ok
();
}
}
...
...
src/merge_operator.rs
View file @
95c21ea1
...
@@ -56,8 +56,8 @@ pub extern "C" fn full_merge_callback(
...
@@ -56,8 +56,8 @@ pub extern "C" fn full_merge_callback(
&
mut
MergeOperands
::
new
(
operands_list
,
&
mut
MergeOperands
::
new
(
operands_list
,
operands_list_len
,
operands_list_len
,
num_operands
);
num_operands
);
let
key
:
&
[
u8
]
=
mem
::
transmute
(
slice
::
from_raw_
buf
(
&
raw_key
,
key_len
as
usize
));
let
key
:
&
[
u8
]
=
mem
::
transmute
(
slice
::
from_raw_
parts
(
&
raw_key
,
key_len
as
usize
));
let
oldval
:
&
[
u8
]
=
mem
::
transmute
(
slice
::
from_raw_
buf
(
&
existing_value
,
let
oldval
:
&
[
u8
]
=
mem
::
transmute
(
slice
::
from_raw_
parts
(
&
existing_value
,
existing_value_len
as
usize
));
existing_value_len
as
usize
));
let
mut
result
=
let
mut
result
=
(
cb
.merge_fn
)(
key
,
Some
(
oldval
),
operands
);
(
cb
.merge_fn
)(
key
,
Some
(
oldval
),
operands
);
...
@@ -67,7 +67,7 @@ pub extern "C" fn full_merge_callback(
...
@@ -67,7 +67,7 @@ pub extern "C" fn full_merge_callback(
assert
!
(
!
buf
.is_null
());
assert
!
(
!
buf
.is_null
());
*
new_value_length
=
result
.len
()
as
size_t
;
*
new_value_length
=
result
.len
()
as
size_t
;
*
success
=
1
as
u8
;
*
success
=
1
as
u8
;
ptr
::
copy
(
&
mut
*
buf
,
result
.as_ptr
()
as
*
const
c_void
,
result
.len
());
ptr
::
copy
(
result
.as_ptr
()
as
*
mut
c_void
,
&
mut
*
buf
,
result
.len
());
buf
as
*
const
c_char
buf
as
*
const
c_char
}
}
}
}
...
@@ -83,7 +83,7 @@ pub extern "C" fn partial_merge_callback(
...
@@ -83,7 +83,7 @@ pub extern "C" fn partial_merge_callback(
let
operands
=
&
mut
MergeOperands
::
new
(
operands_list
,
let
operands
=
&
mut
MergeOperands
::
new
(
operands_list
,
operands_list_len
,
operands_list_len
,
num_operands
);
num_operands
);
let
key
:
&
[
u8
]
=
mem
::
transmute
(
slice
::
from_raw_
buf
(
&
raw_key
,
key_len
as
usize
));
let
key
:
&
[
u8
]
=
mem
::
transmute
(
slice
::
from_raw_
parts
(
&
raw_key
,
key_len
as
usize
));
let
mut
result
=
(
cb
.merge_fn
)(
key
,
None
,
operands
);
let
mut
result
=
(
cb
.merge_fn
)(
key
,
None
,
operands
);
result
.shrink_to_fit
();
result
.shrink_to_fit
();
//TODO(tan) investigate zero-copy techniques to improve performance
//TODO(tan) investigate zero-copy techniques to improve performance
...
@@ -91,7 +91,7 @@ pub extern "C" fn partial_merge_callback(
...
@@ -91,7 +91,7 @@ pub extern "C" fn partial_merge_callback(
assert
!
(
!
buf
.is_null
());
assert
!
(
!
buf
.is_null
());
*
new_value_length
=
1
as
size_t
;
*
new_value_length
=
1
as
size_t
;
*
success
=
1
as
u8
;
*
success
=
1
as
u8
;
ptr
::
copy
(
&
mut
*
buf
,
result
.as_ptr
()
as
*
const
c_void
,
result
.len
());
ptr
::
copy
(
result
.as_ptr
()
as
*
mut
c_void
,
&
mut
*
buf
,
result
.len
());
buf
as
*
const
c_char
buf
as
*
const
c_char
}
}
}
}
...
...
src/rocksdb.rs
View file @
95c21ea1
...
@@ -198,7 +198,7 @@ pub struct RocksDBVector {
...
@@ -198,7 +198,7 @@ pub struct RocksDBVector {
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_
mut_buf
(
self
.base
.deref
(),
self
.len
)
}
unsafe
{
slice
::
from_raw_
parts
(
self
.base
.get
(),
self
.len
)
}
}
}
}
}
...
...
src/rocksdb_options.rs
View file @
95c21ea1
...
@@ -22,13 +22,12 @@ use rocksdb_ffi;
...
@@ -22,13 +22,12 @@ use rocksdb_ffi;
use
merge_operator
::{
MergeOperatorCallback
,
MergeOperands
,
destructor_callback
,
full_merge_callback
,
use
merge_operator
::{
MergeOperatorCallback
,
MergeOperands
,
destructor_callback
,
full_merge_callback
,
partial_merge_callback
,
name_callback
};
partial_merge_callback
,
name_callback
};
#[derive(Copy,
Clone)]
pub
struct
RocksDBOptions
{
pub
struct
RocksDBOptions
{
pub
inner
:
rocksdb_ffi
::
RocksDBOptions
,
pub
inner
:
rocksdb_ffi
::
RocksDBOptions
,
block_options
:
rocksdb_ffi
::
RocksDBBlockBasedTableOptions
,
block_options
:
rocksdb_ffi
::
RocksDBBlockBasedTableOptions
,
}
}
impl
Copy
for
RocksDBOptions
{}
impl
RocksDBOptions
{
impl
RocksDBOptions
{
pub
fn
new
()
->
RocksDBOptions
{
pub
fn
new
()
->
RocksDBOptions
{
unsafe
{
unsafe
{
...
...
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