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
fe19e2b5
Unverified
Commit
fe19e2b5
authored
Sep 16, 2021
by
Qi Yu
Committed by
GitHub
Sep 16, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reduce boxing in callback structs (#663)
Close #513. Signed-off-by:
yuqi1129
<
yuqi4733@gmail.com
>
parent
0d2028ff
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
151 additions
and
142 deletions
+151
-142
lib.rs
librocksdb_sys/src/lib.rs
+1
-1
event_listener.rs
src/event_listener.rs
+46
-73
logger.rs
src/logger.rs
+7
-7
rocksdb_options.rs
src/rocksdb_options.rs
+9
-5
table_filter.rs
src/table_filter.rs
+7
-4
table_properties_collector.rs
src/table_properties_collector.rs
+21
-18
table_properties_collector_factory.rs
src/table_properties_collector_factory.rs
+37
-21
test_table_properties.rs
tests/cases/test_table_properties.rs
+12
-7
test_titan.rs
tests/cases/test_titan.rs
+11
-6
No files found.
librocksdb_sys/src/lib.rs
View file @
fe19e2b5
...
@@ -2733,7 +2733,7 @@ mod test {
...
@@ -2733,7 +2733,7 @@ mod test {
use
std
::{
fs
,
ptr
,
slice
};
use
std
::{
fs
,
ptr
,
slice
};
fn
tempdir_with_prefix
(
prefix
:
&
str
)
->
tempfile
::
TempDir
{
fn
tempdir_with_prefix
(
prefix
:
&
str
)
->
tempfile
::
TempDir
{
tempfile
::
Builder
::
new
()
.prefix
(
prefix
)
.tempdir
()
.expect
()
tempfile
::
Builder
::
new
()
.prefix
(
prefix
)
.tempdir
()
.expect
(
""
)
}
}
#[test]
#[test]
...
...
src/event_listener.rs
View file @
fe19e2b5
...
@@ -229,108 +229,83 @@ pub trait EventListener: Send + Sync {
...
@@ -229,108 +229,83 @@ pub trait EventListener: Send + Sync {
fn
on_stall_conditions_changed
(
&
self
,
_
:
&
WriteStallInfo
)
{}
fn
on_stall_conditions_changed
(
&
self
,
_
:
&
WriteStallInfo
)
{}
}
}
extern
"C"
fn
destructor
(
ctx
:
*
mut
c_void
)
{
extern
"C"
fn
destructor
<
E
:
EventListener
>
(
ctx
:
*
mut
c_void
)
{
unsafe
{
unsafe
{
Box
::
from_raw
(
ctx
as
*
mut
Box
<
dyn
EventListener
>
);
Box
::
from_raw
(
ctx
as
*
mut
E
);
}
}
}
}
// Maybe we should reuse db instance?
// Maybe we should reuse db instance?
// TODO: refactor DB implement so that we can convert DBInstance to DB.
// TODO: refactor DB implement so that we can convert DBInstance to DB.
extern
"C"
fn
on_flush_begin
(
ctx
:
*
mut
c_void
,
_
:
*
mut
DBInstance
,
info
:
*
const
DBFlushJobInfo
)
{
extern
"C"
fn
on_flush_begin
<
E
:
EventListener
>
(
let
(
ctx
,
info
)
=
unsafe
{
ctx
:
*
mut
c_void
,
(
_
:
*
mut
DBInstance
,
&*
(
ctx
as
*
mut
Box
<
dyn
EventListener
>
),
info
:
*
const
DBFlushJobInfo
,
&*
(
info
as
*
const
FlushJobInfo
),
)
{
)
let
(
ctx
,
info
)
=
unsafe
{
(
&*
(
ctx
as
*
mut
E
),
&*
(
info
as
*
const
FlushJobInfo
))
};
};
ctx
.on_flush_begin
(
info
);
ctx
.on_flush_begin
(
info
);
}
}
extern
"C"
fn
on_flush_completed
(
extern
"C"
fn
on_flush_completed
<
E
:
EventListener
>
(
ctx
:
*
mut
c_void
,
ctx
:
*
mut
c_void
,
_
:
*
mut
DBInstance
,
_
:
*
mut
DBInstance
,
info
:
*
const
DBFlushJobInfo
,
info
:
*
const
DBFlushJobInfo
,
)
{
)
{
let
(
ctx
,
info
)
=
unsafe
{
let
(
ctx
,
info
)
=
unsafe
{
(
&*
(
ctx
as
*
mut
E
),
&*
(
info
as
*
const
FlushJobInfo
))
};
(
&*
(
ctx
as
*
mut
Box
<
dyn
EventListener
>
),
&*
(
info
as
*
const
FlushJobInfo
),
)
};
ctx
.on_flush_completed
(
info
);
ctx
.on_flush_completed
(
info
);
}
}
extern
"C"
fn
on_compaction_begin
(
extern
"C"
fn
on_compaction_begin
<
E
:
EventListener
>
(
ctx
:
*
mut
c_void
,
ctx
:
*
mut
c_void
,
_
:
*
mut
DBInstance
,
_
:
*
mut
DBInstance
,
info
:
*
const
DBCompactionJobInfo
,
info
:
*
const
DBCompactionJobInfo
,
)
{
)
{
let
(
ctx
,
info
)
=
unsafe
{
let
(
ctx
,
info
)
=
unsafe
{
(
&*
(
ctx
as
*
mut
E
),
&*
(
info
as
*
const
CompactionJobInfo
))
};
(
&*
(
ctx
as
*
mut
Box
<
dyn
EventListener
>
),
&*
(
info
as
*
const
CompactionJobInfo
),
)
};
ctx
.on_compaction_begin
(
info
);
ctx
.on_compaction_begin
(
info
);
}
}
extern
"C"
fn
on_compaction_completed
(
extern
"C"
fn
on_compaction_completed
<
E
:
EventListener
>
(
ctx
:
*
mut
c_void
,
ctx
:
*
mut
c_void
,
_
:
*
mut
DBInstance
,
_
:
*
mut
DBInstance
,
info
:
*
const
DBCompactionJobInfo
,
info
:
*
const
DBCompactionJobInfo
,
)
{
)
{
let
(
ctx
,
info
)
=
unsafe
{
let
(
ctx
,
info
)
=
unsafe
{
(
&*
(
ctx
as
*
mut
E
),
&*
(
info
as
*
const
CompactionJobInfo
))
};
(
&*
(
ctx
as
*
mut
Box
<
dyn
EventListener
>
),
&*
(
info
as
*
const
CompactionJobInfo
),
)
};
ctx
.on_compaction_completed
(
info
);
ctx
.on_compaction_completed
(
info
);
}
}
extern
"C"
fn
on_subcompaction_begin
(
ctx
:
*
mut
c_void
,
info
:
*
const
DBSubcompactionJobInfo
)
{
extern
"C"
fn
on_subcompaction_begin
<
E
:
EventListener
>
(
let
(
ctx
,
info
)
=
unsafe
{
ctx
:
*
mut
c_void
,
(
info
:
*
const
DBSubcompactionJobInfo
,
&*
(
ctx
as
*
mut
Box
<
dyn
EventListener
>
),
)
{
&*
(
info
as
*
const
SubcompactionJobInfo
),
let
(
ctx
,
info
)
=
unsafe
{
(
&*
(
ctx
as
*
mut
E
),
&*
(
info
as
*
const
SubcompactionJobInfo
))
};
)
};
ctx
.on_subcompaction_begin
(
info
);
ctx
.on_subcompaction_begin
(
info
);
}
}
extern
"C"
fn
on_subcompaction_completed
(
ctx
:
*
mut
c_void
,
info
:
*
const
DBSubcompactionJobInfo
)
{
extern
"C"
fn
on_subcompaction_completed
<
E
:
EventListener
>
(
let
(
ctx
,
info
)
=
unsafe
{
ctx
:
*
mut
c_void
,
(
info
:
*
const
DBSubcompactionJobInfo
,
&*
(
ctx
as
*
mut
Box
<
dyn
EventListener
>
),
)
{
&*
(
info
as
*
const
SubcompactionJobInfo
),
let
(
ctx
,
info
)
=
unsafe
{
(
&*
(
ctx
as
*
mut
E
),
&*
(
info
as
*
const
SubcompactionJobInfo
))
};
)
};
ctx
.on_subcompaction_completed
(
info
);
ctx
.on_subcompaction_completed
(
info
);
}
}
extern
"C"
fn
on_external_file_ingested
(
extern
"C"
fn
on_external_file_ingested
<
E
:
EventListener
>
(
ctx
:
*
mut
c_void
,
ctx
:
*
mut
c_void
,
_
:
*
mut
DBInstance
,
_
:
*
mut
DBInstance
,
info
:
*
const
DBIngestionInfo
,
info
:
*
const
DBIngestionInfo
,
)
{
)
{
let
(
ctx
,
info
)
=
unsafe
{
let
(
ctx
,
info
)
=
unsafe
{
(
&*
(
ctx
as
*
mut
E
),
&*
(
info
as
*
const
IngestionInfo
))
};
(
&*
(
ctx
as
*
mut
Box
<
dyn
EventListener
>
),
&*
(
info
as
*
const
IngestionInfo
),
)
};
ctx
.on_external_file_ingested
(
info
);
ctx
.on_external_file_ingested
(
info
);
}
}
extern
"C"
fn
on_background_error
(
extern
"C"
fn
on_background_error
<
E
:
EventListener
>
(
ctx
:
*
mut
c_void
,
ctx
:
*
mut
c_void
,
reason
:
DBBackgroundErrorReason
,
reason
:
DBBackgroundErrorReason
,
status
:
*
mut
DBStatusPtr
,
status
:
*
mut
DBStatusPtr
,
)
{
)
{
let
(
ctx
,
result
)
=
unsafe
{
let
(
ctx
,
result
)
=
unsafe
{
(
(
&*
(
ctx
as
*
mut
Box
<
dyn
EventListener
>
),
&*
(
ctx
as
*
mut
E
),
||
->
Result
<
(),
String
>
{
||
->
Result
<
(),
String
>
{
ffi_try!
(
crocksdb_status_ptr_get_error
(
status
));
ffi_try!
(
crocksdb_status_ptr_get_error
(
status
));
Ok
(())
Ok
(())
...
@@ -340,31 +315,29 @@ extern "C" fn on_background_error(
...
@@ -340,31 +315,29 @@ extern "C" fn on_background_error(
ctx
.on_background_error
(
reason
,
result
);
ctx
.on_background_error
(
reason
,
result
);
}
}
extern
"C"
fn
on_stall_conditions_changed
(
ctx
:
*
mut
c_void
,
info
:
*
const
DBWriteStallInfo
)
{
extern
"C"
fn
on_stall_conditions_changed
<
E
:
EventListener
>
(
let
(
ctx
,
info
)
=
unsafe
{
ctx
:
*
mut
c_void
,
(
info
:
*
const
DBWriteStallInfo
,
&*
(
ctx
as
*
mut
Box
<
dyn
EventListener
>
),
)
{
&*
(
info
as
*
const
WriteStallInfo
),
let
(
ctx
,
info
)
=
unsafe
{
(
&*
(
ctx
as
*
mut
E
),
&*
(
info
as
*
const
WriteStallInfo
))
};
)
};
ctx
.on_stall_conditions_changed
(
info
);
ctx
.on_stall_conditions_changed
(
info
);
}
}
pub
fn
new_event_listener
<
L
:
EventListener
>
(
l
:
L
)
->
*
mut
DBEventListener
{
pub
fn
new_event_listener
<
E
:
EventListener
>
(
e
:
E
)
->
*
mut
DBEventListener
{
let
p
:
Box
<
dyn
EventListener
>
=
Box
::
new
(
l
);
let
p
:
Box
<
dyn
EventListener
>
=
Box
::
new
(
e
);
unsafe
{
unsafe
{
crocksdb_ffi
::
crocksdb_eventlistener_create
(
crocksdb_ffi
::
crocksdb_eventlistener_create
(
Box
::
into_raw
(
Box
::
new
(
p
)
)
as
*
mut
c_void
,
Box
::
into_raw
(
p
)
as
*
mut
c_void
,
destructor
,
destructor
::
<
E
>
,
on_flush_begin
,
on_flush_begin
::
<
E
>
,
on_flush_completed
,
on_flush_completed
::
<
E
>
,
on_compaction_begin
,
on_compaction_begin
::
<
E
>
,
on_compaction_completed
,
on_compaction_completed
::
<
E
>
,
on_subcompaction_begin
,
on_subcompaction_begin
::
<
E
>
,
on_subcompaction_completed
,
on_subcompaction_completed
::
<
E
>
,
on_external_file_ingested
,
on_external_file_ingested
::
<
E
>
,
on_background_error
,
on_background_error
::
<
E
>
,
on_stall_conditions_changed
,
on_stall_conditions_changed
::
<
E
>
,
)
)
}
}
}
}
src/logger.rs
View file @
fe19e2b5
...
@@ -10,15 +10,15 @@ pub trait Logger: Send + Sync {
...
@@ -10,15 +10,15 @@ pub trait Logger: Send + Sync {
fn
logv
(
&
self
,
log_level
:
InfoLogLevel
,
log
:
&
str
);
fn
logv
(
&
self
,
log_level
:
InfoLogLevel
,
log
:
&
str
);
}
}
extern
"C"
fn
destructor
(
ctx
:
*
mut
c_void
)
{
extern
"C"
fn
destructor
<
L
:
Logger
>
(
ctx
:
*
mut
c_void
)
{
unsafe
{
unsafe
{
Box
::
from_raw
(
ctx
as
*
mut
Box
<
dyn
Logger
>
);
Box
::
from_raw
(
ctx
as
*
mut
L
);
}
}
}
}
extern
"C"
fn
logv
(
ctx
:
*
mut
c_void
,
log_level
:
InfoLogLevel
,
log
:
*
const
c_char
)
{
extern
"C"
fn
logv
<
L
:
Logger
>
(
ctx
:
*
mut
c_void
,
log_level
:
InfoLogLevel
,
log
:
*
const
c_char
)
{
unsafe
{
unsafe
{
let
logger
=
&*
(
ctx
as
*
mut
Box
<
dyn
Logger
>
);
let
logger
=
&*
(
ctx
as
*
mut
L
);
let
log
=
CStr
::
from_ptr
(
log
);
let
log
=
CStr
::
from_ptr
(
log
);
logger
.logv
(
log_level
,
&
log
.to_string_lossy
());
logger
.logv
(
log_level
,
&
log
.to_string_lossy
());
}
}
...
@@ -28,9 +28,9 @@ pub fn new_logger<L: Logger>(l: L) -> *mut DBLogger {
...
@@ -28,9 +28,9 @@ pub fn new_logger<L: Logger>(l: L) -> *mut DBLogger {
unsafe
{
unsafe
{
let
p
:
Box
<
dyn
Logger
>
=
Box
::
new
(
l
);
let
p
:
Box
<
dyn
Logger
>
=
Box
::
new
(
l
);
crocksdb_ffi
::
crocksdb_logger_create
(
crocksdb_ffi
::
crocksdb_logger_create
(
Box
::
into_raw
(
Box
::
new
(
p
)
)
as
*
mut
c_void
,
Box
::
into_raw
(
p
)
as
*
mut
c_void
,
destructor
,
destructor
::
<
L
>
,
logv
,
logv
::
<
L
>
,
)
)
}
}
}
}
...
...
src/rocksdb_options.rs
View file @
fe19e2b5
...
@@ -44,6 +44,7 @@ use table_properties_collector_factory::{
...
@@ -44,6 +44,7 @@ use table_properties_collector_factory::{
new_table_properties_collector_factory
,
TablePropertiesCollectorFactory
,
new_table_properties_collector_factory
,
TablePropertiesCollectorFactory
,
};
};
use
titan
::
TitanDBOptions
;
use
titan
::
TitanDBOptions
;
use
TablePropertiesCollector
;
#[derive(Default,
Debug)]
#[derive(Default,
Debug)]
pub
struct
HistogramData
{
pub
struct
HistogramData
{
...
@@ -474,15 +475,15 @@ impl ReadOptions {
...
@@ -474,15 +475,15 @@ impl ReadOptions {
}
}
}
}
pub
fn
set_table_filter
(
&
mut
self
,
filter
:
Box
<
dyn
TableFilter
>
)
{
pub
fn
set_table_filter
<
T
:
TableFilter
>
(
&
mut
self
,
filter
:
T
)
{
unsafe
{
unsafe
{
let
f
=
Box
::
into_raw
(
Box
::
new
(
filter
));
let
f
=
Box
::
into_raw
(
Box
::
new
(
filter
));
let
f
=
f
as
*
mut
c_void
;
let
f
=
f
as
*
mut
c_void
;
crocksdb_ffi
::
crocksdb_readoptions_set_table_filter
(
crocksdb_ffi
::
crocksdb_readoptions_set_table_filter
(
self
.inner
,
self
.inner
,
f
,
f
,
table_filter
,
table_filter
::
<
T
>
,
destroy_table_filter
,
destroy_table_filter
::
<
T
>
,
);
);
}
}
}
}
...
@@ -1429,10 +1430,13 @@ impl ColumnFamilyOptions {
...
@@ -1429,10 +1430,13 @@ impl ColumnFamilyOptions {
}
}
}
}
pub
fn
add_table_properties_collector_factory
(
pub
fn
add_table_properties_collector_factory
<
C
:
TablePropertiesCollector
,
T
:
TablePropertiesCollectorFactory
<
C
>
,
>
(
&
mut
self
,
&
mut
self
,
fname
:
&
str
,
fname
:
&
str
,
factory
:
Box
<
dyn
TablePropertiesCollectorFactory
>
,
factory
:
T
,
)
{
)
{
unsafe
{
unsafe
{
let
f
=
new_table_properties_collector_factory
(
fname
,
factory
);
let
f
=
new_table_properties_collector_factory
(
fname
,
factory
);
...
...
src/table_filter.rs
View file @
fe19e2b5
...
@@ -24,16 +24,19 @@ pub trait TableFilter {
...
@@ -24,16 +24,19 @@ pub trait TableFilter {
fn
table_filter
(
&
self
,
props
:
&
TableProperties
)
->
bool
;
fn
table_filter
(
&
self
,
props
:
&
TableProperties
)
->
bool
;
}
}
pub
extern
"C"
fn
table_filter
(
ctx
:
*
mut
c_void
,
props
:
*
const
DBTableProperties
)
->
c_uchar
{
pub
extern
"C"
fn
table_filter
<
T
:
TableFilter
>
(
ctx
:
*
mut
c_void
,
props
:
*
const
DBTableProperties
,
)
->
c_uchar
{
unsafe
{
unsafe
{
let
filter
=
&*
(
ctx
as
*
mut
Box
<
dyn
TableFilter
>
);
let
filter
=
&*
(
ctx
as
*
mut
T
);
let
props
=
&*
(
props
as
*
const
TableProperties
);
let
props
=
&*
(
props
as
*
const
TableProperties
);
filter
.table_filter
(
props
)
as
c_uchar
filter
.table_filter
(
props
)
as
c_uchar
}
}
}
}
pub
extern
"C"
fn
destroy_table_filter
(
filter
:
*
mut
c_void
)
{
pub
extern
"C"
fn
destroy_table_filter
<
T
:
TableFilter
>
(
filter
:
*
mut
c_void
)
{
unsafe
{
unsafe
{
Box
::
from_raw
(
filter
as
*
mut
Box
<
dyn
TableFilter
>
);
Box
::
from_raw
(
filter
as
*
mut
T
);
}
}
}
}
src/table_properties_collector.rs
View file @
fe19e2b5
...
@@ -33,13 +33,13 @@ pub trait TablePropertiesCollector {
...
@@ -33,13 +33,13 @@ pub trait TablePropertiesCollector {
fn
finish
(
&
mut
self
)
->
HashMap
<
Vec
<
u8
>
,
Vec
<
u8
>>
;
fn
finish
(
&
mut
self
)
->
HashMap
<
Vec
<
u8
>
,
Vec
<
u8
>>
;
}
}
struct
TablePropertiesCollectorHandle
{
struct
TablePropertiesCollectorHandle
<
T
:
TablePropertiesCollector
>
{
name
:
CString
,
name
:
CString
,
rep
:
Box
<
dyn
TablePropertiesCollector
>
,
rep
:
T
,
}
}
impl
TablePropertiesCollectorHandle
{
impl
<
T
:
TablePropertiesCollector
>
TablePropertiesCollectorHandle
<
T
>
{
fn
new
(
name
:
&
str
,
rep
:
Box
<
dyn
TablePropertiesCollector
>
)
->
TablePropertiesCollectorHandle
{
fn
new
(
name
:
&
str
,
rep
:
T
)
->
TablePropertiesCollectorHandle
<
T
>
{
TablePropertiesCollectorHandle
{
TablePropertiesCollectorHandle
{
name
:
CString
::
new
(
name
)
.unwrap
(),
name
:
CString
::
new
(
name
)
.unwrap
(),
rep
:
rep
,
rep
:
rep
,
...
@@ -47,20 +47,20 @@ impl TablePropertiesCollectorHandle {
...
@@ -47,20 +47,20 @@ impl TablePropertiesCollectorHandle {
}
}
}
}
extern
"C"
fn
name
(
handle
:
*
mut
c_void
)
->
*
const
c_char
{
extern
"C"
fn
name
<
T
:
TablePropertiesCollector
>
(
handle
:
*
mut
c_void
)
->
*
const
c_char
{
unsafe
{
unsafe
{
let
handle
=
&
mut
*
(
handle
as
*
mut
TablePropertiesCollectorHandle
);
let
handle
=
&
mut
*
(
handle
as
*
mut
TablePropertiesCollectorHandle
<
T
>
);
handle
.name
.as_ptr
()
handle
.name
.as_ptr
()
}
}
}
}
extern
"C"
fn
destruct
(
handle
:
*
mut
c_void
)
{
extern
"C"
fn
destruct
<
T
:
TablePropertiesCollector
>
(
handle
:
*
mut
c_void
)
{
unsafe
{
unsafe
{
Box
::
from_raw
(
handle
as
*
mut
TablePropertiesCollectorHandle
);
Box
::
from_raw
(
handle
as
*
mut
TablePropertiesCollectorHandle
<
T
>
);
}
}
}
}
pub
extern
"C"
fn
add
(
pub
extern
"C"
fn
add
<
T
:
TablePropertiesCollector
>
(
handle
:
*
mut
c_void
,
handle
:
*
mut
c_void
,
key
:
*
const
u8
,
key
:
*
const
u8
,
key_len
:
size_t
,
key_len
:
size_t
,
...
@@ -71,7 +71,7 @@ pub extern "C" fn add(
...
@@ -71,7 +71,7 @@ pub extern "C" fn add(
file_size
:
u64
,
file_size
:
u64
,
)
{
)
{
unsafe
{
unsafe
{
let
handle
=
&
mut
*
(
handle
as
*
mut
TablePropertiesCollectorHandle
);
let
handle
=
&
mut
*
(
handle
as
*
mut
TablePropertiesCollectorHandle
<
T
>
);
let
key
=
slice
::
from_raw_parts
(
key
,
key_len
);
let
key
=
slice
::
from_raw_parts
(
key
,
key_len
);
let
value
=
slice
::
from_raw_parts
(
value
,
value_len
);
let
value
=
slice
::
from_raw_parts
(
value
,
value_len
);
handle
handle
...
@@ -80,9 +80,12 @@ pub extern "C" fn add(
...
@@ -80,9 +80,12 @@ pub extern "C" fn add(
}
}
}
}
pub
extern
"C"
fn
finish
(
handle
:
*
mut
c_void
,
props
:
*
mut
DBUserCollectedProperties
)
{
pub
extern
"C"
fn
finish
<
T
:
TablePropertiesCollector
>
(
handle
:
*
mut
c_void
,
props
:
*
mut
DBUserCollectedProperties
,
)
{
unsafe
{
unsafe
{
let
handle
=
&
mut
*
(
handle
as
*
mut
TablePropertiesCollectorHandle
);
let
handle
=
&
mut
*
(
handle
as
*
mut
TablePropertiesCollectorHandle
<
T
>
);
for
(
key
,
value
)
in
handle
.rep
.finish
()
{
for
(
key
,
value
)
in
handle
.rep
.finish
()
{
crocksdb_ffi
::
crocksdb_user_collected_properties_add
(
crocksdb_ffi
::
crocksdb_user_collected_properties_add
(
props
,
props
,
...
@@ -95,16 +98,16 @@ pub extern "C" fn finish(handle: *mut c_void, props: *mut DBUserCollectedPropert
...
@@ -95,16 +98,16 @@ pub extern "C" fn finish(handle: *mut c_void, props: *mut DBUserCollectedPropert
}
}
}
}
pub
unsafe
fn
new_table_properties_collector
(
pub
unsafe
fn
new_table_properties_collector
<
T
:
TablePropertiesCollector
>
(
cname
:
&
str
,
cname
:
&
str
,
collector
:
Box
<
dyn
TablePropertiesCollector
>
,
collector
:
T
,
)
->
*
mut
DBTablePropertiesCollector
{
)
->
*
mut
DBTablePropertiesCollector
{
let
handle
=
TablePropertiesCollectorHandle
::
new
(
cname
,
collector
);
let
handle
=
TablePropertiesCollectorHandle
::
new
(
cname
,
collector
);
crocksdb_ffi
::
crocksdb_table_properties_collector_create
(
crocksdb_ffi
::
crocksdb_table_properties_collector_create
(
Box
::
into_raw
(
Box
::
new
(
handle
))
as
*
mut
c_void
,
Box
::
into_raw
(
Box
::
new
(
handle
))
as
*
mut
c_void
,
name
,
name
::
<
T
>
,
destruct
,
destruct
::
<
T
>
,
add
,
add
::
<
T
>
,
finish
,
finish
::
<
T
>
,
)
)
}
}
src/table_properties_collector_factory.rs
View file @
fe19e2b5
...
@@ -14,65 +14,81 @@
...
@@ -14,65 +14,81 @@
use
crocksdb_ffi
::{
self
,
DBTablePropertiesCollector
,
DBTablePropertiesCollectorFactory
};
use
crocksdb_ffi
::{
self
,
DBTablePropertiesCollector
,
DBTablePropertiesCollectorFactory
};
use
libc
::{
c_char
,
c_void
};
use
libc
::{
c_char
,
c_void
};
use
std
::
ffi
::
CString
;
use
std
::
ffi
::
CString
;
use
std
::
marker
::
PhantomData
;
use
table_properties_collector
::{
new_table_properties_collector
,
TablePropertiesCollector
};
use
table_properties_collector
::{
new_table_properties_collector
,
TablePropertiesCollector
};
/// Constructs `TablePropertiesCollector`.
/// Constructs `TablePropertiesCollector`.
/// Internals create a new `TablePropertiesCollector` for each new table.
/// Internals create a new `TablePropertiesCollector` for each new table.
pub
trait
TablePropertiesCollectorFactory
{
pub
trait
TablePropertiesCollectorFactory
<
T
:
TablePropertiesCollector
>
{
/// Has to be thread-safe.
/// Has to be thread-safe.
fn
create_table_properties_collector
(
&
mut
self
,
cf
:
u32
)
->
Box
<
dyn
TablePropertiesCollector
>
;
fn
create_table_properties_collector
(
&
mut
self
,
cf
:
u32
)
->
T
;
}
}
struct
TablePropertiesCollectorFactoryHandle
{
struct
TablePropertiesCollectorFactoryHandle
<
C
,
T
>
where
C
:
TablePropertiesCollector
,
T
:
TablePropertiesCollectorFactory
<
C
>
,
{
name
:
CString
,
name
:
CString
,
rep
:
Box
<
dyn
TablePropertiesCollectorFactory
>
,
rep
:
T
,
_phantom
:
PhantomData
<
C
>
,
}
}
impl
TablePropertiesCollectorFactoryHandle
{
impl
<
C
:
TablePropertiesCollector
,
T
:
TablePropertiesCollectorFactory
<
C
>>
fn
new
(
TablePropertiesCollectorFactoryHandle
<
C
,
T
>
name
:
&
str
,
{
rep
:
Box
<
dyn
TablePropertiesCollectorFactory
>
,
fn
new
(
name
:
&
str
,
rep
:
T
)
->
TablePropertiesCollectorFactoryHandle
<
C
,
T
>
{
)
->
TablePropertiesCollectorFactoryHandle
{
TablePropertiesCollectorFactoryHandle
::
<
C
,
T
>
{
TablePropertiesCollectorFactoryHandle
{
name
:
CString
::
new
(
name
)
.unwrap
(),
name
:
CString
::
new
(
name
)
.unwrap
(),
rep
:
rep
,
rep
:
rep
,
_phantom
:
PhantomData
,
}
}
}
}
}
}
extern
"C"
fn
name
(
handle
:
*
mut
c_void
)
->
*
const
c_char
{
extern
"C"
fn
name
<
C
:
TablePropertiesCollector
,
T
:
TablePropertiesCollectorFactory
<
C
>>
(
handle
:
*
mut
c_void
,
)
->
*
const
c_char
{
unsafe
{
unsafe
{
let
handle
=
&
mut
*
(
handle
as
*
mut
TablePropertiesCollectorFactoryHandle
);
let
handle
=
&
mut
*
(
handle
as
*
mut
TablePropertiesCollectorFactoryHandle
<
C
,
T
>
);
handle
.name
.as_ptr
()
handle
.name
.as_ptr
()
}
}
}
}
extern
"C"
fn
destruct
(
handle
:
*
mut
c_void
)
{
extern
"C"
fn
destruct
<
C
:
TablePropertiesCollector
,
T
:
TablePropertiesCollectorFactory
<
C
>>
(
handle
:
*
mut
c_void
,
)
{
unsafe
{
unsafe
{
Box
::
from_raw
(
handle
as
*
mut
TablePropertiesCollectorFactoryHandle
);
Box
::
from_raw
(
handle
as
*
mut
TablePropertiesCollectorFactoryHandle
<
C
,
T
>
);
}
}
}
}
extern
"C"
fn
create_table_properties_collector
(
extern
"C"
fn
create_table_properties_collector
<
C
:
TablePropertiesCollector
,
T
:
TablePropertiesCollectorFactory
<
C
>
,
>
(
handle
:
*
mut
c_void
,
handle
:
*
mut
c_void
,
cf
:
u32
,
cf
:
u32
,
)
->
*
mut
DBTablePropertiesCollector
{
)
->
*
mut
DBTablePropertiesCollector
{
unsafe
{
unsafe
{
let
handle
=
&
mut
*
(
handle
as
*
mut
TablePropertiesCollectorFactoryHandle
);
let
handle
=
&
mut
*
(
handle
as
*
mut
TablePropertiesCollectorFactoryHandle
<
C
,
T
>
);
let
collector
=
handle
.rep
.create_table_properties_collector
(
cf
);
let
collector
=
handle
.rep
.create_table_properties_collector
(
cf
);
new_table_properties_collector
(
handle
.name
.to_str
()
.unwrap
(),
collector
)
new_table_properties_collector
(
handle
.name
.to_str
()
.unwrap
(),
collector
)
}
}
}
}
pub
unsafe
fn
new_table_properties_collector_factory
(
pub
unsafe
fn
new_table_properties_collector_factory
<
C
:
TablePropertiesCollector
,
T
:
TablePropertiesCollectorFactory
<
C
>
,
>
(
fname
:
&
str
,
fname
:
&
str
,
factory
:
Box
<
dyn
TablePropertiesCollectorFactory
>
,
factory
:
T
,
)
->
*
mut
DBTablePropertiesCollectorFactory
{
)
->
*
mut
DBTablePropertiesCollectorFactory
{
let
handle
=
TablePropertiesCollectorFactoryHandle
::
new
(
fname
,
factory
);
let
handle
=
TablePropertiesCollectorFactoryHandle
::
new
(
fname
,
factory
);
crocksdb_ffi
::
crocksdb_table_properties_collector_factory_create
(
crocksdb_ffi
::
crocksdb_table_properties_collector_factory_create
(
Box
::
into_raw
(
Box
::
new
(
handle
))
as
*
mut
c_void
,
Box
::
into_raw
(
Box
::
new
(
handle
))
as
*
mut
c_void
,
name
,
name
::
<
C
,
T
>
,
destruct
,
destruct
::
<
C
,
T
>
,
create_table_properties_collector
,
create_table_properties_collector
::
<
C
,
T
>
,
)
)
}
}
tests/cases/test_table_properties.rs
View file @
fe19e2b5
...
@@ -132,9 +132,9 @@ impl ExampleFactory {
...
@@ -132,9 +132,9 @@ impl ExampleFactory {
}
}
}
}
impl
TablePropertiesCollectorFactory
for
ExampleFactory
{
impl
TablePropertiesCollectorFactory
<
ExampleCollector
>
for
ExampleFactory
{
fn
create_table_properties_collector
(
&
mut
self
,
_
:
u32
)
->
Box
<
dyn
TablePropertiesCollector
>
{
fn
create_table_properties_collector
(
&
mut
self
,
_
:
u32
)
->
ExampleCollector
{
Box
::
new
(
ExampleCollector
::
new
()
)
ExampleCollector
::
new
(
)
}
}
}
}
...
@@ -168,7 +168,10 @@ fn test_table_properties_collector_factory() {
...
@@ -168,7 +168,10 @@ fn test_table_properties_collector_factory() {
let
mut
opts
=
DBOptions
::
new
();
let
mut
opts
=
DBOptions
::
new
();
let
mut
cf_opts
=
ColumnFamilyOptions
::
new
();
let
mut
cf_opts
=
ColumnFamilyOptions
::
new
();
opts
.create_if_missing
(
true
);
opts
.create_if_missing
(
true
);
cf_opts
.add_table_properties_collector_factory
(
"example-collector"
,
Box
::
new
(
f
));
cf_opts
.add_table_properties_collector_factory
::
<
ExampleCollector
,
ExampleFactory
>
(
"example-collector"
,
f
,
);
let
path
=
tempdir_with_prefix
(
"_rust_rocksdb_collectortest"
);
let
path
=
tempdir_with_prefix
(
"_rust_rocksdb_collectortest"
);
let
db
=
DB
::
open_cf
(
let
db
=
DB
::
open_cf
(
...
@@ -242,8 +245,10 @@ fn test_table_properties_with_table_filter() {
...
@@ -242,8 +245,10 @@ fn test_table_properties_with_table_filter() {
let
mut
opts
=
DBOptions
::
new
();
let
mut
opts
=
DBOptions
::
new
();
let
mut
cf_opts
=
ColumnFamilyOptions
::
new
();
let
mut
cf_opts
=
ColumnFamilyOptions
::
new
();
opts
.create_if_missing
(
true
);
opts
.create_if_missing
(
true
);
cf_opts
.add_table_properties_collector_factory
(
"example-collector"
,
Box
::
new
(
f
));
cf_opts
.add_table_properties_collector_factory
::
<
ExampleCollector
,
ExampleFactory
>
(
"example-collector"
,
f
,
);
let
path
=
tempdir_with_prefix
(
"_rust_rocksdb_collector_with_table_filter"
);
let
path
=
tempdir_with_prefix
(
"_rust_rocksdb_collector_with_table_filter"
);
let
db
=
DB
::
open_cf
(
let
db
=
DB
::
open_cf
(
opts
,
opts
,
...
@@ -279,7 +284,7 @@ fn test_table_properties_with_table_filter() {
...
@@ -279,7 +284,7 @@ fn test_table_properties_with_table_filter() {
// Scan with table filter
// Scan with table filter
let
f
=
BigTableFilter
::
new
(
2
);
let
f
=
BigTableFilter
::
new
(
2
);
let
mut
ropts
=
ReadOptions
::
new
();
let
mut
ropts
=
ReadOptions
::
new
();
ropts
.set_table_filter
(
Box
::
new
(
f
)
);
ropts
.set_table_filter
::
<
BigTableFilter
>
(
f
);
let
mut
iter
=
db
.iter_opt
(
ropts
);
let
mut
iter
=
db
.iter_opt
(
ropts
);
let
key
=
b
"key"
;
let
key
=
b
"key"
;
let
key5
=
b
"key5"
;
let
key5
=
b
"key5"
;
...
...
tests/cases/test_titan.rs
View file @
fe19e2b5
...
@@ -81,9 +81,9 @@ impl TablePropertiesCollector for TitanCollector {
...
@@ -81,9 +81,9 @@ impl TablePropertiesCollector for TitanCollector {
#[derive(Default)]
#[derive(Default)]
struct
TitanCollectorFactory
{}
struct
TitanCollectorFactory
{}
impl
TablePropertiesCollectorFactory
for
TitanCollectorFactory
{
impl
TablePropertiesCollectorFactory
<
TitanCollector
>
for
TitanCollectorFactory
{
fn
create_table_properties_collector
(
&
mut
self
,
_
:
u32
)
->
Box
<
dyn
TablePropertiesCollector
>
{
fn
create_table_properties_collector
(
&
mut
self
,
_
:
u32
)
->
TitanCollector
{
Box
::
new
(
TitanCollector
::
default
()
)
TitanCollector
::
default
(
)
}
}
}
}
...
@@ -122,8 +122,10 @@ fn test_titandb() {
...
@@ -122,8 +122,10 @@ fn test_titandb() {
let
mut
cf_opts
=
ColumnFamilyOptions
::
new
();
let
mut
cf_opts
=
ColumnFamilyOptions
::
new
();
let
f
=
TitanCollectorFactory
::
default
();
let
f
=
TitanCollectorFactory
::
default
();
cf_opts
.set_titandb_options
(
&
tdb_opts
);
cf_opts
.set_titandb_options
(
&
tdb_opts
);
cf_opts
.add_table_properties_collector_factory
(
"titan-collector"
,
Box
::
new
(
f
));
cf_opts
.add_table_properties_collector_factory
::
<
TitanCollector
,
TitanCollectorFactory
>
(
"titan-collector"
,
f
,
);
let
mut
db
=
DB
::
open_cf
(
let
mut
db
=
DB
::
open_cf
(
opts
,
opts
,
path
.path
()
.to_str
()
.unwrap
(),
path
.path
()
.to_str
()
.unwrap
(),
...
@@ -263,7 +265,10 @@ fn test_titan_delete_files_in_ranges() {
...
@@ -263,7 +265,10 @@ fn test_titan_delete_files_in_ranges() {
opts
.set_titandb_options
(
&
tdb_opts
);
opts
.set_titandb_options
(
&
tdb_opts
);
let
mut
cf_opts
=
ColumnFamilyOptions
::
new
();
let
mut
cf_opts
=
ColumnFamilyOptions
::
new
();
let
f
=
TitanCollectorFactory
::
default
();
let
f
=
TitanCollectorFactory
::
default
();
cf_opts
.add_table_properties_collector_factory
(
"titan-collector"
,
Box
::
new
(
f
));
cf_opts
.add_table_properties_collector_factory
::
<
TitanCollector
,
TitanCollectorFactory
>
(
"titan-collector"
,
f
,
);
cf_opts
.set_titandb_options
(
&
tdb_opts
);
cf_opts
.set_titandb_options
(
&
tdb_opts
);
let
db
=
DB
::
open_cf
(
let
db
=
DB
::
open_cf
(
...
...
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