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
d7acfb70
Commit
d7acfb70
authored
Jul 01, 2017
by
Huachao Huang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fetch properties lazily
parent
0fe7d360
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
21 deletions
+33
-21
rocksdb.rs
src/rocksdb.rs
+10
-10
table_properties.rs
src/table_properties.rs
+0
-0
test_table_properties.rs
tests/test_table_properties.rs
+23
-11
No files found.
src/rocksdb.rs
View file @
d7acfb70
...
...
@@ -35,7 +35,7 @@ pub struct CFHandle {
}
impl
CFHandle
{
pub
fn
get_
id
(
&
self
)
->
u32
{
pub
fn
id
(
&
self
)
->
u32
{
unsafe
{
crocksdb_ffi
::
crocksdb_column_family_handle_get_id
(
self
.inner
)
}
}
}
...
...
@@ -1047,9 +1047,9 @@ impl DB {
pub
fn
get_properties_of_all_tables
(
&
self
)
->
Result
<
TablePropertiesCollection
,
String
>
{
unsafe
{
let
props
=
TablePropertiesCollectionHandle
::
new
();
ffi_try!
(
crocksdb_get_properties_of_all_tables
(
self
.inner
,
props
.inner
));
props
.normalize
(
)
let
handle
=
TablePropertiesCollectionHandle
::
new
();
ffi_try!
(
crocksdb_get_properties_of_all_tables
(
self
.inner
,
handle
.inner
));
Ok
(
TablePropertiesCollection
::
new
(
handle
)
)
}
}
...
...
@@ -1057,9 +1057,9 @@ impl DB {
cf
:
&
CFHandle
)
->
Result
<
TablePropertiesCollection
,
String
>
{
unsafe
{
let
props
=
TablePropertiesCollectionHandle
::
new
();
ffi_try!
(
crocksdb_get_properties_of_all_tables_cf
(
self
.inner
,
cf
.inner
,
props
.inner
));
props
.normalize
(
)
let
handle
=
TablePropertiesCollectionHandle
::
new
();
ffi_try!
(
crocksdb_get_properties_of_all_tables_cf
(
self
.inner
,
cf
.inner
,
handle
.inner
));
Ok
(
TablePropertiesCollection
::
new
(
handle
)
)
}
}
...
...
@@ -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
props
=
TablePropertiesCollectionHandle
::
new
();
let
handle
=
TablePropertiesCollectionHandle
::
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
(),
props
.inner
));
props
.normalize
(
)
handle
.inner
));
Ok
(
TablePropertiesCollection
::
new
(
handle
)
)
}
}
}
...
...
src/table_properties.rs
View file @
d7acfb70
This diff is collapsed.
Click to expand it.
tests/test_table_properties.rs
View file @
d7acfb70
...
...
@@ -16,6 +16,7 @@ use rocksdb::{DB, Range, Options, Writable, DBEntryType, TablePropertiesCollecti
TablePropertiesCollector
,
TablePropertiesCollectorFactory
};
use
std
::
cmp
::
Ordering
;
use
std
::
collections
::
HashMap
;
use
std
::
ffi
::
CString
;
use
std
::
fmt
;
use
std
::
io
::
Cursor
;
use
tempdir
::
TempDir
;
...
...
@@ -39,6 +40,7 @@ fn decode_u32(x: &[u8]) -> u32 {
}
struct
ExampleCollector
{
name
:
CString
,
num_keys
:
u32
,
num_puts
:
u32
,
num_merges
:
u32
,
...
...
@@ -49,6 +51,7 @@ struct ExampleCollector {
impl
ExampleCollector
{
fn
new
()
->
ExampleCollector
{
ExampleCollector
{
name
:
CString
::
new
(
"example-collector"
)
.unwrap
(),
num_keys
:
0
,
num_puts
:
0
,
num_merges
:
0
,
...
...
@@ -95,11 +98,11 @@ impl fmt::Display for ExampleCollector {
}
impl
TablePropertiesCollector
for
ExampleCollector
{
fn
name
(
&
self
)
->
&
str
{
"example-collector"
fn
name
(
&
self
)
->
&
CString
{
&
self
.name
}
fn
add_userkey
(
&
mut
self
,
key
:
&
[
u8
],
_
:
&
[
u8
],
entry_type
:
DBEntryType
)
{
fn
add_userkey
(
&
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
();
...
...
@@ -119,17 +122,19 @@ impl TablePropertiesCollector for ExampleCollector {
}
}
struct
ExampleFactory
{}
struct
ExampleFactory
{
name
:
CString
,
}
impl
ExampleFactory
{
fn
new
()
->
ExampleFactory
{
ExampleFactory
{}
ExampleFactory
{
name
:
CString
::
new
(
"example-factory"
)
.unwrap
()
}
}
}
impl
TablePropertiesCollectorFactory
for
ExampleFactory
{
fn
name
(
&
self
)
->
&
str
{
"example-factory"
fn
name
(
&
self
)
->
&
CString
{
&
self
.name
}
fn
create_table_properties_collector
(
&
mut
self
,
_
:
u32
)
->
Box
<
TablePropertiesCollector
>
{
...
...
@@ -143,12 +148,19 @@ fn check_collection(collection: &TablePropertiesCollection,
num_puts
:
u32
,
num_merges
:
u32
,
num_deletes
:
u32
)
{
let
mut
len
=
0
;
let
mut
res
=
ExampleCollector
::
new
();
for
(
_
,
props
)
in
collection
{
assert_eq!
(
props
.property_collectors_names
,
"[example-factory]"
);
res
.add
(
&
ExampleCollector
::
decode
(
&
props
.user_collected_properties
));
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
();
}
assert_eq!
(
collection
.len
()
as
u32
,
num_files
);
assert_eq!
(
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