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
b9f0eee4
Commit
b9f0eee4
authored
Sep 29, 2016
by
zhangjinpeng1987
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use None as largest/smallest key
parent
8173993f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
30 deletions
+15
-30
rocksdb.rs
src/rocksdb.rs
+12
-27
test_compact_range.rs
test/test_compact_range.rs
+1
-1
test_compaction_filter.rs
test/test_compaction_filter.rs
+2
-2
No files found.
src/rocksdb.rs
View file @
b9f0eee4
...
...
@@ -26,6 +26,7 @@ use std::ops::Deref;
use
std
::
path
::
Path
;
use
std
::
slice
;
use
std
::
str
::
from_utf8
;
use
std
::
ptr
;
const
DEFAULT_COLUMN_FAMILY
:
&
'static
str
=
"default"
;
...
...
@@ -848,47 +849,31 @@ impl DB {
sizes
}
pub
fn
compact_range
(
&
self
,
start_key
:
&
[
u8
],
end_key
:
&
[
u8
]
)
{
pub
fn
compact_range
(
&
self
,
start_key
:
Option
<&
[
u8
]
>
,
end_key
:
Option
<&
[
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
()
};
let
(
start
,
s_len
)
=
start_key
.map_or
((
ptr
::
null
(),
0
),
|
k
|
(
k
.as_ptr
(),
k
.len
()));
let
(
end
,
e_len
)
=
end_key
.map_or
((
ptr
::
null
(),
0
),
|
k
|
(
k
.as_ptr
(),
k
.len
()));
rocksdb_ffi
::
rocksdb_compact_range
(
self
.inner
,
start
,
s
tart_key
.len
()
as
size_t
,
s
_len
,
end
,
e
nd_key
.len
()
);
e
_len
);
}
}
pub
fn
compact_range_cf
(
&
self
,
cf
:
&
CFHandle
,
start_key
:
&
[
u8
]
,
end_key
:
&
[
u8
]
)
{
start_key
:
Option
<&
[
u8
]
>
,
end_key
:
Option
<&
[
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
()
};
let
(
start
,
s_len
)
=
start_key
.map_or
((
ptr
::
null
(),
0
),
|
k
|
(
k
.as_ptr
(),
k
.len
()));
let
(
end
,
e_len
)
=
end_key
.map_or
((
ptr
::
null
(),
0
),
|
k
|
(
k
.as_ptr
(),
k
.len
()));
rocksdb_ffi
::
rocksdb_compact_range_cf
(
self
.inner
,
cf
.inner
,
start
,
s
tart_key
.len
()
as
size_t
,
s
_len
,
end
,
e
nd_key
.len
()
);
e
_len
);
}
}
...
...
test/test_compact_range.rs
View file @
b9f0eee4
...
...
@@ -28,7 +28,7 @@ fn test_compact_range() {
for
&
(
ref
k
,
_
)
in
&
samples
{
db
.delete
(
k
)
.unwrap
()
}
db
.compact_range
(
b
""
,
b
""
);
db
.compact_range
(
None
,
None
);
let
new_size
=
db
.get_approximate_sizes
(
&
[
Range
::
new
(
b
"k0"
,
b
"k6"
)])[
0
];
assert
!
(
old_size
>
new_size
);
}
test/test_compaction_filter.rs
View file @
b9f0eee4
...
...
@@ -47,7 +47,7 @@ fn test_compaction_filter() {
let
_snap
=
db
.snapshot
();
// Because ignore_snapshots is false, so force compact will not effect
// the keys written before.
db
.compact_range
(
b
"key1"
,
b
"key3"
);
db
.compact_range
(
Some
(
b
"key1"
),
Some
(
b
"key3"
)
);
for
&
(
ref
k
,
ref
v
)
in
&
samples
{
assert_eq!
(
v
.as_slice
(),
&*
db
.get
(
k
)
.unwrap
()
.unwrap
());
}
...
...
@@ -66,7 +66,7 @@ fn test_compaction_filter() {
let
db
=
DB
::
open
(
&
opts
,
path
.path
()
.to_str
()
.unwrap
())
.unwrap
();
let
_snap
=
db
.snapshot
();
// Because ignore_snapshots is true, so all the keys will be compacted.
db
.compact_range
(
b
"key1"
,
b
"key3"
);
db
.compact_range
(
Some
(
b
"key1"
),
Some
(
b
"key3"
)
);
for
&
(
ref
k
,
_
)
in
&
samples
{
assert
!
(
db
.get
(
k
)
.unwrap
()
.is_none
());
}
...
...
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