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
64a298ff
Commit
64a298ff
authored
Nov 30, 2014
by
Tyler Neely
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add debugging info, some proper malloc'ing
parent
90ef2333
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
10 deletions
+43
-10
ffi.rs
src/ffi.rs
+1
-1
rocksdb.rs
src/rocksdb.rs
+42
-9
No files found.
src/ffi.rs
View file @
64a298ff
...
...
@@ -144,7 +144,7 @@ extern {
}
#[allow(dead_code)]
#[
t
est]
#[
z
est]
fn
internal
()
{
unsafe
{
let
opts
=
rocksdb_options_create
();
...
...
src/rocksdb.rs
View file @
64a298ff
...
...
@@ -5,6 +5,7 @@ use std::c_vec::CVec;
use
std
::
c_str
::
CString
;
use
std
::
str
::
from_utf8
;
use
std
::
string
::
raw
::
from_buf_len
;
use
std
::
ptr
;
use
rocksdb_ffi
;
...
...
@@ -164,8 +165,10 @@ impl RocksDB {
let
val_len
:
size_t
=
0
;
let
val_len_ptr
=
&
val_len
as
*
const
size_t
;
let
err
=
0
as
*
mut
i8
;
println!
(
"above ffi get"
);
let
val
=
rocksdb_ffi
::
rocksdb_get
(
self
.inner
,
readopts
,
key
.as_ptr
(),
key
.len
()
as
size_t
,
val_len_ptr
,
err
)
as
*
mut
u8
;
println!
(
"below ffi get"
);
if
err
.is_not_null
()
{
let
cs
=
CString
::
new
(
err
as
*
const
i8
,
true
);
match
cs
.as_str
()
{
...
...
@@ -314,7 +317,7 @@ impl <'a,T,E> RocksDBResult<'a,T,E> {
}
#[allow(dead_code)]
#[
t
est]
#[
z
est]
fn
external
()
{
let
db
=
RocksDB
::
open_default
(
"externaltest"
)
.unwrap
();
let
p
=
db
.put
(
b
"k1"
,
b
"v1111"
);
...
...
@@ -327,10 +330,17 @@ fn external() {
}
extern
"C"
fn
null_destructor
(
args
:
*
mut
c_void
)
{
println!
(
"in null_destructor
now
"
);
println!
(
"in null_destructor"
);
}
extern
"C"
fn
mo_name
(
args
:
*
mut
c_void
)
->
*
const
c_char
{
"test_mo"
.to_c_str
()
.as_ptr
()
println!
(
"in mo_name"
);
let
name
=
"test_mo"
.to_c_str
();
unsafe
{
let
buf
=
libc
::
malloc
(
8
as
size_t
);
ptr
::
copy_memory
(
&
mut
*
buf
,
name
.as_ptr
()
as
*
const
c_void
,
8
);
println!
(
"returning from mo_name"
);
buf
as
*
const
c_char
}
}
extern
"C"
fn
full_merge
(
arg
:
*
mut
c_void
,
key
:
*
const
c_char
,
key_len
:
*
mut
size_t
,
...
...
@@ -339,14 +349,25 @@ extern "C" fn full_merge(
num_operands
:
c_int
,
success
:
*
mut
u8
,
new_value_length
:
*
mut
size_t
)
->
*
const
c_char
{
unsafe
{
println!
(
"in the FULL merge operator
right now!
"
);
println!
(
"in the FULL merge operator"
);
//println!("first opt len: {}", operands_list_len[0]);
let
oldkey
=
from_buf_len
(
key
as
*
const
u8
,
key_len
as
uint
);
let
oldval
=
from_buf_len
(
existing_value
as
*
const
u8
,
existing_value_len
as
uint
);
let
buf
=
libc
::
malloc
(
1
as
size_t
);
match
buf
.is_null
()
{
false
=>
{
*
new_value_length
=
1
;
*
success
=
1
as
u8
;
let
newval
=
"2"
;
ptr
::
copy_memory
(
&
mut
*
buf
,
newval
.as_ptr
()
as
*
const
c_void
,
1
);
println!
(
"returning from full_merge"
);
buf
as
*
const
c_char
},
true
=>
{
return
0
as
*
const
c_char
;
}
}
}
"2"
.to_c_str
()
.as_ptr
()
}
extern
"C"
fn
partial_merge
(
arg
:
*
mut
c_void
,
key
:
*
const
c_char
,
key_len
:
*
mut
size_t
,
...
...
@@ -354,7 +375,7 @@ extern "C" fn partial_merge(
num_operands
:
c_int
,
success
:
*
mut
u8
,
new_value_length
:
*
mut
size_t
)
->
*
const
c_char
{
unsafe
{
println!
(
"in the PARTIAL merge operator
right now!
"
);
println!
(
"in the PARTIAL merge operator"
);
*
new_value_length
=
2
;
*
success
=
1
as
u8
;
}
...
...
@@ -363,7 +384,7 @@ extern "C" fn partial_merge(
#[allow(dead_code)]
#[
z
est]
#[
t
est]
fn
mergetest
()
{
unsafe
{
let
opts
=
RocksDBOptions
::
new
();
...
...
@@ -377,11 +398,23 @@ fn mergetest() {
opts
.create_if_missing
(
true
);
opts
.set_merge_operator
(
mo
);
let
db
=
RocksDB
::
open
(
opts
,
"externaltest"
)
.unwrap
();
println!
(
"after open"
);
let
p
=
db
.put
(
b
"k1"
,
b
"1"
);
//assert!(p.is_ok());
assert
!
(
p
.is_ok
());
println!
(
"before merge"
);
let
m
=
db
.merge
(
b
"k1"
,
b
"1"
);
println!
(
"m is {}"
,
m
);
println!
(
"after merge"
);
println!
(
"k1's value is: {}"
,
db
.get
(
b
"k1"
)
.unwrap
()
.to_utf8
()
.unwrap
());
db
.get
(
b
"k1"
)
.map
(
|
value
|
{
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 present!"
)
})
.on_error
(
|
e
|
{
println!
(
"error reading value: {}"
,
e
)
});
/*
assert!(m.is_ok());
let r: RocksDBResult<RocksDBVector, String> = db.get(b"k1");
...
...
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