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
a50c0841
Commit
a50c0841
authored
Jul 07, 2017
by
Jay Lee
Committed by
Jay
Jul 07, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
user properties: clean up API (#90)
- reduce allocation - collect lazily - strict access mode
parent
44b2521a
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
207 additions
and
159 deletions
+207
-159
.travis.yml
.travis.yml
+1
-1
c.cc
librocksdb_sys/crocksdb/c.cc
+0
-0
c.h
librocksdb_sys/crocksdb/rocksdb/c.h
+34
-35
lib.rs
librocksdb_sys/src/lib.rs
+27
-23
lib.rs
src/lib.rs
+1
-1
rocksdb.rs
src/rocksdb.rs
+8
-12
table_properties.rs
src/table_properties.rs
+119
-80
test_table_properties.rs
tests/test_table_properties.rs
+17
-7
No files found.
.travis.yml
View file @
a50c0841
...
@@ -18,7 +18,7 @@ before_script:
...
@@ -18,7 +18,7 @@ before_script:
-
make -f travis-build/Makefile prepare-rustfmt
-
make -f travis-build/Makefile prepare-rustfmt
script
:
script
:
-
cargo fmt
&& git diff-index --quiet HEAD --
|| (echo please make format and run tests before creating a pr!; exit 1)
-
cargo fmt
-- --write-mode diff
|| (echo please make format and run tests before creating a pr!; exit 1)
-
cargo build --features static-link
-
cargo build --features static-link
-
cargo test --all --features static-link
-
cargo test --all --features static-link
...
...
librocksdb_sys/crocksdb/c.cc
View file @
a50c0841
This diff is collapsed.
Click to expand it.
librocksdb_sys/crocksdb/rocksdb/c.h
View file @
a50c0841
...
@@ -1226,22 +1226,23 @@ extern C_ROCKSDB_LIBRARY_API void crocksdb_get_supported_compression(int *, size
...
@@ -1226,22 +1226,23 @@ extern C_ROCKSDB_LIBRARY_API void crocksdb_get_supported_compression(int *, size
/* Table Properties */
/* Table Properties */
extern
C_ROCKSDB_LIBRARY_API
crocksdb_table_properties_t
*
extern
C_ROCKSDB_LIBRARY_API
uint64_t
crocksdb_table_properties_get_u64
(
crocksdb_table_properties_create
(
);
const
crocksdb_table_properties_t
*
,
crocksdb_table_property_t
prop
);
extern
C_ROCKSDB_LIBRARY_API
void
extern
C_ROCKSDB_LIBRARY_API
const
char
*
crocksdb_table_properties_get_str
(
crocksdb_table_properties_destroy
(
crocksdb_table_properties_t
*
);
const
crocksdb_table_properties_t
*
,
crocksdb_table_property_t
prop
,
size_t
*
slen
);
extern
C_ROCKSDB_LIBRARY_API
uint64_t
extern
C_ROCKSDB_LIBRARY_API
const
crocksdb_user_collected_properties_t
*
crocksdb_table_properties_get_u
64
(
crocksdb_table_properties_t
*
,
crocksdb_table_properties_get_u
ser_properties
(
crocksdb_table_property_t
prop
);
const
crocksdb_table_properties_t
*
);
extern
C_ROCKSDB_LIBRARY_API
const
char
*
extern
C_ROCKSDB_LIBRARY_API
const
char
*
crocksdb_user_collected_properties_get
(
crocksdb_table_properties_get_str
(
crocksdb_table_properties_t
*
,
const
crocksdb_user_collected_properties_t
*
props
,
const
char
*
key
,
crocksdb_table_property_t
prop
,
size_t
*
s
len
);
size_t
klen
,
size_t
*
v
len
);
extern
C_ROCKSDB_LIBRARY_API
crocksdb_user_collected_properties_t
*
extern
C_ROCKSDB_LIBRARY_API
size_t
crocksdb_user_collected_properties_len
(
crocksdb_table_properties_get_user_properties
(
crocksdb_table
_properties_t
*
);
const
crocksdb_user_collected
_properties_t
*
);
extern
C_ROCKSDB_LIBRARY_API
void
extern
C_ROCKSDB_LIBRARY_API
void
crocksdb_user_collected_properties_add
(
crocksdb_user_collected_properties_add
(
...
@@ -1250,15 +1251,15 @@ crocksdb_user_collected_properties_add(
...
@@ -1250,15 +1251,15 @@ crocksdb_user_collected_properties_add(
extern
C_ROCKSDB_LIBRARY_API
crocksdb_user_collected_properties_iterator_t
*
extern
C_ROCKSDB_LIBRARY_API
crocksdb_user_collected_properties_iterator_t
*
crocksdb_user_collected_properties_iter_create
(
crocksdb_user_collected_properties_iter_create
(
crocksdb_user_collected_properties_t
*
);
const
crocksdb_user_collected_properties_t
*
);
extern
C_ROCKSDB_LIBRARY_API
void
extern
C_ROCKSDB_LIBRARY_API
void
crocksdb_user_collected_properties_iter_destroy
(
crocksdb_user_collected_properties_iter_destroy
(
crocksdb_user_collected_properties_iterator_t
*
);
crocksdb_user_collected_properties_iterator_t
*
);
extern
C_ROCKSDB_LIBRARY_API
unsigned
char
extern
C_ROCKSDB_LIBRARY_API
unsigned
char
crocksdb_user_collected_properties_iter_valid
(
crocksdb_user_collected_properties_iter_valid
(
crocksdb_user_collected_properties_iterator_t
*
);
const
crocksdb_user_collected_properties_iterator_t
*
);
extern
C_ROCKSDB_LIBRARY_API
void
extern
C_ROCKSDB_LIBRARY_API
void
crocksdb_user_collected_properties_iter_next
(
crocksdb_user_collected_properties_iter_next
(
...
@@ -1266,23 +1267,23 @@ crocksdb_user_collected_properties_iter_next(
...
@@ -1266,23 +1267,23 @@ crocksdb_user_collected_properties_iter_next(
extern
C_ROCKSDB_LIBRARY_API
const
char
*
extern
C_ROCKSDB_LIBRARY_API
const
char
*
crocksdb_user_collected_properties_iter_key
(
crocksdb_user_collected_properties_iter_key
(
crocksdb_user_collected_properties_iterator_t
*
,
size_t
*
klen
);
c
onst
c
rocksdb_user_collected_properties_iterator_t
*
,
size_t
*
klen
);
extern
C_ROCKSDB_LIBRARY_API
const
char
*
extern
C_ROCKSDB_LIBRARY_API
const
char
*
crocksdb_user_collected_properties_iter_value
(
crocksdb_user_collected_properties_iter_value
(
crocksdb_user_collected_properties_iterator_t
*
,
size_t
*
vlen
);
c
onst
c
rocksdb_user_collected_properties_iterator_t
*
,
size_t
*
vlen
);
/* Table Properties Collection */
/* Table Properties Collection */
extern
C_ROCKSDB_LIBRARY_API
crocksdb_table_properties_collection_t
*
extern
C_ROCKSDB_LIBRARY_API
size_t
crocksdb_table_properties_collection_len
(
crocksdb_table_properties_collection_create
(
);
const
crocksdb_table_properties_collection_t
*
);
extern
C_ROCKSDB_LIBRARY_API
void
extern
C_ROCKSDB_LIBRARY_API
void
crocksdb_table_properties_collection_destroy
(
crocksdb_table_properties_collection_t
*
);
crocksdb_table_properties_collection_destroy
(
crocksdb_table_properties_collection_t
*
);
extern
C_ROCKSDB_LIBRARY_API
crocksdb_table_properties_collection_iterator_t
*
extern
C_ROCKSDB_LIBRARY_API
crocksdb_table_properties_collection_iterator_t
*
crocksdb_table_properties_collection_iter_create
(
crocksdb_table_properties_collection_iter_create
(
crocksdb_table_properties_collection_t
*
);
c
onst
c
rocksdb_table_properties_collection_t
*
);
extern
C_ROCKSDB_LIBRARY_API
void
extern
C_ROCKSDB_LIBRARY_API
void
crocksdb_table_properties_collection_iter_destroy
(
crocksdb_table_properties_collection_iter_destroy
(
...
@@ -1290,7 +1291,7 @@ crocksdb_table_properties_collection_iter_destroy(
...
@@ -1290,7 +1291,7 @@ crocksdb_table_properties_collection_iter_destroy(
extern
C_ROCKSDB_LIBRARY_API
unsigned
char
extern
C_ROCKSDB_LIBRARY_API
unsigned
char
crocksdb_table_properties_collection_iter_valid
(
crocksdb_table_properties_collection_iter_valid
(
crocksdb_table_properties_collection_iterator_t
*
);
c
onst
c
rocksdb_table_properties_collection_iterator_t
*
);
extern
C_ROCKSDB_LIBRARY_API
void
extern
C_ROCKSDB_LIBRARY_API
void
crocksdb_table_properties_collection_iter_next
(
crocksdb_table_properties_collection_iter_next
(
...
@@ -1298,11 +1299,11 @@ crocksdb_table_properties_collection_iter_next(
...
@@ -1298,11 +1299,11 @@ crocksdb_table_properties_collection_iter_next(
extern
C_ROCKSDB_LIBRARY_API
const
char
*
extern
C_ROCKSDB_LIBRARY_API
const
char
*
crocksdb_table_properties_collection_iter_key
(
crocksdb_table_properties_collection_iter_key
(
crocksdb_table_properties_collection_iterator_t
*
,
size_t
*
klen
);
c
onst
c
rocksdb_table_properties_collection_iterator_t
*
,
size_t
*
klen
);
extern
C_ROCKSDB_LIBRARY_API
void
extern
C_ROCKSDB_LIBRARY_API
const
crocksdb_table_properties_t
*
crocksdb_table_properties_collection_iter_value
(
crocksdb_table_properties_collection_iter_value
(
c
rocksdb_table_properties_collection_iterator_t
*
,
crocksdb_table_properties_t
*
props
);
c
onst
crocksdb_table_properties_collection_iterator_t
*
);
/* Table Properties Collector */
/* Table Properties Collector */
...
@@ -1340,22 +1341,20 @@ crocksdb_options_add_table_properties_collector_factory(
...
@@ -1340,22 +1341,20 @@ crocksdb_options_add_table_properties_collector_factory(
/* Get Table Properties */
/* Get Table Properties */
extern
C_ROCKSDB_LIBRARY_API
void
extern
C_ROCKSDB_LIBRARY_API
crocksdb_table_properties_collection_t
*
crocksdb_get_propeties_of_all_tables
(
crocksdb_t
*
db
,
crocksdb_get_propeties_of_all_tables
(
crocksdb_t
*
db
,
char
**
errptr
);
crocksdb_table_properties_collection_t
*
props
,
char
**
errptr
);
extern
C_ROCKSDB_LIBRARY_API
void
extern
C_ROCKSDB_LIBRARY_API
crocksdb_table_properties_collection_t
*
crocksdb_get_propeties_of_all_tables_cf
(
crocksdb_get_propeties_of_all_tables_cf
(
crocksdb_t
*
db
,
crocksdb_t
*
db
,
crocksdb_column_family_handle_t
*
cf
,
crocksdb_column_family_handle_t
*
cf
,
crocksdb_table_properties_collection_t
*
props
,
char
**
errptr
);
char
**
errptr
);
extern
C_ROCKSDB_LIBRARY_API
void
extern
C_ROCKSDB_LIBRARY_API
crocksdb_table_properties_collection_t
*
crocksdb_get_propeties_of_tables_in_range
(
crocksdb_get_propeties_of_tables_in_range
(
crocksdb_t
*
db
,
crocksdb_column_family_handle_t
*
cf
,
crocksdb_t
*
db
,
crocksdb_column_family_handle_t
*
cf
,
int
num_ranges
,
int
num_ranges
,
const
char
*
const
*
start_keys
,
const
size_t
*
start_keys_lens
,
const
char
*
const
*
start_keys
,
const
size_t
*
start_keys_lens
,
const
char
*
const
*
limit_keys
,
const
size_t
*
limit_keys_lens
,
const
char
*
const
*
limit_keys
,
const
size_t
*
limit_keys_lens
,
c
rocksdb_table_properties_collection_t
*
props
,
c
har
**
errptr
);
char
**
errptr
);
#ifdef __cplusplus
#ifdef __cplusplus
}
/* end extern "C" */
}
/* end extern "C" */
...
...
librocksdb_sys/src/lib.rs
View file @
a50c0841
...
@@ -866,63 +866,67 @@ extern "C" {
...
@@ -866,63 +866,67 @@ extern "C" {
value_len
:
size_t
);
value_len
:
size_t
);
pub
fn
crocksdb_user_collected_properties_iter_create
pub
fn
crocksdb_user_collected_properties_iter_create
(
props
:
*
mu
t
DBUserCollectedProperties
)
(
props
:
*
cons
t
DBUserCollectedProperties
)
->
*
mut
DBUserCollectedPropertiesIterator
;
->
*
mut
DBUserCollectedPropertiesIterator
;
pub
fn
crocksdb_user_collected_properties_iter_destroy
pub
fn
crocksdb_user_collected_properties_iter_destroy
(
it
:
*
mut
DBUserCollectedPropertiesIterator
);
(
it
:
*
mut
DBUserCollectedPropertiesIterator
);
pub
fn
crocksdb_user_collected_properties_iter_valid
pub
fn
crocksdb_user_collected_properties_iter_valid
(
it
:
*
mu
t
DBUserCollectedPropertiesIterator
)
->
bool
;
(
it
:
*
cons
t
DBUserCollectedPropertiesIterator
)
->
bool
;
pub
fn
crocksdb_user_collected_properties_iter_next
pub
fn
crocksdb_user_collected_properties_iter_next
(
it
:
*
mut
DBUserCollectedPropertiesIterator
);
(
it
:
*
mut
DBUserCollectedPropertiesIterator
);
pub
fn
crocksdb_user_collected_properties_iter_key
(
it
:
*
mu
t
DBUserCollectedPropertiesIterator
,
pub
fn
crocksdb_user_collected_properties_iter_key
(
it
:
*
cons
t
DBUserCollectedPropertiesIterator
,
klen
:
*
mut
size_t
)
klen
:
*
mut
size_t
)
->
*
const
uint8_t
;
->
*
const
uint8_t
;
pub
fn
crocksdb_user_collected_properties_iter_value
pub
fn
crocksdb_user_collected_properties_iter_value
(
it
:
*
mu
t
DBUserCollectedPropertiesIterator
,
vlen
:
*
mut
size_t
)
->
*
const
uint8_t
;
(
it
:
*
cons
t
DBUserCollectedPropertiesIterator
,
vlen
:
*
mut
size_t
)
->
*
const
uint8_t
;
pub
fn
crocksdb_table_properties_create
()
->
*
mut
DBTableProperties
;
pub
fn
crocksdb_table_properties_get_u64
(
props
:
*
const
DBTableProperties
,
pub
fn
crocksdb_table_properties_destroy
(
props
:
*
mut
DBTableProperties
);
pub
fn
crocksdb_table_properties_get_u64
(
props
:
*
mut
DBTableProperties
,
prop
:
DBTableProperty
)
prop
:
DBTableProperty
)
->
uint64_t
;
->
uint64_t
;
pub
fn
crocksdb_table_properties_get_str
(
props
:
*
mu
t
DBTableProperties
,
pub
fn
crocksdb_table_properties_get_str
(
props
:
*
cons
t
DBTableProperties
,
prop
:
DBTableProperty
,
prop
:
DBTableProperty
,
slen
:
*
mut
size_t
)
slen
:
*
mut
size_t
)
->
*
const
uint8_t
;
->
*
const
uint8_t
;
pub
fn
crocksdb_table_properties_get_user_properties
(
props
:
*
mut
DBTableProperties
)
pub
fn
crocksdb_table_properties_get_user_properties
(
props
:
*
const
DBTableProperties
)
->
*
mut
DBUserCollectedProperties
;
->
*
const
DBUserCollectedProperties
;
pub
fn
crocksdb_user_collected_properties_get
(
props
:
*
const
DBUserCollectedProperties
,
key
:
*
const
uint8_t
,
klen
:
size_t
,
vlen
:
*
mut
size_t
)
->
*
const
uint8_t
;
pub
fn
crocksdb_user_collected_properties_len
(
props
:
*
const
DBUserCollectedProperties
)
->
size_t
;
pub
fn
crocksdb_table_properties_collection_
create
()
->
*
mut
DBTablePropertiesCollection
;
pub
fn
crocksdb_table_properties_collection_
len
(
props
:
*
const
DBTablePropertiesCollection
)
->
size_t
;
pub
fn
crocksdb_table_properties_collection_destroy
(
props
:
*
mut
DBTablePropertiesCollection
);
pub
fn
crocksdb_table_properties_collection_destroy
(
props
:
*
mut
DBTablePropertiesCollection
);
pub
fn
crocksdb_table_properties_collection_iter_create
pub
fn
crocksdb_table_properties_collection_iter_create
(
props
:
*
mu
t
DBTablePropertiesCollection
)
(
props
:
*
cons
t
DBTablePropertiesCollection
)
->
*
mut
DBTablePropertiesCollectionIterator
;
->
*
mut
DBTablePropertiesCollectionIterator
;
pub
fn
crocksdb_table_properties_collection_iter_destroy
pub
fn
crocksdb_table_properties_collection_iter_destroy
(
it
:
*
mut
DBTablePropertiesCollectionIterator
);
(
it
:
*
mut
DBTablePropertiesCollectionIterator
);
pub
fn
crocksdb_table_properties_collection_iter_valid
pub
fn
crocksdb_table_properties_collection_iter_valid
(
it
:
*
mu
t
DBTablePropertiesCollectionIterator
)
->
bool
;
(
it
:
*
cons
t
DBTablePropertiesCollectionIterator
)
->
bool
;
pub
fn
crocksdb_table_properties_collection_iter_next
pub
fn
crocksdb_table_properties_collection_iter_next
(
it
:
*
mut
DBTablePropertiesCollectionIterator
);
(
it
:
*
mut
DBTablePropertiesCollectionIterator
);
pub
fn
crocksdb_table_properties_collection_iter_key
(
pub
fn
crocksdb_table_properties_collection_iter_key
(
it
:
*
mu
t
DBTablePropertiesCollectionIterator
,
klen
:
*
mut
size_t
)
->
*
const
uint8_t
;
it
:
*
cons
t
DBTablePropertiesCollectionIterator
,
klen
:
*
mut
size_t
)
->
*
const
uint8_t
;
pub
fn
crocksdb_table_properties_collection_iter_value
pub
fn
crocksdb_table_properties_collection_iter_value
(
it
:
*
mut
DBTablePropertiesCollectionIterator
,
value
:
*
mut
DBTableProperties
)
;
(
it
:
*
const
DBTablePropertiesCollectionIterator
)
->
*
const
DBTableProperties
;
pub
fn
crocksdb_table_properties_collector_create
(
state
:
*
mut
c_void
,
pub
fn
crocksdb_table_properties_collector_create
(
state
:
*
mut
c_void
,
name
:
extern
"C"
fn
(
*
mut
c_void
)
name
:
extern
"C"
fn
(
*
mut
c_void
)
...
@@ -958,13 +962,13 @@ extern "C" {
...
@@ -958,13 +962,13 @@ extern "C" {
options
:
*
mut
DBOptions
,
f
:
*
mut
DBTablePropertiesCollectorFactory
);
options
:
*
mut
DBOptions
,
f
:
*
mut
DBTablePropertiesCollectorFactory
);
pub
fn
crocksdb_get_properties_of_all_tables
(
db
:
*
mut
DBInstance
,
pub
fn
crocksdb_get_properties_of_all_tables
(
db
:
*
mut
DBInstance
,
props
:
*
mut
DBTablePropertiesCollection
,
errptr
:
*
mut
*
mut
c_char
)
errptr
:
*
mut
*
mut
c_char
)
;
->
*
mut
DBTablePropertiesCollection
;
pub
fn
crocksdb_get_properties_of_all_tables_cf
(
db
:
*
mut
DBInstance
,
pub
fn
crocksdb_get_properties_of_all_tables_cf
(
db
:
*
mut
DBInstance
,
cf
:
*
mut
DBCFHandle
,
cf
:
*
mut
DBCFHandle
,
props
:
*
mut
DBTablePropertiesCollection
,
errptr
:
*
mut
*
mut
c_char
)
errptr
:
*
mut
*
mut
c_char
)
;
->
*
mut
DBTablePropertiesCollection
;
pub
fn
crocksdb_get_properties_of_tables_in_range
(
db
:
*
mut
DBInstance
,
pub
fn
crocksdb_get_properties_of_tables_in_range
(
db
:
*
mut
DBInstance
,
cf
:
*
mut
DBCFHandle
,
cf
:
*
mut
DBCFHandle
,
...
@@ -973,8 +977,8 @@ extern "C" {
...
@@ -973,8 +977,8 @@ extern "C" {
start_keys_lens
:
*
const
size_t
,
start_keys_lens
:
*
const
size_t
,
limit_keys
:
*
const
*
const
uint8_t
,
limit_keys
:
*
const
*
const
uint8_t
,
limit_keys_lens
:
*
const
size_t
,
limit_keys_lens
:
*
const
size_t
,
props
:
*
mut
DBTablePropertiesCollection
,
errptr
:
*
mut
*
mut
c_char
)
errptr
:
*
mut
*
mut
c_char
)
;
->
*
mut
DBTablePropertiesCollection
;
}
}
...
...
src/lib.rs
View file @
a50c0841
...
@@ -40,6 +40,6 @@ pub use rocksdb::{DB, DBIterator, DBVector, Kv, SeekKey, Writable, WriteBatch, C
...
@@ -40,6 +40,6 @@ pub use rocksdb::{DB, DBIterator, DBVector, Kv, SeekKey, Writable, WriteBatch, C
pub
use
rocksdb_options
::{
BlockBasedOptions
,
Options
,
ReadOptions
,
WriteOptions
,
RestoreOptions
,
pub
use
rocksdb_options
::{
BlockBasedOptions
,
Options
,
ReadOptions
,
WriteOptions
,
RestoreOptions
,
IngestExternalFileOptions
,
EnvOptions
,
HistogramData
,
CompactOptions
};
IngestExternalFileOptions
,
EnvOptions
,
HistogramData
,
CompactOptions
};
pub
use
slice_transform
::
SliceTransform
;
pub
use
slice_transform
::
SliceTransform
;
pub
use
table_properties
::{
TableProperties
,
TablePropertiesCollection
};
pub
use
table_properties
::{
TableProperties
,
TablePropertiesCollection
,
UserCollectedProperties
};
pub
use
table_properties_collector
::
TablePropertiesCollector
;
pub
use
table_properties_collector
::
TablePropertiesCollector
;
pub
use
table_properties_collector_factory
::
TablePropertiesCollectorFactory
;
pub
use
table_properties_collector_factory
::
TablePropertiesCollectorFactory
;
src/rocksdb.rs
View file @
a50c0841
...
@@ -27,7 +27,7 @@ use std::fmt::{self, Debug, Formatter};
...
@@ -27,7 +27,7 @@ use std::fmt::{self, Debug, Formatter};
use
std
::
ops
::
Deref
;
use
std
::
ops
::
Deref
;
use
std
::
path
::
Path
;
use
std
::
path
::
Path
;
use
std
::
str
::
from_utf8
;
use
std
::
str
::
from_utf8
;
use
table_properties
::
{
TablePropertiesCollection
,
new_table_properties_collection
}
;
use
table_properties
::
TablePropertiesCollection
;
const
DEFAULT_COLUMN_FAMILY
:
&
'static
str
=
"default"
;
const
DEFAULT_COLUMN_FAMILY
:
&
'static
str
=
"default"
;
...
@@ -1048,9 +1048,8 @@ impl DB {
...
@@ -1048,9 +1048,8 @@ impl DB {
pub
fn
get_properties_of_all_tables
(
&
self
)
->
Result
<
TablePropertiesCollection
,
String
>
{
pub
fn
get_properties_of_all_tables
(
&
self
)
->
Result
<
TablePropertiesCollection
,
String
>
{
unsafe
{
unsafe
{
let
props
=
new_table_properties_collection
();
let
props
=
ffi_try!
(
crocksdb_get_properties_of_all_tables
(
self
.inner
));
ffi_try!
(
crocksdb_get_properties_of_all_tables
(
self
.inner
,
props
.inner
));
Ok
(
TablePropertiesCollection
::
from_raw
(
props
))
Ok
(
props
)
}
}
}
}
...
@@ -1058,9 +1057,8 @@ impl DB {
...
@@ -1058,9 +1057,8 @@ impl DB {
cf
:
&
CFHandle
)
cf
:
&
CFHandle
)
->
Result
<
TablePropertiesCollection
,
String
>
{
->
Result
<
TablePropertiesCollection
,
String
>
{
unsafe
{
unsafe
{
let
props
=
new_table_properties_collection
();
let
props
=
ffi_try!
(
crocksdb_get_properties_of_all_tables_cf
(
self
.inner
,
cf
.inner
));
ffi_try!
(
crocksdb_get_properties_of_all_tables_cf
(
self
.inner
,
cf
.inner
,
props
.inner
));
Ok
(
TablePropertiesCollection
::
from_raw
(
props
))
Ok
(
props
)
}
}
}
}
...
@@ -1073,16 +1071,14 @@ impl DB {
...
@@ -1073,16 +1071,14 @@ impl DB {
let
limit_keys
:
Vec
<*
const
u8
>
=
ranges
.iter
()
.map
(|
x
|
x
.end_key
.as_ptr
())
.collect
();
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
();
let
limit_keys_lens
:
Vec
<
_
>
=
ranges
.iter
()
.map
(|
x
|
x
.end_key
.len
())
.collect
();
unsafe
{
unsafe
{
let
props
=
new_table_properties_collection
();
let
props
=
ffi_try!
(
crocksdb_get_properties_of_tables_in_range
(
self
.inner
,
ffi_try!
(
crocksdb_get_properties_of_tables_in_range
(
self
.inner
,
cf
.inner
,
cf
.inner
,
ranges
.len
()
as
i32
,
ranges
.len
()
as
i32
,
start_keys
.as_ptr
(),
start_keys
.as_ptr
(),
start_keys_lens
.as_ptr
(),
start_keys_lens
.as_ptr
(),
limit_keys
.as_ptr
(),
limit_keys
.as_ptr
(),
limit_keys_lens
.as_ptr
(),
limit_keys_lens
.as_ptr
()));
props
.inner
));
Ok
(
TablePropertiesCollection
::
from_raw
(
props
))
Ok
(
props
)
}
}
}
}
}
}
...
...
src/table_properties.rs
View file @
a50c0841
...
@@ -11,20 +11,18 @@
...
@@ -11,20 +11,18 @@
// 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
,
DBTableProperties
,
DBTableProperty
,
DBUserCollectedPropertiesIterator
,
use
crocksdb_ffi
::{
self
,
DBTableProperties
,
DBTableProperty
,
DBUserCollectedPropertiesIterator
,
DBTablePropertiesCollection
,
DBTablePropertiesCollectionIterator
};
DBTablePropertiesCollection
,
DBTablePropertiesCollectionIterator
,
DBUserCollectedProperties
};
use
libc
::
size_t
;
use
libc
::
size_t
;
use
std
::
collections
::
HashMap
;
use
std
::
{
slice
,
str
,
mem
}
;
use
std
::
marker
::
PhantomData
;
use
std
::
marker
::
PhantomData
;
use
std
::
slice
;
use
std
::
ops
::
Index
;
use
std
::
str
;
pub
fn
new_table_properties_collection
()
->
TablePropertiesCollection
{
TablePropertiesCollection
::
new
()
}
pub
struct
TablePropertiesCollection
{
pub
struct
TablePropertiesCollection
{
pub
inner
:
*
mut
DBTablePropertiesCollection
,
inner
:
*
mut
DBTablePropertiesCollection
,
}
}
impl
Drop
for
TablePropertiesCollection
{
impl
Drop
for
TablePropertiesCollection
{
...
@@ -36,22 +34,29 @@ impl Drop for TablePropertiesCollection {
...
@@ -36,22 +34,29 @@ impl Drop for TablePropertiesCollection {
}
}
impl
TablePropertiesCollection
{
impl
TablePropertiesCollection
{
fn
new
()
->
TablePropertiesCollection
{
pub
unsafe
fn
from_raw
(
ptr
:
*
mut
DBTablePropertiesCollection
)
->
TablePropertiesCollection
{
unsafe
{
TablePropertiesCollection
{
inner
:
ptr
}
TablePropertiesCollection
{
inner
:
crocksdb_ffi
::
crocksdb_table_properties_collection_create
(),
}
}
}
}
pub
fn
collect
(
&
self
)
->
HashMap
<&
str
,
TableProperties
>
{
pub
fn
iter
(
&
self
)
->
TablePropertiesCollectionIter
{
let
mut
res
=
HashMap
::
new
();
self
.into_iter
()
let
mut
iter
=
TablePropertiesCollectionIter
::
new
(
self
);
}
while
iter
.valid
()
{
res
.insert
(
iter
.key
(),
iter
.value
());
pub
fn
len
(
&
self
)
->
usize
{
iter
.next
();
unsafe
{
crocksdb_ffi
::
crocksdb_table_properties_collection_len
(
self
.inner
)
}
}
}
res
pub
fn
is_empty
(
&
self
)
->
bool
{
self
.len
()
==
0
}
}
impl
<
'a
>
IntoIterator
for
&
'a
TablePropertiesCollection
{
type
Item
=
(
&
'a
str
,
&
'a
TableProperties
);
type
IntoIter
=
TablePropertiesCollectionIter
<
'a
>
;
fn
into_iter
(
self
)
->
Self
::
IntoIter
{
TablePropertiesCollectionIter
::
new
(
self
)
}
}
}
}
...
@@ -77,61 +82,50 @@ impl<'a> TablePropertiesCollectionIter<'a> {
...
@@ -77,61 +82,50 @@ impl<'a> TablePropertiesCollectionIter<'a> {
}
}
}
}
}
}
}
pub
fn
valid
(
&
self
)
->
bool
{
impl
<
'a
>
Iterator
for
TablePropertiesCollectionIter
<
'a
>
{
unsafe
{
crocksdb_ffi
::
crocksdb_table_properties_collection_iter_valid
(
self
.inner
)
}
type
Item
=
(
&
'a
str
,
&
'a
TableProperties
);
}
pub
fn
next
(
&
mut
self
)
{
fn
next
(
&
mut
self
)
->
Option
<
(
&
'a
str
,
&
'a
TableProperties
)
>
{
unsafe
{
unsafe
{
crocksdb_ffi
::
crocksdb_table_properties_collection_iter_next
(
self
.inner
);
if
!
crocksdb_ffi
::
crocksdb_table_properties_collection_iter_valid
(
self
.inner
)
{
}
return
None
;
}
}
pub
fn
key
(
&
self
)
->
&
'a
str
{
unsafe
{
let
mut
klen
:
size_t
=
0
;
let
mut
klen
:
size_t
=
0
;
let
k
=
crocksdb_ffi
::
crocksdb_table_properties_collection_iter_key
(
self
.inner
,
let
k
=
crocksdb_ffi
::
crocksdb_table_properties_collection_iter_key
(
self
.inner
,
&
mut
klen
);
&
mut
klen
);
let
bytes
=
slice
::
from_raw_parts
(
k
,
klen
);
let
bytes
=
slice
::
from_raw_parts
(
k
,
klen
);
str
::
from_utf8
(
bytes
)
.unwrap
()
let
key
=
str
::
from_utf8
(
bytes
)
.unwrap
();
}
let
props
=
crocksdb_ffi
::
crocksdb_table_properties_collection_iter_value
(
self
.inner
);
}
let
val
=
TableProperties
::
from_ptr
(
props
);
crocksdb_ffi
::
crocksdb_table_properties_collection_iter_next
(
self
.inner
);
pub
fn
value
(
&
self
)
->
TableProperties
{
Some
((
key
,
val
))
unsafe
{
let
props
=
TableProperties
::
new
();
crocksdb_ffi
::
crocksdb_table_properties_collection_iter_value
(
self
.inner
,
props
.inner
);
props
}
}
}
}
}
}
pub
struct
TableProperties
{
pub
struct
TableProperties
{
inner
:
*
mut
DBTableProperties
,
inner
:
DBTableProperties
,
}
}
impl
Drop
for
TableProperties
{
impl
TableProperties
{
fn
drop
(
&
mut
self
)
{
fn
from_ptr
<
'a
>
(
ptr
:
*
const
DBTableProperties
)
->
&
'a
TableProperties
{
unsafe
{
unsafe
{
crocksdb_ffi
::
crocksdb_table_properties_destroy
(
self
.inner
);
let
res
=
&*
ptr
;
mem
::
transmute
(
res
)
}
}
}
}
}
impl
TableProperties
{
fn
new
()
->
TableProperties
{
unsafe
{
TableProperties
{
inner
:
crocksdb_ffi
::
crocksdb_table_properties_create
()
}
}
}
fn
get_u64
(
&
self
,
prop
:
DBTableProperty
)
->
u64
{
fn
get_u64
(
&
self
,
prop
:
DBTableProperty
)
->
u64
{
unsafe
{
crocksdb_ffi
::
crocksdb_table_properties_get_u64
(
self
.inner
,
prop
)
}
unsafe
{
crocksdb_ffi
::
crocksdb_table_properties_get_u64
(
&
self
.inner
,
prop
)
}
}
}
fn
get_str
(
&
self
,
prop
:
DBTableProperty
)
->
&
str
{
fn
get_str
(
&
self
,
prop
:
DBTableProperty
)
->
&
str
{
unsafe
{
unsafe
{
let
mut
slen
:
size_t
=
0
;
let
mut
slen
:
size_t
=
0
;
let
s
=
crocksdb_ffi
::
crocksdb_table_properties_get_str
(
self
.inner
,
prop
,
&
mut
slen
);
let
s
=
crocksdb_ffi
::
crocksdb_table_properties_get_str
(
&
self
.inner
,
prop
,
&
mut
slen
);
let
bytes
=
slice
::
from_raw_parts
(
s
,
slen
);
let
bytes
=
slice
::
from_raw_parts
(
s
,
slen
);
str
::
from_utf8
(
bytes
)
.unwrap
()
str
::
from_utf8
(
bytes
)
.unwrap
()
}
}
...
@@ -205,19 +199,68 @@ impl TableProperties {
...
@@ -205,19 +199,68 @@ impl TableProperties {
self
.get_str
(
DBTableProperty
::
CompressionName
)
self
.get_str
(
DBTableProperty
::
CompressionName
)
}
}
pub
fn
user_collected_properties
(
&
self
)
->
HashMap
<&
[
u8
],
&
[
u8
]
>
{
pub
fn
user_collected_properties
(
&
self
)
->
&
UserCollectedProperties
{
let
mut
res
=
HashMap
::
new
();
unsafe
{
let
mut
iter
=
UserCollectedPropertiesIter
::
new
(
self
);
let
ptr
=
crocksdb_ffi
::
crocksdb_table_properties_get_user_properties
(
&
self
.inner
);
while
iter
.valid
()
{
UserCollectedProperties
::
from_ptr
(
ptr
)
res
.insert
(
iter
.key
(),
iter
.value
());
}
iter
.next
();
}
}
pub
struct
UserCollectedProperties
{
inner
:
DBUserCollectedProperties
,
}
impl
UserCollectedProperties
{
unsafe
fn
from_ptr
<
'a
>
(
ptr
:
*
const
DBUserCollectedProperties
)
->
&
'a
UserCollectedProperties
{
let
prop
=
&*
ptr
;
mem
::
transmute
(
prop
)
}
pub
fn
get
<
Q
:
AsRef
<
[
u8
]
>>
(
&
self
,
index
:
Q
)
->
Option
<&
[
u8
]
>
{
let
bytes
=
index
.as_ref
();
let
mut
size
=
0
;
unsafe
{
let
ptr
=
crocksdb_ffi
::
crocksdb_user_collected_properties_get
(
&
self
.inner
,
bytes
.as_ptr
(),
bytes
.len
(),
&
mut
size
);
if
ptr
.is_null
()
{
return
None
;
}
Some
(
slice
::
from_raw_parts
(
ptr
,
size
))
}
}
res
}
pub
fn
len
(
&
self
)
->
usize
{
unsafe
{
crocksdb_ffi
::
crocksdb_user_collected_properties_len
(
&
self
.inner
)
}
}
pub
fn
is_empty
(
&
self
)
->
bool
{
self
.len
()
==
0
}
}
}
}
struct
UserCollectedPropertiesIter
<
'a
>
{
impl
<
Q
:
AsRef
<
[
u8
]
>>
Index
<
Q
>
for
UserCollectedProperties
{
props
:
PhantomData
<&
'a
TableProperties
>
,
type
Output
=
[
u8
];
fn
index
(
&
self
,
index
:
Q
)
->
&
[
u8
]
{
let
key
=
index
.as_ref
();
self
.get
(
key
)
.unwrap_or_else
(||
panic!
(
"no entry found for key {:?}"
,
key
))
}
}
impl
<
'a
>
IntoIterator
for
&
'a
UserCollectedProperties
{
type
Item
=
(
&
'a
[
u8
],
&
'a
[
u8
]);
type
IntoIter
=
UserCollectedPropertiesIter
<
'a
>
;
fn
into_iter
(
self
)
->
Self
::
IntoIter
{
UserCollectedPropertiesIter
::
new
(
self
)
}
}
pub
struct
UserCollectedPropertiesIter
<
'a
>
{
props
:
PhantomData
<&
'a
UserCollectedProperties
>
,
inner
:
*
mut
DBUserCollectedPropertiesIterator
,
inner
:
*
mut
DBUserCollectedPropertiesIterator
,
}
}
...
@@ -230,41 +273,37 @@ impl<'a> Drop for UserCollectedPropertiesIter<'a> {
...
@@ -230,41 +273,37 @@ impl<'a> Drop for UserCollectedPropertiesIter<'a> {
}
}
impl
<
'a
>
UserCollectedPropertiesIter
<
'a
>
{
impl
<
'a
>
UserCollectedPropertiesIter
<
'a
>
{
fn
new
(
props
:
&
'a
Table
Properties
)
->
UserCollectedPropertiesIter
<
'a
>
{
fn
new
(
props
:
&
'a
UserCollected
Properties
)
->
UserCollectedPropertiesIter
<
'a
>
{
unsafe
{
unsafe
{
let
inner
=
crocksdb_ffi
::
crocksdb_table_properties_get_user_properties
(
props
.inner
);
UserCollectedPropertiesIter
{
UserCollectedPropertiesIter
{
props
:
PhantomData
,
props
:
PhantomData
,
inner
:
crocksdb_ffi
::
crocksdb_user_collected_properties_iter_create
(
inner
),
inner
:
crocksdb_ffi
::
crocksdb_user_collected_properties_iter_create
(
&
props
.
inner
),
}
}
}
}
}
}
}
fn
valid
(
&
self
)
->
bool
{
impl
<
'a
>
Iterator
for
UserCollectedPropertiesIter
<
'a
>
{
unsafe
{
crocksdb_ffi
::
crocksdb_user_collected_properties_iter_valid
(
self
.inner
)
}
type
Item
=
(
&
'a
[
u8
],
&
'a
[
u8
]);
}
fn
next
(
&
mut
self
)
{
fn
next
(
&
mut
self
)
->
Option
<
(
&
'a
[
u8
],
&
'a
[
u8
])
>
{
unsafe
{
crocksdb_ffi
::
crocksdb_user_collected_properties_iter_next
(
self
.inner
);
}
}
fn
key
(
&
self
)
->
&
'a
[
u8
]
{
unsafe
{
unsafe
{
if
!
crocksdb_ffi
::
crocksdb_user_collected_properties_iter_valid
(
self
.inner
)
{
return
None
;
}
let
mut
klen
:
size_t
=
0
;
let
mut
klen
:
size_t
=
0
;
let
k
=
crocksdb_ffi
::
crocksdb_user_collected_properties_iter_key
(
self
.inner
,
let
k
=
crocksdb_ffi
::
crocksdb_user_collected_properties_iter_key
(
self
.inner
,
&
mut
klen
);
&
mut
klen
);
slice
::
from_raw_parts
(
k
,
klen
)
let
key
=
slice
::
from_raw_parts
(
k
,
klen
);
}
}
fn
value
(
&
self
)
->
&
'a
[
u8
]
{
unsafe
{
let
mut
vlen
:
size_t
=
0
;
let
mut
vlen
:
size_t
=
0
;
let
v
=
crocksdb_ffi
::
crocksdb_user_collected_properties_iter_value
(
self
.inner
,
let
v
=
crocksdb_ffi
::
crocksdb_user_collected_properties_iter_value
(
self
.inner
,
&
mut
vlen
);
&
mut
vlen
);
slice
::
from_raw_parts
(
v
,
vlen
)
let
val
=
slice
::
from_raw_parts
(
v
,
vlen
);
crocksdb_ffi
::
crocksdb_user_collected_properties_iter_next
(
self
.inner
);
Some
((
key
,
val
))
}
}
}
}
}
}
tests/test_table_properties.rs
View file @
a50c0841
...
@@ -13,7 +13,7 @@
...
@@ -13,7 +13,7 @@
use
byteorder
::{
LittleEndian
,
ReadBytesExt
,
WriteBytesExt
};
use
byteorder
::{
LittleEndian
,
ReadBytesExt
,
WriteBytesExt
};
use
rocksdb
::{
DB
,
Range
,
Options
,
Writable
,
DBEntryType
,
TablePropertiesCollection
,
use
rocksdb
::{
DB
,
Range
,
Options
,
Writable
,
DBEntryType
,
TablePropertiesCollection
,
TablePropertiesCollector
,
TablePropertiesCollectorFactory
};
TablePropertiesCollector
,
TablePropertiesCollectorFactory
,
UserCollectedProperties
};
use
std
::
collections
::
HashMap
;
use
std
::
collections
::
HashMap
;
use
std
::
fmt
;
use
std
::
fmt
;
use
tempdir
::
TempDir
;
use
tempdir
::
TempDir
;
...
@@ -70,12 +70,20 @@ impl ExampleCollector {
...
@@ -70,12 +70,20 @@ impl ExampleCollector {
props
props
}
}
fn
decode
(
props
:
HashMap
<&
[
u8
],
&
[
u8
]
>
)
->
ExampleCollector
{
fn
decode
(
props
:
&
UserCollectedProperties
)
->
ExampleCollector
{
assert
!
(
!
props
.is_empty
());
let
mut
c
=
ExampleCollector
::
new
();
let
mut
c
=
ExampleCollector
::
new
();
c
.num_keys
=
decode_u32
(
props
.get
(
&
[
Props
::
NumKeys
as
u8
]
.as_ref
())
.unwrap
());
c
.num_keys
=
decode_u32
(
&
props
[
&
[
Props
::
NumKeys
as
u8
]]);
c
.num_puts
=
decode_u32
(
props
.get
(
&
[
Props
::
NumPuts
as
u8
]
.as_ref
())
.unwrap
());
c
.num_puts
=
decode_u32
(
&
props
[
&
[
Props
::
NumPuts
as
u8
]]);
c
.num_merges
=
decode_u32
(
props
.get
(
&
[
Props
::
NumMerges
as
u8
]
.as_ref
())
.unwrap
());
c
.num_merges
=
decode_u32
(
&
props
[
&
[
Props
::
NumMerges
as
u8
]]);
c
.num_deletes
=
decode_u32
(
props
.get
(
&
[
Props
::
NumDeletes
as
u8
]
.as_ref
())
.unwrap
());
c
.num_deletes
=
decode_u32
(
&
props
[
&
[
Props
::
NumDeletes
as
u8
]]);
for
(
k
,
v
)
in
props
{
assert_eq!
(
v
,
props
.get
(
k
)
.unwrap
());
}
assert
!
(
props
.get
(
&
[
Props
::
NumKeys
as
u8
,
Props
::
NumPuts
as
u8
])
.is_none
());
assert
!
(
props
.len
()
>=
4
);
c
c
}
}
}
}
...
@@ -133,7 +141,9 @@ fn check_collection(collection: &TablePropertiesCollection,
...
@@ -133,7 +141,9 @@ fn check_collection(collection: &TablePropertiesCollection,
num_merges
:
u32
,
num_merges
:
u32
,
num_deletes
:
u32
)
{
num_deletes
:
u32
)
{
let
mut
res
=
ExampleCollector
::
new
();
let
mut
res
=
ExampleCollector
::
new
();
let
props
=
collection
.collect
();
assert
!
(
!
collection
.is_empty
());
let
props
:
HashMap
<
_
,
_
>
=
collection
.iter
()
.collect
();
assert_eq!
(
props
.len
(),
collection
.len
());
for
(
k
,
v
)
in
&
props
{
for
(
k
,
v
)
in
&
props
{
assert
!
(
k
.ends_with
(
".sst"
));
assert
!
(
k
.ends_with
(
".sst"
));
assert_eq!
(
v
.property_collectors_names
(),
"[example-collector]"
);
assert_eq!
(
v
.property_collectors_names
(),
"[example-collector]"
);
...
...
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