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
38ee726a
Commit
38ee726a
authored
Mar 28, 2017
by
siddontang
Committed by
GitHub
Mar 28, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support log ttl and add test (#33)
parent
714f3272
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
65 additions
and
4 deletions
+65
-4
lib.rs
librocksdb_sys/src/lib.rs
+14
-0
lib.rs
src/lib.rs
+1
-1
rocksdb_options.rs
src/rocksdb_options.rs
+13
-1
test_rocksdb_options.rs
tests/test_rocksdb_options.rs
+37
-2
No files found.
librocksdb_sys/src/lib.rs
View file @
38ee726a
...
...
@@ -134,6 +134,18 @@ pub enum DBStatisticsHistogramType {
DbSeekMicros
=
19
,
}
#[derive(Copy,
Clone)]
#[repr(C)]
pub
enum
DBInfoLogLevel
{
DBDebug
=
0
,
DBInfo
=
1
,
DBWarn
=
2
,
DBError
=
3
,
DBFatal
=
4
,
DBHeader
=
5
,
DBNumInfoLog
=
6
,
}
pub
fn
error_message
(
ptr
:
*
mut
c_char
)
->
String
{
let
c_str
=
unsafe
{
CStr
::
from_ptr
(
ptr
)
};
let
s
=
format!
(
"{}"
,
c_str
.to_string_lossy
());
...
...
@@ -223,6 +235,8 @@ extern "C" {
pub
fn
crocksdb_options_set_max_bytes_for_level_multiplier
(
options
:
*
mut
DBOptions
,
mul
:
c_int
);
pub
fn
crocksdb_options_set_max_log_file_size
(
options
:
*
mut
DBOptions
,
bytes
:
size_t
);
pub
fn
crocksdb_options_set_log_file_time_to_roll
(
options
:
*
mut
DBOptions
,
bytes
:
size_t
);
pub
fn
crocksdb_options_set_info_log_level
(
options
:
*
mut
DBOptions
,
level
:
DBInfoLogLevel
);
pub
fn
crocksdb_options_set_keep_log_file_num
(
options
:
*
mut
DBOptions
,
num
:
size_t
);
pub
fn
crocksdb_options_set_max_manifest_file_size
(
options
:
*
mut
DBOptions
,
bytes
:
u64
);
pub
fn
crocksdb_options_set_hash_skip_list_rep
(
options
:
*
mut
DBOptions
,
...
...
src/lib.rs
View file @
38ee726a
...
...
@@ -28,7 +28,7 @@ mod compaction_filter;
mod
slice_transform
;
pub
use
compaction_filter
::
CompactionFilter
;
pub
use
librocksdb_sys
::{
DBCompactionStyle
,
DBCompressionType
,
DBRecoveryMode
,
pub
use
librocksdb_sys
::{
DBCompactionStyle
,
DBCompressionType
,
DBRecoveryMode
,
DBInfoLogLevel
,
DBStatisticsTickerType
,
DBStatisticsHistogramType
,
new_bloom_filter
,
self
as
crocksdb_ffi
};
pub
use
merge_operator
::
MergeOperands
;
...
...
src/rocksdb_options.rs
View file @
38ee726a
...
...
@@ -19,7 +19,7 @@ use comparator::{self, ComparatorCallback, compare_callback};
use
crocksdb_ffi
::{
self
,
DBOptions
,
DBWriteOptions
,
DBBlockBasedTableOptions
,
DBReadOptions
,
DBRestoreOptions
,
DBCompressionType
,
DBRecoveryMode
,
DBSnapshot
,
DBInstance
,
DBFlushOptions
,
DBStatisticsTickerType
,
DBStatisticsHistogramType
,
DBRateLimiter
};
DBRateLimiter
,
DBInfoLogLevel
};
use
libc
::{
self
,
c_int
,
size_t
,
c_void
};
use
merge_operator
::{
self
,
MergeOperatorCallback
,
full_merge_callback
,
partial_merge_callback
};
use
merge_operator
::
MergeFn
;
...
...
@@ -677,6 +677,18 @@ impl Options {
}
}
pub
fn
set_log_file_time_to_roll
(
&
mut
self
,
ttl
:
u64
)
{
unsafe
{
crocksdb_ffi
::
crocksdb_options_set_log_file_time_to_roll
(
self
.inner
,
ttl
as
size_t
);
}
}
pub
fn
set_info_log_level
(
&
mut
self
,
level
:
DBInfoLogLevel
)
{
unsafe
{
crocksdb_ffi
::
crocksdb_options_set_info_log_level
(
self
.inner
,
level
);
}
}
pub
fn
set_keep_log_file_num
(
&
mut
self
,
num
:
u64
)
{
unsafe
{
crocksdb_ffi
::
crocksdb_options_set_keep_log_file_num
(
self
.inner
,
num
as
size_t
);
...
...
tests/test_rocksdb_options.rs
View file @
38ee726a
...
...
@@ -11,10 +11,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use
rocksdb
::{
DB
,
Options
,
BlockBasedOptions
,
WriteOptions
,
SliceTransform
};
use
rocksdb
::{
DB
,
Options
,
BlockBasedOptions
,
WriteOptions
,
SliceTransform
,
Writable
};
use
rocksdb
::
crocksdb_ffi
::{
DBStatisticsHistogramType
as
HistogramType
,
DBStatisticsTickerType
as
TickerType
};
DBStatisticsTickerType
as
TickerType
,
DBInfoLogLevel
as
InfoLogLevel
};
use
std
::
path
::
Path
;
use
std
::
thread
;
use
std
::
time
::
Duration
;
use
tempdir
::
TempDir
;
...
...
@@ -138,14 +140,47 @@ fn test_create_info_log() {
let
path
=
TempDir
::
new
(
"_rust_rocksdb_test_create_info_log_opt"
)
.expect
(
""
);
let
mut
opts
=
Options
::
new
();
opts
.create_if_missing
(
true
);
opts
.set_info_log_level
(
InfoLogLevel
::
DBDebug
);
opts
.set_log_file_time_to_roll
(
1
);
let
info_dir
=
TempDir
::
new
(
"_rust_rocksdb_test_info_log_dir"
)
.expect
(
""
);
opts
.create_info_log
(
info_dir
.path
()
.to_str
()
.unwrap
())
.unwrap
();
let
db
=
DB
::
open
(
opts
,
path
.path
()
.to_str
()
.unwrap
())
.unwrap
();
assert
!
(
Path
::
new
(
info_dir
.path
()
.join
(
"LOG"
)
.to_str
()
.unwrap
())
.is_file
());
thread
::
sleep
(
Duration
::
from_secs
(
2
));
for
i
in
0
..
200
{
db
.put
(
format!
(
"k_{}"
,
i
)
.as_bytes
(),
b
"v"
)
.unwrap
();
db
.flush
(
true
)
.unwrap
();
}
drop
(
db
);
// The LOG must be rolled many times.
let
count
=
info_dir
.path
()
.read_dir
()
.unwrap
()
.count
();
assert
!
(
count
>
1
);
}
#[test]
fn
test_auto_roll_max_size_info_log
()
{
let
path
=
TempDir
::
new
(
"_rust_rocksdb_test_max_size_info_log_opt"
)
.expect
(
""
);
let
mut
opts
=
Options
::
new
();
opts
.create_if_missing
(
true
);
opts
.set_max_log_file_size
(
10
);
let
info_dir
=
TempDir
::
new
(
"_rust_rocksdb_max_size_info_log_dir"
)
.expect
(
""
);
opts
.create_info_log
(
info_dir
.path
()
.to_str
()
.unwrap
())
.unwrap
();
let
db
=
DB
::
open
(
opts
,
path
.path
()
.to_str
()
.unwrap
())
.unwrap
();
assert
!
(
Path
::
new
(
info_dir
.path
()
.join
(
"LOG"
)
.to_str
()
.unwrap
())
.is_file
());
drop
(
db
);
// The LOG must be rolled many times.
let
count
=
info_dir
.path
()
.read_dir
()
.unwrap
()
.count
();
assert
!
(
count
>
1
);
}
#[test]
...
...
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