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
cb63dcd1
Unverified
Commit
cb63dcd1
authored
Feb 02, 2018
by
Huachao Huang
Committed by
GitHub
Feb 02, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add compact options to compact files to a specific level (#186)
parent
c4b1aca7
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
51 additions
and
1 deletion
+51
-1
lib.rs
librocksdb_sys/src/lib.rs
+8
-0
rocksdb_options.rs
src/rocksdb_options.rs
+12
-0
test_compact_range.rs
tests/test_compact_range.rs
+31
-1
No files found.
librocksdb_sys/src/lib.rs
View file @
cb63dcd1
...
...
@@ -984,6 +984,14 @@ extern "C" {
opt
:
*
mut
DBCompactOptions
,
v
:
bool
,
);
pub
fn
crocksdb_compactoptions_set_change_level
(
opt
:
*
mut
DBCompactOptions
,
v
:
bool
,
);
pub
fn
crocksdb_compactoptions_set_target_level
(
opt
:
*
mut
DBCompactOptions
,
v
:
i32
,
);
pub
fn
crocksdb_fifo_compaction_options_create
()
->
*
mut
DBFifoCompactionOptions
;
pub
fn
crocksdb_fifo_compaction_options_set_max_table_files_size
(
...
...
src/rocksdb_options.rs
View file @
cb63dcd1
...
...
@@ -471,6 +471,18 @@ impl CompactOptions {
crocksdb_ffi
::
crocksdb_compactoptions_set_exclusive_manual_compaction
(
self
.inner
,
v
);
}
}
pub
fn
set_change_level
(
&
mut
self
,
v
:
bool
)
{
unsafe
{
crocksdb_ffi
::
crocksdb_compactoptions_set_change_level
(
self
.inner
,
v
);
}
}
pub
fn
set_target_level
(
&
mut
self
,
v
:
i32
)
{
unsafe
{
crocksdb_ffi
::
crocksdb_compactoptions_set_target_level
(
self
.inner
,
v
);
}
}
}
impl
Drop
for
CompactOptions
{
...
...
tests/test_compact_range.rs
View file @
cb63dcd1
...
...
@@ -11,7 +11,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use
rocksdb
::{
DBOptions
,
Range
,
Writable
,
DB
};
use
rocksdb
::{
DBOptions
,
Range
,
Writable
,
DB
,
CompactOptions
,
ColumnFamilyOptions
};
use
tempdir
::
TempDir
;
...
...
@@ -45,3 +45,33 @@ fn test_compact_range() {
let
new_size
=
db
.get_approximate_sizes
(
&
[
Range
::
new
(
b
"k0"
,
b
"k6"
)])[
0
];
assert
!
(
old_size
>
new_size
);
}
#[test]
fn
test_compact_range_change_level
()
{
let
path
=
TempDir
::
new
(
"_rust_rocksdb_test_compact_range_change_level"
)
.expect
(
""
);
let
mut
opts
=
DBOptions
::
new
();
opts
.create_if_missing
(
true
);
let
mut
cf_opts
=
ColumnFamilyOptions
::
new
();
cf_opts
.set_level_zero_file_num_compaction_trigger
(
10
);
let
db
=
DB
::
open_cf
(
opts
,
path
.path
()
.to_str
()
.unwrap
(),
vec!
[(
"default"
,
cf_opts
)])
.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
();
db
.flush
(
true
)
.unwrap
();
}
let
compact_level
=
1
;
let
mut
compact_opts
=
CompactOptions
::
new
();
compact_opts
.set_change_level
(
true
);
compact_opts
.set_target_level
(
compact_level
);
let
handle
=
db
.cf_handle
(
"default"
)
.unwrap
();
db
.compact_range_cf_opt
(
handle
,
&
compact_opts
,
None
,
None
);
let
name
=
format!
(
"rocksdb.num-files-at-level{}"
,
compact_level
);
assert_eq!
(
db
.get_property_int
(
&
name
)
.unwrap
(),
samples
.len
()
as
u64
);
}
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