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
e918d1fc
Commit
e918d1fc
authored
Jul 02, 2017
by
Huachao Huang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
address comment and use reference
parent
ea46eb52
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
190 additions
and
171 deletions
+190
-171
c.cc
librocksdb_sys/crocksdb/c.cc
+65
-53
c.h
librocksdb_sys/crocksdb/rocksdb/c.h
+24
-18
lib.rs
librocksdb_sys/src/lib.rs
+6
-2
rocksdb.rs
src/rocksdb.rs
+11
-11
table_properties.rs
src/table_properties.rs
+55
-53
table_properties_collector.rs
src/table_properties_collector.rs
+16
-16
test_table_properties.rs
tests/test_table_properties.rs
+13
-18
No files found.
librocksdb_sys/crocksdb/c.cc
View file @
e918d1fc
...
...
@@ -662,7 +662,7 @@ void crocksdb_drop_column_family(
SaveError
(
errptr
,
db
->
rep
->
DropColumnFamily
(
handle
->
rep
));
}
uint32_t
crocksdb_column_family_handle_
get_
id
(
crocksdb_column_family_handle_t
*
handle
)
{
uint32_t
crocksdb_column_family_handle_id
(
crocksdb_column_family_handle_t
*
handle
)
{
return
handle
->
rep
->
GetID
();
}
...
...
@@ -2934,22 +2934,24 @@ struct crocksdb_user_collected_properties_t {
UserCollectedProperties
*
rep_
=
nullptr
;
};
struct
crocksdb_user_collected_properties_iterator_t
{
UserCollectedProperties
*
rep_
=
nullptr
;
UserCollectedProperties
::
iterator
iter_
;
};
void
crocksdb_user_collected_properties_add
(
crocksdb_user_collected_properties_t
*
props
,
const
char
*
k
,
size_t
klen
,
const
char
*
v
,
size_t
vlen
)
{
void
crocksdb_user_collected_properties_add
(
crocksdb_user_collected_properties_t
*
props
,
const
char
*
k
,
size_t
klen
,
const
char
*
v
,
size_t
vlen
)
{
props
->
rep_
->
emplace
(
std
::
make_pair
(
std
::
string
(
k
,
klen
),
std
::
string
(
v
,
vlen
)));
}
struct
crocksdb_user_collected_properties_iterator_t
{
UserCollectedProperties
::
iterator
cur_
;
UserCollectedProperties
::
iterator
end_
;
};
crocksdb_user_collected_properties_iterator_t
*
crocksdb_user_collected_properties_iter_create
(
crocksdb_user_collected_properties_t
*
props
)
{
crocksdb_user_collected_properties_iter_create
(
crocksdb_user_collected_properties_t
*
props
)
{
auto
it
=
new
crocksdb_user_collected_properties_iterator_t
;
it
->
rep_
=
props
->
rep_
;
it
->
iter_
=
props
->
rep_
->
begin
();
it
->
cur_
=
props
->
rep_
->
begin
()
;
it
->
end_
=
props
->
rep_
->
end
();
return
it
;
}
...
...
@@ -2960,35 +2962,48 @@ void crocksdb_user_collected_properties_iter_destroy(
unsigned
char
crocksdb_user_collected_properties_iter_valid
(
crocksdb_user_collected_properties_iterator_t
*
it
)
{
return
it
->
iter_
!=
it
->
rep_
->
end
()
;
return
it
->
cur_
!=
it
->
end_
;
}
void
crocksdb_user_collected_properties_iter_next
(
crocksdb_user_collected_properties_iterator_t
*
it
)
{
++
(
it
->
ite
r_
);
++
(
it
->
cu
r_
);
}
const
char
*
crocksdb_user_collected_properties_iter_key
(
crocksdb_user_collected_properties_iterator_t
*
it
,
size_t
*
klen
)
{
if
(
klen
)
{
*
klen
=
it
->
ite
r_
->
first
.
size
();
*
klen
=
it
->
cu
r_
->
first
.
size
();
}
return
it
->
ite
r_
->
first
.
data
();
return
it
->
cu
r_
->
first
.
data
();
}
const
char
*
crocksdb_user_collected_properties_iter_value
(
crocksdb_user_collected_properties_iterator_t
*
it
,
size_t
*
vlen
)
{
if
(
vlen
)
{
*
vlen
=
it
->
ite
r_
->
second
.
size
();
*
vlen
=
it
->
cu
r_
->
second
.
size
();
}
return
it
->
ite
r_
->
second
.
data
();
return
it
->
cu
r_
->
second
.
data
();
}
struct
crocksdb_table_properties_t
{
TableProperties
*
rep_
=
nullptr
;
crocksdb_user_collected_properties_t
user_props_
;
std
::
shared_ptr
<
const
TableProperties
>
rep_
;
crocksdb_user_collected_properties_t
users_
;
void
init
(
std
::
shared_ptr
<
const
TableProperties
>
rep
)
{
rep_
=
rep
;
users_
.
rep_
=
const_cast
<
UserCollectedProperties
*>
(
&
rep
->
user_collected_properties
);
}
};
crocksdb_table_properties_t
*
crocksdb_table_properties_create
()
{
return
new
crocksdb_table_properties_t
;
}
void
crocksdb_table_properties_destroy
(
crocksdb_table_properties_t
*
props
)
{
delete
props
;
}
uint64_t
crocksdb_table_properties_get_u64
(
crocksdb_table_properties_t
*
props
,
crocksdb_table_property_t
prop
)
{
auto
rep
=
props
->
rep_
;
...
...
@@ -3033,14 +3048,12 @@ const char* crocksdb_table_properties_get_str(crocksdb_table_properties_t* props
if
(
slen
)
*
slen
=
rep
->
compression_name
.
size
();
return
rep
->
compression_name
.
data
();
}
if
(
slen
)
*
slen
=
0
;
return
nullptr
;
}
crocksdb_user_collected_properties_t
*
crocksdb_table_properties_get_user_properties
(
crocksdb_table_properties_t
*
props
)
{
props
->
user_props_
.
rep_
=
&
props
->
rep_
->
user_collected_properties
;
return
&
props
->
user_props_
;
return
&
props
->
users_
;
}
/* Table Properties Collection */
...
...
@@ -3057,12 +3070,6 @@ struct crocksdb_table_properties_collection_t {
}
};
struct
crocksdb_table_properties_collection_iterator_t
{
TablePropertiesCollection
*
rep_
=
nullptr
;
TablePropertiesCollection
::
iterator
iter_
;
crocksdb_table_properties_t
props_
;
};
crocksdb_table_properties_collection_t
*
crocksdb_table_properties_collection_create
()
{
return
new
crocksdb_table_properties_collection_t
;
...
...
@@ -3073,11 +3080,17 @@ void crocksdb_table_properties_collection_destroy(
delete
collection
;
}
struct
crocksdb_table_properties_collection_iterator_t
{
TablePropertiesCollection
::
iterator
cur_
;
TablePropertiesCollection
::
iterator
end_
;
};
crocksdb_table_properties_collection_iterator_t
*
crocksdb_table_properties_collection_iter_create
(
crocksdb_table_properties_collection_t
*
c
)
{
crocksdb_table_properties_collection_iter_create
(
crocksdb_table_properties_collection_t
*
collection
)
{
auto
it
=
new
crocksdb_table_properties_collection_iterator_t
;
it
->
rep_
=
c
->
rep_
;
it
->
iter_
=
c
->
rep_
->
begin
();
it
->
cur_
=
collection
->
rep_
->
begin
()
;
it
->
end_
=
collection
->
rep_
->
end
();
return
it
;
}
...
...
@@ -3088,26 +3101,25 @@ void crocksdb_table_properties_collection_iter_destroy(
unsigned
char
crocksdb_table_properties_collection_iter_valid
(
crocksdb_table_properties_collection_iterator_t
*
it
)
{
return
it
->
iter_
!=
it
->
rep_
->
end
()
;
return
it
->
cur_
!=
it
->
end_
;
}
void
crocksdb_table_properties_collection_iter_next
(
crocksdb_table_properties_collection_iterator_t
*
it
)
{
++
(
it
->
ite
r_
);
++
(
it
->
cu
r_
);
}
const
char
*
crocksdb_table_properties_collection_iter_key
(
crocksdb_table_properties_collection_iterator_t
*
it
,
size_t
*
klen
)
{
if
(
klen
)
{
*
klen
=
it
->
ite
r_
->
first
.
size
();
*
klen
=
it
->
cu
r_
->
first
.
size
();
}
return
it
->
ite
r_
->
first
.
data
();
return
it
->
cu
r_
->
first
.
data
();
}
crocksdb_table_properties_t
*
crocksdb_table_properties_collection_iter_value
(
crocksdb_table_properties_collection_iterator_t
*
it
)
{
it
->
props_
.
rep_
=
const_cast
<
TableProperties
*>
(
it
->
iter_
->
second
.
get
());
return
&
it
->
props_
;
void
crocksdb_table_properties_collection_iter_value
(
crocksdb_table_properties_collection_iterator_t
*
it
,
crocksdb_table_properties_t
*
props
)
{
props
->
init
(
it
->
cur_
->
second
);
}
/* Table Properties Collector */
...
...
@@ -3116,10 +3128,10 @@ struct crocksdb_table_properties_collector_t : public TablePropertiesCollector {
void
*
state_
;
const
char
*
(
*
name_
)(
void
*
);
void
(
*
destruct_
)(
void
*
);
void
(
*
add_
userkey_
)(
void
*
,
const
char
*
key
,
size_t
key_len
,
const
char
*
value
,
size_t
value_len
,
int
entry_type
,
uint64_t
seq
,
uint64_t
file_size
);
void
(
*
add_
)(
void
*
,
const
char
*
key
,
size_t
key_len
,
const
char
*
value
,
size_t
value_len
,
int
entry_type
,
uint64_t
seq
,
uint64_t
file_size
);
void
(
*
finish_
)(
void
*
,
crocksdb_user_collected_properties_t
*
props
);
virtual
~
crocksdb_table_properties_collector_t
()
{
...
...
@@ -3131,10 +3143,10 @@ struct crocksdb_table_properties_collector_t : public TablePropertiesCollector {
EntryType
entry_type
,
SequenceNumber
seq
,
uint64_t
file_size
)
override
{
add_
userkey_
(
state_
,
key
.
data
(),
key
.
size
(),
value
.
data
(),
value
.
size
(),
entry_type
,
seq
,
file_size
);
add_
(
state_
,
key
.
data
(),
key
.
size
(),
value
.
data
(),
value
.
size
(),
entry_type
,
seq
,
file_size
);
return
Status
::
OK
();
}
...
...
@@ -3160,16 +3172,16 @@ crocksdb_table_properties_collector_create(
void
*
state
,
const
char
*
(
*
name
)(
void
*
),
void
(
*
destruct
)(
void
*
),
void
(
*
add
_userkey
)(
void
*
,
const
char
*
key
,
size_t
key_len
,
const
char
*
value
,
size_t
value_len
,
int
entry_type
,
uint64_t
seq
,
uint64_t
file_size
),
void
(
*
add
)(
void
*
,
const
char
*
key
,
size_t
key_len
,
const
char
*
value
,
size_t
value_len
,
int
entry_type
,
uint64_t
seq
,
uint64_t
file_size
),
void
(
*
finish
)(
void
*
,
crocksdb_user_collected_properties_t
*
props
))
{
auto
c
=
new
crocksdb_table_properties_collector_t
;
c
->
state_
=
state
;
c
->
name_
=
name
;
c
->
destruct_
=
destruct
;
c
->
add_
userkey_
=
add_userkey
;
c
->
add_
=
add
;
c
->
finish_
=
finish
;
return
c
;
}
...
...
librocksdb_sys/crocksdb/rocksdb/c.h
View file @
e918d1fc
...
...
@@ -231,7 +231,7 @@ crocksdb_create_column_family(crocksdb_t* db,
extern
C_ROCKSDB_LIBRARY_API
void
crocksdb_drop_column_family
(
crocksdb_t
*
db
,
crocksdb_column_family_handle_t
*
handle
,
char
**
errptr
);
extern
C_ROCKSDB_LIBRARY_API
uint32_t
crocksdb_column_family_handle_
get_
id
(
extern
C_ROCKSDB_LIBRARY_API
uint32_t
crocksdb_column_family_handle_id
(
crocksdb_column_family_handle_t
*
);
extern
C_ROCKSDB_LIBRARY_API
void
crocksdb_column_family_handle_destroy
(
...
...
@@ -1211,6 +1211,23 @@ extern C_ROCKSDB_LIBRARY_API const char* crocksdb_pinnableslice_value(
/* Table Properties */
extern
C_ROCKSDB_LIBRARY_API
crocksdb_table_properties_t
*
crocksdb_table_properties_create
();
extern
C_ROCKSDB_LIBRARY_API
void
crocksdb_table_properties_destroy
(
crocksdb_table_properties_t
*
);
extern
C_ROCKSDB_LIBRARY_API
uint64_t
crocksdb_table_properties_get_u64
(
crocksdb_table_properties_t
*
,
crocksdb_table_property_t
prop
);
extern
C_ROCKSDB_LIBRARY_API
const
char
*
crocksdb_table_properties_get_str
(
crocksdb_table_properties_t
*
,
crocksdb_table_property_t
prop
,
size_t
*
slen
);
extern
C_ROCKSDB_LIBRARY_API
crocksdb_user_collected_properties_t
*
crocksdb_table_properties_get_user_properties
(
crocksdb_table_properties_t
*
);
extern
C_ROCKSDB_LIBRARY_API
void
crocksdb_user_collected_properties_add
(
crocksdb_user_collected_properties_t
*
,
...
...
@@ -1240,17 +1257,6 @@ extern C_ROCKSDB_LIBRARY_API const char*
crocksdb_user_collected_properties_iter_value
(
crocksdb_user_collected_properties_iterator_t
*
,
size_t
*
vlen
);
extern
C_ROCKSDB_LIBRARY_API
uint64_t
crocksdb_table_properties_get_u64
(
crocksdb_table_properties_t
*
,
crocksdb_table_property_t
prop
);
extern
C_ROCKSDB_LIBRARY_API
const
char
*
crocksdb_table_properties_get_str
(
crocksdb_table_properties_t
*
,
crocksdb_table_property_t
prop
,
size_t
*
slen
);
extern
C_ROCKSDB_LIBRARY_API
crocksdb_user_collected_properties_t
*
crocksdb_table_properties_get_user_properties
(
crocksdb_table_properties_t
*
);
/* Table Properties Collection */
extern
C_ROCKSDB_LIBRARY_API
crocksdb_table_properties_collection_t
*
...
...
@@ -1279,9 +1285,9 @@ extern C_ROCKSDB_LIBRARY_API const char*
crocksdb_table_properties_collection_iter_key
(
crocksdb_table_properties_collection_iterator_t
*
,
size_t
*
klen
);
extern
C_ROCKSDB_LIBRARY_API
crocksdb_table_properties_t
*
extern
C_ROCKSDB_LIBRARY_API
void
crocksdb_table_properties_collection_iter_value
(
crocksdb_table_properties_collection_iterator_t
*
);
crocksdb_table_properties_collection_iterator_t
*
,
crocksdb_table_properties_t
*
props
);
/* Table Properties Collector */
...
...
@@ -1290,10 +1296,10 @@ crocksdb_table_properties_collector_create(
void
*
state
,
const
char
*
(
*
name
)(
void
*
),
void
(
*
destruct
)(
void
*
),
void
(
*
add
_userkey
)(
void
*
,
const
char
*
key
,
size_t
key_len
,
const
char
*
value
,
size_t
value_len
,
int
entry_type
,
uint64_t
seq
,
uint64_t
file_size
),
void
(
*
add
)(
void
*
,
const
char
*
key
,
size_t
key_len
,
const
char
*
value
,
size_t
value_len
,
int
entry_type
,
uint64_t
seq
,
uint64_t
file_size
),
void
(
*
finish
)(
void
*
,
crocksdb_user_collected_properties_t
*
props
));
extern
C_ROCKSDB_LIBRARY_API
void
...
...
librocksdb_sys/src/lib.rs
View file @
e918d1fc
...
...
@@ -636,7 +636,7 @@ extern "C" {
pub
fn
crocksdb_drop_column_family
(
db
:
*
mut
DBInstance
,
column_family_handle
:
*
mut
DBCFHandle
,
err
:
*
mut
*
mut
c_char
);
pub
fn
crocksdb_column_family_handle_
get_
id
(
column_family_handle
:
*
mut
DBCFHandle
)
->
u32
;
pub
fn
crocksdb_column_family_handle_id
(
column_family_handle
:
*
mut
DBCFHandle
)
->
u32
;
pub
fn
crocksdb_column_family_handle_destroy
(
column_family_handle
:
*
mut
DBCFHandle
);
pub
fn
crocksdb_list_column_families
(
db
:
*
const
DBOptions
,
path
:
*
const
c_char
,
...
...
@@ -873,6 +873,10 @@ extern "C" {
pub
fn
crocksdb_user_collected_properties_iter_value
(
it
:
*
mut
DBUserCollectedPropertiesIterator
,
vlen
:
*
mut
size_t
)
->
*
const
uint8_t
;
pub
fn
crocksdb_table_properties_create
()
->
*
mut
DBTableProperties
;
pub
fn
crocksdb_table_properties_destroy
(
props
:
*
mut
DBTableProperties
);
pub
fn
crocksdb_table_properties_get_u64
(
props
:
*
mut
DBTableProperties
,
prop
:
DBTableProperty
)
->
uint64_t
;
...
...
@@ -906,7 +910,7 @@ extern "C" {
it
:
*
mut
DBTablePropertiesCollectionIterator
,
klen
:
*
mut
size_t
)
->
*
const
uint8_t
;
pub
fn
crocksdb_table_properties_collection_iter_value
(
it
:
*
mut
DBTablePropertiesCollectionIterator
)
->
*
mut
DBTableProperties
;
(
it
:
*
mut
DBTablePropertiesCollectionIterator
,
value
:
*
mut
DBTableProperties
)
;
pub
fn
crocksdb_table_properties_collector_create
(
state
:
*
mut
c_void
,
name
:
extern
"C"
fn
(
*
mut
c_void
)
...
...
src/rocksdb.rs
View file @
e918d1fc
...
...
@@ -26,7 +26,7 @@ use std::fmt::{self, Debug, Formatter};
use
std
::
ops
::
Deref
;
use
std
::
path
::
Path
;
use
std
::
str
::
from_utf8
;
use
table_properties
::
{
TablePropertiesCollection
,
TablePropertiesCollectionHandle
}
;
use
table_properties
::
TablePropertiesCollection
;
const
DEFAULT_COLUMN_FAMILY
:
&
'static
str
=
"default"
;
...
...
@@ -36,7 +36,7 @@ pub struct CFHandle {
impl
CFHandle
{
pub
fn
id
(
&
self
)
->
u32
{
unsafe
{
crocksdb_ffi
::
crocksdb_column_family_handle_
get_
id
(
self
.inner
)
}
unsafe
{
crocksdb_ffi
::
crocksdb_column_family_handle_id
(
self
.inner
)
}
}
}
...
...
@@ -1047,9 +1047,9 @@ impl DB {
pub
fn
get_properties_of_all_tables
(
&
self
)
->
Result
<
TablePropertiesCollection
,
String
>
{
unsafe
{
let
handle
=
TablePropertiesCollectionHandle
::
new
();
ffi_try!
(
crocksdb_get_properties_of_all_tables
(
self
.inner
,
handle
.inner
));
Ok
(
TablePropertiesCollection
::
new
(
handle
)
)
let
props
=
TablePropertiesCollection
::
new
();
ffi_try!
(
crocksdb_get_properties_of_all_tables
(
self
.inner
,
props
.inner
));
Ok
(
props
)
}
}
...
...
@@ -1057,9 +1057,9 @@ impl DB {
cf
:
&
CFHandle
)
->
Result
<
TablePropertiesCollection
,
String
>
{
unsafe
{
let
handle
=
TablePropertiesCollectionHandle
::
new
();
ffi_try!
(
crocksdb_get_properties_of_all_tables_cf
(
self
.inner
,
cf
.inner
,
handle
.inner
));
Ok
(
TablePropertiesCollection
::
new
(
handle
)
)
let
props
=
TablePropertiesCollection
::
new
();
ffi_try!
(
crocksdb_get_properties_of_all_tables_cf
(
self
.inner
,
cf
.inner
,
props
.inner
));
Ok
(
props
)
}
}
...
...
@@ -1072,7 +1072,7 @@ impl DB {
let
limit_keys
:
Vec
<*
const
u8
>
=
ranges
.iter
()
.map
(|
x
|
x
.end_key
.as_ptr
())
.collect
();
let
limit_keys_lens
:
Vec
<
_
>
=
ranges
.iter
()
.map
(|
x
|
x
.end_key
.len
())
.collect
();
unsafe
{
let
handle
=
TablePropertiesCollectionHandle
::
new
();
let
props
=
TablePropertiesCollection
::
new
();
ffi_try!
(
crocksdb_get_properties_of_tables_in_range
(
self
.inner
,
cf
.inner
,
ranges
.len
()
as
i32
,
...
...
@@ -1080,8 +1080,8 @@ impl DB {
start_keys_lens
.as_ptr
(),
limit_keys
.as_ptr
(),
limit_keys_lens
.as_ptr
(),
handle
.inner
));
Ok
(
TablePropertiesCollection
::
new
(
handle
)
)
props
.inner
));
Ok
(
props
)
}
}
}
...
...
src/table_properties.rs
View file @
e918d1fc
...
...
@@ -21,24 +21,10 @@ use std::slice;
use
std
::
str
;
pub
struct
TablePropertiesCollection
{
handle
:
TablePropertiesCollectionHandle
,
}
impl
TablePropertiesCollection
{
pub
fn
new
(
handle
:
TablePropertiesCollectionHandle
)
->
TablePropertiesCollection
{
TablePropertiesCollection
{
handle
:
handle
}
}
pub
fn
iter
(
&
self
)
->
TablePropertiesCollectionIter
{
TablePropertiesCollectionIter
::
new
(
self
,
self
.handle.inner
)
}
}
pub
struct
TablePropertiesCollectionHandle
{
pub
inner
:
*
mut
DBTablePropertiesCollection
,
}
impl
Drop
for
TablePropertiesCollection
Handle
{
impl
Drop
for
TablePropertiesCollection
{
fn
drop
(
&
mut
self
)
{
unsafe
{
crocksdb_ffi
::
crocksdb_table_properties_collection_destroy
(
self
.inner
);
...
...
@@ -46,18 +32,28 @@ impl Drop for TablePropertiesCollectionHandle {
}
}
impl
TablePropertiesCollection
Handle
{
pub
fn
new
()
->
TablePropertiesCollection
Handle
{
impl
TablePropertiesCollection
{
pub
fn
new
()
->
TablePropertiesCollection
{
unsafe
{
TablePropertiesCollection
Handle
{
TablePropertiesCollection
{
inner
:
crocksdb_ffi
::
crocksdb_table_properties_collection_create
(),
}
}
}
pub
fn
collect
(
&
self
)
->
HashMap
<&
str
,
TableProperties
>
{
let
mut
res
=
HashMap
::
new
();
let
mut
iter
=
TablePropertiesCollectionIter
::
new
(
self
,
self
.inner
);
while
iter
.valid
()
{
res
.insert
(
iter
.key
(),
iter
.value
());
iter
.next
();
}
res
}
}
pub
struct
TablePropertiesCollectionIter
<
'a
>
{
props
:
&
'a
TablePropertiesCollection
,
props
:
PhantomData
<&
'a
TablePropertiesCollection
>
,
inner
:
*
mut
DBTablePropertiesCollectionIterator
,
}
...
...
@@ -70,12 +66,12 @@ impl<'a> Drop for TablePropertiesCollectionIter<'a> {
}
impl
<
'a
>
TablePropertiesCollectionIter
<
'a
>
{
fn
new
(
props
:
&
'a
TablePropertiesCollection
,
fn
new
(
_
:
&
'a
TablePropertiesCollection
,
inner
:
*
mut
DBTablePropertiesCollection
)
->
TablePropertiesCollectionIter
<
'a
>
{
unsafe
{
TablePropertiesCollectionIter
{
props
:
props
,
props
:
PhantomData
,
inner
:
crocksdb_ffi
::
crocksdb_table_properties_collection_iter_create
(
inner
),
}
}
...
...
@@ -91,7 +87,7 @@ impl<'a> TablePropertiesCollectionIter<'a> {
}
}
pub
fn
key
(
&
self
)
->
&
str
{
pub
fn
key
(
&
self
)
->
&
'a
str
{
unsafe
{
let
mut
klen
:
size_t
=
0
;
let
k
=
crocksdb_ffi
::
crocksdb_table_properties_collection_iter_key
(
self
.inner
,
...
...
@@ -103,35 +99,40 @@ impl<'a> TablePropertiesCollectionIter<'a> {
pub
fn
value
(
&
self
)
->
TableProperties
{
unsafe
{
let
inner
=
crocksdb_ffi
::
crocksdb_table_properties_collection_iter_value
(
self
.inner
);
TableProperties
::
new
(
self
.props
,
inner
)
let
props
=
TableProperties
::
new
();
crocksdb_ffi
::
crocksdb_table_properties_collection_iter_value
(
self
.inner
,
props
.inner
);
props
}
}
}
pub
struct
TableProperties
<
'a
>
{
phantom
:
PhantomData
<&
'a
TablePropertiesCollection
>
,
pub
struct
TableProperties
{
inner
:
*
mut
DBTableProperties
,
}
impl
<
'a
>
TableProperties
<
'a
>
{
fn
new
(
_
:
&
'a
TablePropertiesCollection
,
inner
:
*
mut
DBTableProperties
)
->
TableProperties
{
TableProperties
{
phantom
:
PhantomData
,
inner
:
inner
,
impl
Drop
for
TableProperties
{
fn
drop
(
&
mut
self
)
{
unsafe
{
crocksdb_ffi
::
crocksdb_table_properties_destroy
(
self
.inner
);
}
}
}
impl
TableProperties
{
fn
new
()
->
TableProperties
{
unsafe
{
TableProperties
{
inner
:
crocksdb_ffi
::
crocksdb_table_properties_create
()
}
}
}
fn
get_u64
(
&
self
,
prop
:
DBTableProperty
)
->
u64
{
unsafe
{
crocksdb_ffi
::
crocksdb_table_properties_get_u64
(
self
.inner
,
prop
)
}
}
fn
get_str
(
&
self
,
prop
:
DBTableProperty
)
->
String
{
fn
get_str
(
&
self
,
prop
:
DBTableProperty
)
->
&
str
{
unsafe
{
let
mut
slen
:
size_t
=
0
;
let
s
=
crocksdb_ffi
::
crocksdb_table_properties_get_str
(
self
.inner
,
prop
,
&
mut
slen
);
let
bytes
=
slice
::
from_raw_parts
(
s
,
slen
);
String
::
from_utf8
(
bytes
.to_owned
()
)
.unwrap
()
str
::
from_utf8
(
bytes
)
.unwrap
()
}
}
...
...
@@ -175,49 +176,50 @@ impl<'a> TableProperties<'a> {
self
.get_u64
(
DBTableProperty
::
ColumnFamilyId
)
}
pub
fn
column_family_name
(
&
self
)
->
String
{
pub
fn
column_family_name
(
&
self
)
->
&
str
{
self
.get_str
(
DBTableProperty
::
ColumnFamilyName
)
}
pub
fn
filter_policy_name
(
&
self
)
->
String
{
pub
fn
filter_policy_name
(
&
self
)
->
&
str
{
self
.get_str
(
DBTableProperty
::
FilterPolicyName
)
}
pub
fn
comparator_name
(
&
self
)
->
String
{
pub
fn
comparator_name
(
&
self
)
->
&
str
{
self
.get_str
(
DBTableProperty
::
ComparatorName
)
}
pub
fn
merge_operator_name
(
&
self
)
->
String
{
pub
fn
merge_operator_name
(
&
self
)
->
&
str
{
self
.get_str
(
DBTableProperty
::
MergeOperatorName
)
}
pub
fn
prefix_extractor_name
(
&
self
)
->
String
{
pub
fn
prefix_extractor_name
(
&
self
)
->
&
str
{
self
.get_str
(
DBTableProperty
::
PrefixExtractorName
)
}
pub
fn
property_collectors_names
(
&
self
)
->
String
{
pub
fn
property_collectors_names
(
&
self
)
->
&
str
{
self
.get_str
(
DBTableProperty
::
PropertyCollectorsNames
)
}
pub
fn
compression_name
(
&
self
)
->
String
{
pub
fn
compression_name
(
&
self
)
->
&
str
{
self
.get_str
(
DBTableProperty
::
CompressionName
)
}
pub
fn
user_collected_properties
(
&
self
)
->
HashMap
<
Vec
<
u8
>
,
Vec
<
u8
>>
{
let
inner
=
unsafe
{
crocksdb_ffi
::
crocksdb_table_properties_get_user_properties
(
self
.inner
)
};
let
mut
iter
=
UserCollectedPropertiesIter
::
new
(
self
,
inner
);
let
mut
props
=
HashMap
::
new
();
while
iter
.valid
()
{
props
.insert
(
iter
.key
()
.to_owned
(),
iter
.value
()
.to_owned
());
iter
.next
();
pub
fn
user_collected_properties
(
&
self
)
->
HashMap
<&
[
u8
],
&
[
u8
]
>
{
let
mut
res
=
HashMap
::
new
();
unsafe
{
let
inner
=
crocksdb_ffi
::
crocksdb_table_properties_get_user_properties
(
self
.inner
);
let
mut
iter
=
UserCollectedPropertiesIter
::
new
(
self
,
inner
);
while
iter
.valid
()
{
res
.insert
(
iter
.key
(),
iter
.value
());
iter
.next
();
}
}
prop
s
re
s
}
}
struct
UserCollectedPropertiesIter
<
'a
>
{
p
hantom
:
PhantomData
<&
'a
TableProperties
<
'a
>
>
,
p
rops
:
PhantomData
<&
'a
TablePropertiesCollection
>
,
inner
:
*
mut
DBUserCollectedPropertiesIterator
,
}
...
...
@@ -235,7 +237,7 @@ impl<'a> UserCollectedPropertiesIter<'a> {
->
UserCollectedPropertiesIter
<
'a
>
{
unsafe
{
UserCollectedPropertiesIter
{
p
hantom
:
PhantomData
,
p
rops
:
PhantomData
,
inner
:
crocksdb_ffi
::
crocksdb_user_collected_properties_iter_create
(
inner
),
}
}
...
...
@@ -251,7 +253,7 @@ impl<'a> UserCollectedPropertiesIter<'a> {
}
}
fn
key
(
&
self
)
->
&
[
u8
]
{
fn
key
(
&
self
)
->
&
'a
[
u8
]
{
unsafe
{
let
mut
klen
:
size_t
=
0
;
let
k
=
crocksdb_ffi
::
crocksdb_user_collected_properties_iter_key
(
self
.inner
,
...
...
@@ -260,7 +262,7 @@ impl<'a> UserCollectedPropertiesIter<'a> {
}
}
fn
value
(
&
self
)
->
&
[
u8
]
{
fn
value
(
&
self
)
->
&
'a
[
u8
]
{
unsafe
{
let
mut
vlen
:
size_t
=
0
;
let
v
=
crocksdb_ffi
::
crocksdb_user_collected_properties_iter_value
(
self
.inner
,
...
...
src/table_properties_collector.rs
View file @
e918d1fc
...
...
@@ -29,12 +29,12 @@ pub trait TablePropertiesCollector {
fn
name
(
&
self
)
->
&
str
;
/// Will be called when a new key/value pair is inserted into the table.
fn
add
_userkey
(
&
mut
self
,
key
:
&
[
u8
],
value
:
&
[
u8
],
entry_type
:
DBEntryType
,
seq
:
u64
,
file_size
:
u64
);
fn
add
(
&
mut
self
,
key
:
&
[
u8
],
value
:
&
[
u8
],
entry_type
:
DBEntryType
,
seq
:
u64
,
file_size
:
u64
);
/// Will be called when a table has already been built and is ready for
/// writing the properties block.
...
...
@@ -69,19 +69,19 @@ extern "C" fn destruct(handle: *mut c_void) {
}
}
pub
extern
"C"
fn
add
_userkey
(
handle
:
*
mut
c_void
,
key
:
*
const
uint8_t
,
key_len
:
size_t
,
value
:
*
const
uint8_t
,
value_len
:
size_t
,
entry_type
:
c_int
,
seq
:
uint64_t
,
file_size
:
uint64_t
)
{
pub
extern
"C"
fn
add
(
handle
:
*
mut
c_void
,
key
:
*
const
uint8_t
,
key_len
:
size_t
,
value
:
*
const
uint8_t
,
value_len
:
size_t
,
entry_type
:
c_int
,
seq
:
uint64_t
,
file_size
:
uint64_t
)
{
unsafe
{
let
handle
=
&
mut
*
(
handle
as
*
mut
TablePropertiesCollectorHandle
);
let
key
=
slice
::
from_raw_parts
(
key
,
key_len
);
let
value
=
slice
::
from_raw_parts
(
value
,
value_len
);
handle
.rep
.add
_userkey
(
key
,
value
,
mem
::
transmute
(
entry_type
),
seq
,
file_size
);
handle
.rep
.add
(
key
,
value
,
mem
::
transmute
(
entry_type
),
seq
,
file_size
);
}
}
...
...
@@ -105,7 +105,7 @@ pub unsafe fn new_table_properties_collector(collector: Box<TablePropertiesColle
Box
::
into_raw
(
Box
::
new
(
handle
))
as
*
mut
c_void
,
name
,
destruct
,
add
_userkey
,
add
,
finish
,
)
}
tests/test_table_properties.rs
View file @
e918d1fc
...
...
@@ -73,12 +73,12 @@ impl ExampleCollector {
props
}
fn
decode
(
props
:
&
HashMap
<
Vec
<
u8
>
,
Vec
<
u8
>
>
)
->
ExampleCollector
{
fn
decode
(
props
:
HashMap
<&
[
u8
],
&
[
u8
]
>
)
->
ExampleCollector
{
let
mut
c
=
ExampleCollector
::
new
();
c
.num_keys
=
decode_u32
(
props
.get
(
&
vec!
[
Props
::
NumKeys
as
u8
]
)
.unwrap
());
c
.num_puts
=
decode_u32
(
props
.get
(
&
vec!
[
Props
::
NumPuts
as
u8
]
)
.unwrap
());
c
.num_merges
=
decode_u32
(
props
.get
(
&
vec!
[
Props
::
NumMerges
as
u8
]
)
.unwrap
());
c
.num_deletes
=
decode_u32
(
props
.get
(
&
vec!
[
Props
::
NumDeletes
as
u8
]
)
.unwrap
());
c
.num_keys
=
decode_u32
(
props
.get
(
&
[
Props
::
NumKeys
as
u8
]
.as_ref
()
)
.unwrap
());
c
.num_puts
=
decode_u32
(
props
.get
(
&
[
Props
::
NumPuts
as
u8
]
.as_ref
()
)
.unwrap
());
c
.num_merges
=
decode_u32
(
props
.get
(
&
[
Props
::
NumMerges
as
u8
]
.as_ref
()
)
.unwrap
());
c
.num_deletes
=
decode_u32
(
props
.get
(
&
[
Props
::
NumDeletes
as
u8
]
.as_ref
()
)
.unwrap
());
c
}
}
...
...
@@ -99,7 +99,7 @@ impl TablePropertiesCollector for ExampleCollector {
"example-collector"
}
fn
add
_userkey
(
&
mut
self
,
key
:
&
[
u8
],
_
:
&
[
u8
],
entry_type
:
DBEntryType
,
_
:
u64
,
_
:
u64
)
{
fn
add
(
&
mut
self
,
key
:
&
[
u8
],
_
:
&
[
u8
],
entry_type
:
DBEntryType
,
_
:
u64
,
_
:
u64
)
{
if
key
.cmp
(
&
self
.last_key
)
!=
Ordering
::
Equal
{
self
.num_keys
+=
1
;
self
.last_key
.clear
();
...
...
@@ -138,24 +138,19 @@ impl TablePropertiesCollectorFactory for ExampleFactory {
}
fn
check_collection
(
collection
:
&
TablePropertiesCollection
,
num_files
:
u
32
,
num_files
:
u
size
,
num_keys
:
u32
,
num_puts
:
u32
,
num_merges
:
u32
,
num_deletes
:
u32
)
{
let
mut
len
=
0
;
let
mut
res
=
ExampleCollector
::
new
();
let
mut
iter
=
collection
.iter
();
while
iter
.valid
()
{
len
+=
1
;
{
let
v
=
iter
.value
();
assert_eq!
(
v
.property_collectors_names
(),
"[example-factory]"
);
res
.add
(
&
ExampleCollector
::
decode
(
&
v
.user_collected_properties
()));
}
iter
.next
();
let
props
=
collection
.collect
();
for
(
k
,
v
)
in
&
props
{
assert
!
(
k
.ends_with
(
".sst"
));
assert_eq!
(
v
.property_collectors_names
(),
"[example-factory]"
);
res
.add
(
&
ExampleCollector
::
decode
(
v
.user_collected_properties
()));
}
assert_eq!
(
len
,
num_files
);
assert_eq!
(
props
.len
()
,
num_files
);
assert_eq!
(
res
.num_keys
,
num_keys
);
assert_eq!
(
res
.num_puts
,
num_puts
);
assert_eq!
(
res
.num_merges
,
num_merges
);
...
...
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