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
4dd1d667
Unverified
Commit
4dd1d667
authored
Nov 23, 2021
by
Xintao
Committed by
GitHub
Nov 23, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add LiveFiles and Resume public interface (#669)
Signed-off-by:
Xintao
<
hunterlxt@live.com
>
parent
06aa625e
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
104 additions
and
3 deletions
+104
-3
c.cc
librocksdb_sys/crocksdb/c.cc
+5
-1
c.h
librocksdb_sys/crocksdb/crocksdb/c.h
+3
-1
lib.rs
librocksdb_sys/src/lib.rs
+19
-0
metadata.rs
src/metadata.rs
+51
-1
rocksdb.rs
src/rocksdb.rs
+17
-0
test_metadata.rs
tests/cases/test_metadata.rs
+9
-0
No files found.
librocksdb_sys/crocksdb/c.cc
View file @
4dd1d667
...
@@ -742,6 +742,10 @@ void crocksdb_status_ptr_get_error(crocksdb_status_ptr_t* status,
...
@@ -742,6 +742,10 @@ void crocksdb_status_ptr_get_error(crocksdb_status_ptr_t* status,
SaveError
(
errptr
,
*
(
status
->
rep
));
SaveError
(
errptr
,
*
(
status
->
rep
));
}
}
void
crocksdb_resume
(
crocksdb_t
*
db
,
char
**
errptr
)
{
SaveError
(
errptr
,
db
->
rep
->
Resume
());
}
crocksdb_backup_engine_t
*
crocksdb_backup_engine_open
(
crocksdb_backup_engine_t
*
crocksdb_backup_engine_open
(
const
crocksdb_options_t
*
options
,
const
char
*
path
,
char
**
errptr
)
{
const
crocksdb_options_t
*
options
,
const
char
*
path
,
char
**
errptr
)
{
BackupEngine
*
be
;
BackupEngine
*
be
;
...
@@ -4741,7 +4745,7 @@ void crocksdb_options_set_min_level_to_compress(crocksdb_options_t* opt,
...
@@ -4741,7 +4745,7 @@ void crocksdb_options_set_min_level_to_compress(crocksdb_options_t* opt,
}
}
}
}
in
t
crocksdb_livefiles_count
(
const
crocksdb_livefiles_t
*
lf
)
{
size_
t
crocksdb_livefiles_count
(
const
crocksdb_livefiles_t
*
lf
)
{
return
static_cast
<
int
>
(
lf
->
rep
.
size
());
return
static_cast
<
int
>
(
lf
->
rep
.
size
());
}
}
...
...
librocksdb_sys/crocksdb/crocksdb/c.h
View file @
4dd1d667
...
@@ -240,6 +240,8 @@ extern C_ROCKSDB_LIBRARY_API crocksdb_t* crocksdb_open_for_read_only(
...
@@ -240,6 +240,8 @@ extern C_ROCKSDB_LIBRARY_API crocksdb_t* crocksdb_open_for_read_only(
extern
C_ROCKSDB_LIBRARY_API
void
crocksdb_status_ptr_get_error
(
extern
C_ROCKSDB_LIBRARY_API
void
crocksdb_status_ptr_get_error
(
crocksdb_status_ptr_t
*
,
char
**
errptr
);
crocksdb_status_ptr_t
*
,
char
**
errptr
);
extern
C_ROCKSDB_LIBRARY_API
void
rocksdb_resume
(
crocksdb_t
*
db
,
char
**
errptr
);
extern
C_ROCKSDB_LIBRARY_API
crocksdb_backup_engine_t
*
extern
C_ROCKSDB_LIBRARY_API
crocksdb_backup_engine_t
*
crocksdb_backup_engine_open
(
const
crocksdb_options_t
*
options
,
const
char
*
path
,
crocksdb_backup_engine_open
(
const
crocksdb_options_t
*
options
,
const
char
*
path
,
char
**
errptr
);
char
**
errptr
);
...
@@ -1882,7 +1884,7 @@ crocksdb_fifo_compaction_options_set_allow_compaction(
...
@@ -1882,7 +1884,7 @@ crocksdb_fifo_compaction_options_set_allow_compaction(
extern
C_ROCKSDB_LIBRARY_API
void
crocksdb_fifo_compaction_options_destroy
(
extern
C_ROCKSDB_LIBRARY_API
void
crocksdb_fifo_compaction_options_destroy
(
crocksdb_fifo_compaction_options_t
*
fifo_opts
);
crocksdb_fifo_compaction_options_t
*
fifo_opts
);
extern
C_ROCKSDB_LIBRARY_API
in
t
crocksdb_livefiles_count
(
extern
C_ROCKSDB_LIBRARY_API
size_
t
crocksdb_livefiles_count
(
const
crocksdb_livefiles_t
*
);
const
crocksdb_livefiles_t
*
);
extern
C_ROCKSDB_LIBRARY_API
const
char
*
crocksdb_livefiles_name
(
extern
C_ROCKSDB_LIBRARY_API
const
char
*
crocksdb_livefiles_name
(
const
crocksdb_livefiles_t
*
,
int
index
);
const
crocksdb_livefiles_t
*
,
int
index
);
...
...
librocksdb_sys/src/lib.rs
View file @
4dd1d667
...
@@ -43,6 +43,8 @@ use libc::{c_char, c_double, c_int, c_uchar, c_void, size_t};
...
@@ -43,6 +43,8 @@ use libc::{c_char, c_double, c_int, c_uchar, c_void, size_t};
// [1]: https://doc.rust-lang.org/nomicon/ffi.html#representing-opaque-structs
// [1]: https://doc.rust-lang.org/nomicon/ffi.html#representing-opaque-structs
// [2]: https://doc.rust-lang.org/nightly/src/core/ffi.rs.html#28
// [2]: https://doc.rust-lang.org/nightly/src/core/ffi.rs.html#28
#[repr(C)]
pub
struct
DBLivefiles
(
c_void
);
#[repr(C)]
#[repr(C)]
pub
struct
Options
(
c_void
);
pub
struct
Options
(
c_void
);
#[repr(C)]
#[repr(C)]
...
@@ -511,6 +513,7 @@ macro_rules! ffi_try {
...
@@ -511,6 +513,7 @@ macro_rules! ffi_try {
// instead...
// instead...
extern
"C"
{
extern
"C"
{
pub
fn
crocksdb_status_ptr_get_error
(
status
:
*
mut
DBStatusPtr
,
err
:
*
mut
*
mut
c_char
);
pub
fn
crocksdb_status_ptr_get_error
(
status
:
*
mut
DBStatusPtr
,
err
:
*
mut
*
mut
c_char
);
pub
fn
crocksdb_resume
(
db
:
*
mut
DBInstance
,
err
:
*
mut
*
mut
c_char
);
pub
fn
crocksdb_get_db_options
(
db
:
*
mut
DBInstance
)
->
*
mut
Options
;
pub
fn
crocksdb_get_db_options
(
db
:
*
mut
DBInstance
)
->
*
mut
Options
;
pub
fn
crocksdb_set_db_options
(
pub
fn
crocksdb_set_db_options
(
db
:
*
mut
DBInstance
,
db
:
*
mut
DBInstance
,
...
@@ -2308,6 +2311,22 @@ extern "C" {
...
@@ -2308,6 +2311,22 @@ extern "C" {
len
:
*
mut
size_t
,
len
:
*
mut
size_t
,
)
->
*
const
c_char
;
)
->
*
const
c_char
;
pub
fn
crocksdb_livefiles
(
db
:
*
mut
DBInstance
)
->
*
mut
DBLivefiles
;
pub
fn
crocksdb_livefiles_count
(
lf
:
*
const
DBLivefiles
)
->
size_t
;
pub
fn
crocksdb_livefiles_size
(
lf
:
*
const
DBLivefiles
,
index
:
i32
)
->
size_t
;
pub
fn
crocksdb_livefiles_name
(
lf
:
*
const
DBLivefiles
,
index
:
i32
)
->
*
const
c_char
;
pub
fn
crocksdb_livefiles_smallestkey
(
lf
:
*
const
DBLivefiles
,
index
:
i32
,
size
:
*
mut
size_t
,
)
->
*
const
c_char
;
pub
fn
crocksdb_livefiles_largestkey
(
lf
:
*
const
DBLivefiles
,
index
:
i32
,
size
:
*
mut
size_t
,
)
->
*
const
c_char
;
pub
fn
crocksdb_livefiles_destroy
(
lf
:
*
mut
DBLivefiles
);
pub
fn
crocksdb_compaction_options_create
()
->
*
mut
DBCompactionOptions
;
pub
fn
crocksdb_compaction_options_create
()
->
*
mut
DBCompactionOptions
;
pub
fn
crocksdb_compaction_options_destroy
(
opts
:
*
mut
DBCompactionOptions
);
pub
fn
crocksdb_compaction_options_destroy
(
opts
:
*
mut
DBCompactionOptions
);
pub
fn
crocksdb_compaction_options_set_compression
(
pub
fn
crocksdb_compaction_options_set_compression
(
...
...
src/metadata.rs
View file @
4dd1d667
...
@@ -11,7 +11,7 @@
...
@@ -11,7 +11,7 @@
// See the License for the specific language governing permissions and
// See the License for the specific language governing permissions and
// limitations under the License.
// limitations under the License.
use
crocksdb_ffi
::{
self
,
DBColumnFamilyMetaData
,
DBLevelMetaData
,
DBSstFileMetaData
};
use
crocksdb_ffi
::{
self
,
DBColumnFamilyMetaData
,
DBLevelMetaData
,
DB
Livefiles
,
DB
SstFileMetaData
};
use
std
::
ffi
::
CStr
;
use
std
::
ffi
::
CStr
;
use
std
::
slice
;
use
std
::
slice
;
...
@@ -120,3 +120,53 @@ impl<'a> SstFileMetaData<'a> {
...
@@ -120,3 +120,53 @@ impl<'a> SstFileMetaData<'a> {
}
}
}
}
}
}
pub
struct
LiveFiles
{
inner
:
*
mut
DBLivefiles
,
}
impl
LiveFiles
{
pub
fn
from_ptr
(
inner
:
*
mut
DBLivefiles
)
->
LiveFiles
{
LiveFiles
{
inner
:
inner
}
}
pub
fn
get_files_count
(
&
self
)
->
usize
{
unsafe
{
crocksdb_ffi
::
crocksdb_livefiles_count
(
self
.inner
)
}
}
#[allow(dead_code)]
pub
fn
get_size
(
&
self
,
index
:
i32
)
->
usize
{
unsafe
{
crocksdb_ffi
::
crocksdb_livefiles_size
(
self
.inner
,
index
)
}
}
pub
fn
get_name
(
&
self
,
index
:
i32
)
->
String
{
unsafe
{
let
ptr
=
crocksdb_ffi
::
crocksdb_livefiles_name
(
self
.inner
,
index
);
CStr
::
from_ptr
(
ptr
)
.to_string_lossy
()
.into_owned
()
}
}
pub
fn
get_smallestkey
(
&
self
,
index
:
i32
)
->
&
[
u8
]
{
let
mut
len
:
size_t
=
0
;
unsafe
{
let
ptr
=
crocksdb_ffi
::
crocksdb_livefiles_smallestkey
(
self
.inner
,
index
,
&
mut
len
);
slice
::
from_raw_parts
(
ptr
as
*
const
u8
,
len
)
}
}
pub
fn
get_largestkey
(
&
self
,
index
:
i32
)
->
&
[
u8
]
{
let
mut
len
:
size_t
=
0
;
unsafe
{
let
ptr
=
crocksdb_ffi
::
crocksdb_livefiles_largestkey
(
self
.inner
,
index
,
&
mut
len
);
slice
::
from_raw_parts
(
ptr
as
*
const
u8
,
len
)
}
}
}
impl
Drop
for
LiveFiles
{
fn
drop
(
&
mut
self
)
{
unsafe
{
crocksdb_ffi
::
crocksdb_livefiles_destroy
(
self
.inner
);
}
}
}
src/rocksdb.rs
View file @
4dd1d667
...
@@ -46,6 +46,8 @@ use table_properties_rc::TablePropertiesCollection as RcTablePropertiesCollectio
...
@@ -46,6 +46,8 @@ use table_properties_rc::TablePropertiesCollection as RcTablePropertiesCollectio
use
titan
::
TitanDBOptions
;
use
titan
::
TitanDBOptions
;
use
write_batch
::
WriteBatch
;
use
write_batch
::
WriteBatch
;
use
crate
::
metadata
::
LiveFiles
;
pub
struct
CFHandle
{
pub
struct
CFHandle
{
inner
:
*
mut
DBCFHandle
,
inner
:
*
mut
DBCFHandle
,
}
}
...
@@ -1214,6 +1216,14 @@ impl DB {
...
@@ -1214,6 +1216,14 @@ impl DB {
}
}
}
}
/// Ref https://github.com/facebook/rocksdb/wiki/Background-Error-Handling#recovery
pub
fn
resume
(
&
self
)
->
Result
<
(),
String
>
{
unsafe
{
ffi_try!
(
crocksdb_resume
(
self
.inner
));
Ok
(())
}
}
/// Get the sequence number of the most recent transaction.
/// Get the sequence number of the most recent transaction.
pub
fn
get_latest_sequence_number
(
&
self
)
->
u64
{
pub
fn
get_latest_sequence_number
(
&
self
)
->
u64
{
unsafe
{
crocksdb_ffi
::
crocksdb_get_latest_sequence_number
(
self
.inner
)
}
unsafe
{
crocksdb_ffi
::
crocksdb_get_latest_sequence_number
(
self
.inner
)
}
...
@@ -1952,6 +1962,13 @@ impl DB {
...
@@ -1952,6 +1962,13 @@ impl DB {
}
}
}
}
pub
fn
get_live_files
(
&
self
)
->
LiveFiles
{
unsafe
{
let
inner
=
crocksdb_ffi
::
crocksdb_livefiles
(
self
.inner
);
LiveFiles
::
from_ptr
(
inner
)
}
}
pub
fn
compact_files_cf
(
pub
fn
compact_files_cf
(
&
self
,
&
self
,
cf
:
&
CFHandle
,
cf
:
&
CFHandle
,
...
...
tests/cases/test_metadata.rs
View file @
4dd1d667
...
@@ -38,6 +38,15 @@ fn test_metadata() {
...
@@ -38,6 +38,15 @@ fn test_metadata() {
db
.flush
(
true
)
.unwrap
();
db
.flush
(
true
)
.unwrap
();
}
}
let
live_files
=
db
.get_live_files
();
let
files_count
=
live_files
.get_files_count
();
assert_eq!
(
files_count
as
u8
,
num_files
);
for
i
in
0
..
files_count
as
i32
{
assert
!
(
live_files
.get_name
(
i
)
.len
()
>
0
);
assert_eq!
(
live_files
.get_smallestkey
(
i
),
[
num_files
-
1
-
i
as
u8
]);
assert_eq!
(
live_files
.get_largestkey
(
i
),
[
num_files
-
1
-
i
as
u8
]);
}
let
cf_meta
=
db
.get_column_family_meta_data
(
cf_handle
);
let
cf_meta
=
db
.get_column_family_meta_data
(
cf_handle
);
let
cf_levels
=
cf_meta
.get_levels
();
let
cf_levels
=
cf_meta
.get_levels
();
assert_eq!
(
cf_levels
.len
(),
7
);
assert_eq!
(
cf_levels
.len
(),
7
);
...
...
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