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
d3176044
Commit
d3176044
authored
Sep 29, 2016
by
zhangjinpeng1987
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rocksdb_compact_range use nullptr as smallest/largest key
parent
3efedab4
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
59 additions
and
5 deletions
+59
-5
lib.rs
src/lib.rs
+1
-1
rocksdb.rs
src/rocksdb.rs
+24
-4
test_compact_range.rs
test/test_compact_range.rs
+34
-0
No files found.
src/lib.rs
View file @
d3176044
...
...
@@ -30,6 +30,6 @@ pub use librocksdb_sys::{DBCompactionStyle, DBCompressionType, DBRecoveryMode,
new_bloom_filter
,
self
as
rocksdb_ffi
};
pub
use
merge_operator
::
MergeOperands
;
pub
use
rocksdb
::{
DB
,
DBIterator
,
DBVector
,
Kv
,
SeekKey
,
Writable
,
WriteBatch
,
CFHandle
};
CFHandle
,
Range
};
pub
use
rocksdb_options
::{
BlockBasedOptions
,
Options
,
ReadOptions
,
WriteOptions
};
src/rocksdb.rs
View file @
d3176044
...
...
@@ -850,10 +850,20 @@ impl DB {
pub
fn
compact_range
(
&
self
,
start_key
:
&
[
u8
],
end_key
:
&
[
u8
])
{
unsafe
{
let
start
=
if
start_key
.is_empty
()
{
0
as
*
const
u8
}
else
{
start_key
.as_ptr
()
};
let
end
=
if
end_key
.is_empty
()
{
0
as
*
const
u8
}
else
{
end_key
.as_ptr
()
};
rocksdb_ffi
::
rocksdb_compact_range
(
self
.inner
,
start
_key
.as_ptr
()
,
start
,
start_key
.len
()
as
size_t
,
end
_key
.as_ptr
()
,
end
,
end_key
.len
());
}
}
...
...
@@ -863,11 +873,21 @@ impl DB {
start_key
:
&
[
u8
],
end_key
:
&
[
u8
])
{
unsafe
{
let
start
=
if
start_key
.is_empty
()
{
0
as
*
const
u8
}
else
{
start_key
.as_ptr
()
};
let
end
=
if
end_key
.is_empty
()
{
0
as
*
const
u8
}
else
{
end_key
.as_ptr
()
};
rocksdb_ffi
::
rocksdb_compact_range_cf
(
self
.inner
,
cf
.inner
,
start
_key
.as_ptr
()
,
start
,
start_key
.len
()
as
size_t
,
end
_key
.as_ptr
()
,
end
,
end_key
.len
());
}
}
...
...
test/test_compact_range.rs
0 → 100644
View file @
d3176044
use
tempdir
::
TempDir
;
use
rocksdb
::{
DB
,
Options
,
Range
,
Writable
};
#[test]
fn
test_compact_range
()
{
let
path
=
TempDir
::
new
(
"_rust_rocksdb_test_compact_range"
)
.expect
(
""
);
let
mut
opts
=
Options
::
new
();
opts
.create_if_missing
(
true
);
let
db
=
DB
::
open
(
&
opts
,
path
.path
()
.to_str
()
.unwrap
())
.unwrap
();
let
samples
=
vec!
[
(
b
"k1"
.to_vec
(),
b
"value--------1"
.to_vec
()),
(
b
"k2"
.to_vec
(),
b
"value--------2"
.to_vec
()),
(
b
"k3"
.to_vec
(),
b
"value--------3"
.to_vec
()),
(
b
"k4"
.to_vec
(),
b
"value--------4"
.to_vec
()),
(
b
"k5"
.to_vec
(),
b
"value--------5"
.to_vec
()),
];
for
&
(
ref
k
,
ref
v
)
in
&
samples
{
db
.put
(
k
,
v
)
.unwrap
();
assert_eq!
(
v
.as_slice
(),
&*
db
.get
(
k
)
.unwrap
()
.unwrap
());
}
// flush memtable to sst file
db
.flush
(
true
)
.unwrap
();
let
old_size
=
db
.get_approximate_sizes
(
&
[
Range
::
new
(
b
"k0"
,
b
"k6"
)])[
0
];
// delete all and compact whole range
for
&
(
ref
k
,
_
)
in
&
samples
{
db
.delete
(
k
)
.unwrap
()
}
db
.compact_range
(
b
""
,
b
""
);
let
new_size
=
db
.get_approximate_sizes
(
&
[
Range
::
new
(
b
"k0"
,
b
"k6"
)])[
0
];
assert
!
(
old_size
>
new_size
);
}
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