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
459356c8
Commit
459356c8
authored
Oct 12, 2018
by
evenyag
Committed by
Huachao Huang
Oct 12, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix incorrect merge result db reopened (#223) (#224)
parent
348b5bc9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
66 additions
and
26 deletions
+66
-26
merge_operator.rs
src/merge_operator.rs
+66
-26
No files found.
src/merge_operator.rs
View file @
459356c8
...
...
@@ -88,7 +88,7 @@ pub extern "C" fn partial_merge_callback(
// TODO(tan) investigate zero-copy techniques to improve performance
let
buf
=
libc
::
malloc
(
result
.len
()
as
size_t
);
assert
!
(
!
buf
.is_null
());
*
new_value_length
=
1
as
size_t
;
*
new_value_length
=
result
.len
()
as
size_t
;
*
success
=
1
as
u8
;
ptr
::
copy
(
result
.as_ptr
()
as
*
mut
c_void
,
&
mut
*
buf
,
result
.len
());
buf
as
*
const
c_char
...
...
@@ -184,32 +184,72 @@ mod test {
opts
.create_if_missing
(
true
);
let
mut
cf_opts
=
ColumnFamilyOptions
::
new
();
cf_opts
.add_merge_operator
(
"test operator"
,
test_provided_merge
);
let
db
=
DB
::
open_cf
(
opts
,
path
.path
()
.to_str
()
.unwrap
(),
vec!
[(
"default"
,
cf_opts
)],
)
.unwrap
();
let
p
=
db
.put
(
b
"k1"
,
b
"a"
);
assert
!
(
p
.is_ok
());
let
_
=
db
.merge
(
b
"k1"
,
b
"b"
);
let
_
=
db
.merge
(
b
"k1"
,
b
"c"
);
let
_
=
db
.merge
(
b
"k1"
,
b
"d"
);
let
_
=
db
.merge
(
b
"k1"
,
b
"efg"
);
let
m
=
db
.merge
(
b
"k1"
,
b
"h"
);
assert
!
(
m
.is_ok
());
match
db
.get
(
b
"k1"
)
{
Ok
(
Some
(
value
))
=>
match
value
.to_utf8
()
{
Some
(
v
)
=>
println!
(
"retrieved utf8 value: {}"
,
v
),
None
=>
println!
(
"did not read valid utf-8 out of the db"
),
},
Err
(
e
)
=>
println!
(
"error reading value {:?}"
,
e
),
_
=>
panic!
(
"value not present"
),
{
let
db
=
DB
::
open_cf
(
opts
.clone
(),
path
.path
()
.to_str
()
.unwrap
(),
vec!
[(
"default"
,
cf_opts
.clone
())],
)
.unwrap
();
let
p
=
db
.put
(
b
"k1"
,
b
"a"
);
assert
!
(
p
.is_ok
());
let
_
=
db
.merge
(
b
"k1"
,
b
"b"
);
let
_
=
db
.merge
(
b
"k1"
,
b
"c"
);
let
_
=
db
.merge
(
b
"k1"
,
b
"d"
);
let
_
=
db
.merge
(
b
"k1"
,
b
"efg"
);
let
m
=
db
.merge
(
b
"k1"
,
b
"h"
);
assert
!
(
m
.is_ok
());
match
db
.get
(
b
"k1"
)
{
Ok
(
Some
(
value
))
=>
match
value
.to_utf8
()
{
Some
(
v
)
=>
println!
(
"retrieved utf8 value: {}"
,
v
),
None
=>
println!
(
"did not read valid utf-8 out of the db"
),
},
Err
(
e
)
=>
println!
(
"error reading value {:?}"
,
e
),
_
=>
panic!
(
"value not present"
),
}
let
r
:
Result
<
Option
<
DBVector
>
,
String
>
=
db
.get
(
b
"k1"
);
assert_eq!
(
r
.unwrap
()
.unwrap
(),
b
"abcdefgh"
);
let
_
=
db
.merge
(
b
"k2"
,
b
"he"
);
let
_
=
db
.merge
(
b
"k2"
,
b
"l"
);
let
_
=
db
.merge
(
b
"k2"
,
b
"l"
);
let
_
=
db
.merge
(
b
"k2"
,
b
"o wor"
);
let
m
=
db
.merge
(
b
"k2"
,
b
"ld"
);
assert
!
(
m
.is_ok
());
let
r
:
Result
<
Option
<
DBVector
>
,
String
>
=
db
.get
(
b
"k2"
);
assert_eq!
(
r
.unwrap
()
.unwrap
(),
b
"hello world"
);
}
assert
!
(
m
.is_ok
());
let
r
:
Result
<
Option
<
DBVector
>
,
String
>
=
db
.get
(
b
"k1"
);
assert
!
(
r
.unwrap
()
.unwrap
()
.to_utf8
()
.unwrap
()
==
"abcdefgh"
);
assert
!
(
db
.delete
(
b
"k1"
)
.is_ok
());
assert
!
(
db
.get
(
b
"k1"
)
.unwrap
()
.is_none
());
{
// Reopen
let
db
=
DB
::
open_cf
(
opts
.clone
(),
path
.path
()
.to_str
()
.unwrap
(),
vec!
[(
"default"
,
cf_opts
.clone
())],
)
.unwrap
();
let
r
:
Result
<
Option
<
DBVector
>
,
String
>
=
db
.get
(
b
"k1"
);
assert_eq!
(
r
.unwrap
()
.unwrap
(),
b
"abcdefgh"
);
let
r
:
Result
<
Option
<
DBVector
>
,
String
>
=
db
.get
(
b
"k2"
);
assert_eq!
(
r
.unwrap
()
.unwrap
(),
b
"hello world"
);
assert
!
(
db
.delete
(
b
"k1"
)
.is_ok
());
assert
!
(
db
.get
(
b
"k1"
)
.unwrap
()
.is_none
());
}
{
// Reopen
let
db
=
DB
::
open_cf
(
opts
.clone
(),
path
.path
()
.to_str
()
.unwrap
(),
vec!
[(
"default"
,
cf_opts
)],
)
.unwrap
();
assert
!
(
db
.get
(
b
"k1"
)
.unwrap
()
.is_none
());
let
r
:
Result
<
Option
<
DBVector
>
,
String
>
=
db
.get
(
b
"k2"
);
assert_eq!
(
r
.unwrap
()
.unwrap
(),
b
"hello world"
);
}
}
}
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