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
9722aa63
Commit
9722aa63
authored
Jul 04, 2017
by
Huachao Huang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
address comment
parent
0eda4b6f
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
35 additions
and
52 deletions
+35
-52
c.cc
librocksdb_sys/crocksdb/c.cc
+13
-21
rocksdb.rs
src/rocksdb.rs
+10
-10
table_properties.rs
src/table_properties.rs
+10
-17
table_properties_collector.rs
src/table_properties_collector.rs
+1
-2
test_table_properties.rs
tests/test_table_properties.rs
+1
-2
No files found.
librocksdb_sys/crocksdb/c.cc
View file @
9722aa63
...
...
@@ -3023,25 +3023,25 @@ const char* crocksdb_table_properties_get_str(crocksdb_table_properties_t* props
auto
rep
=
props
->
rep_
;
switch
(
prop
)
{
case
kColumnFamilyName
:
if
(
slen
)
*
slen
=
rep
->
column_family_name
.
size
();
*
slen
=
rep
->
column_family_name
.
size
();
return
rep
->
column_family_name
.
data
();
case
kFilterPolicyName
:
if
(
slen
)
*
slen
=
rep
->
filter_policy_name
.
size
();
*
slen
=
rep
->
filter_policy_name
.
size
();
return
rep
->
filter_policy_name
.
data
();
case
kComparatorName
:
if
(
slen
)
*
slen
=
rep
->
comparator_name
.
size
();
*
slen
=
rep
->
comparator_name
.
size
();
return
rep
->
comparator_name
.
data
();
case
kMergeOperatorName
:
if
(
slen
)
*
slen
=
rep
->
merge_operator_name
.
size
();
*
slen
=
rep
->
merge_operator_name
.
size
();
return
rep
->
merge_operator_name
.
data
();
case
kPrefixExtractorName
:
if
(
slen
)
*
slen
=
rep
->
prefix_extractor_name
.
size
();
*
slen
=
rep
->
prefix_extractor_name
.
size
();
return
rep
->
prefix_extractor_name
.
data
();
case
kPropertyCollectorsNames
:
if
(
slen
)
*
slen
=
rep
->
property_collectors_names
.
size
();
*
slen
=
rep
->
property_collectors_names
.
size
();
return
rep
->
property_collectors_names
.
data
();
case
kCompressionName
:
if
(
slen
)
*
slen
=
rep
->
compression_name
.
size
();
*
slen
=
rep
->
compression_name
.
size
();
return
rep
->
compression_name
.
data
();
}
return
nullptr
;
...
...
@@ -3055,15 +3055,7 @@ crocksdb_table_properties_get_user_properties(crocksdb_table_properties_t* props
/* Table Properties Collection */
struct
crocksdb_table_properties_collection_t
{
TablePropertiesCollection
*
rep_
=
nullptr
;
crocksdb_table_properties_collection_t
()
{
rep_
=
new
TablePropertiesCollection
;
}
~
crocksdb_table_properties_collection_t
()
{
delete
rep_
;
}
TablePropertiesCollection
rep_
;
};
crocksdb_table_properties_collection_t
*
...
...
@@ -3085,8 +3077,8 @@ crocksdb_table_properties_collection_iterator_t*
crocksdb_table_properties_collection_iter_create
(
crocksdb_table_properties_collection_t
*
collection
)
{
auto
it
=
new
crocksdb_table_properties_collection_iterator_t
;
it
->
cur_
=
collection
->
rep_
->
begin
();
it
->
end_
=
collection
->
rep_
->
end
();
it
->
cur_
=
collection
->
rep_
.
begin
();
it
->
end_
=
collection
->
rep_
.
end
();
return
it
;
}
...
...
@@ -3237,7 +3229,7 @@ void crocksdb_options_add_table_properties_collector_factory(
void
crocksdb_get_properties_of_all_tables
(
crocksdb_t
*
db
,
crocksdb_table_properties_collection_t
*
props
,
char
**
errptr
)
{
auto
s
=
db
->
rep
->
GetPropertiesOfAllTables
(
props
->
rep_
);
auto
s
=
db
->
rep
->
GetPropertiesOfAllTables
(
&
props
->
rep_
);
if
(
!
s
.
ok
())
{
SaveError
(
errptr
,
s
);
}
...
...
@@ -3246,7 +3238,7 @@ void crocksdb_get_properties_of_all_tables(crocksdb_t* db,
void
crocksdb_get_properties_of_all_tables_cf
(
crocksdb_t
*
db
,
crocksdb_column_family_handle_t
*
cf
,
crocksdb_table_properties_collection_t
*
props
,
char
**
errptr
)
{
auto
s
=
db
->
rep
->
GetPropertiesOfAllTables
(
cf
->
rep
,
props
->
rep_
);
auto
s
=
db
->
rep
->
GetPropertiesOfAllTables
(
cf
->
rep
,
&
props
->
rep_
);
if
(
!
s
.
ok
())
{
SaveError
(
errptr
,
s
);
}
...
...
@@ -3266,7 +3258,7 @@ void crocksdb_get_properties_of_tables_in_range(
auto
s
=
db
->
rep
->
GetPropertiesOfTablesInRange
(
cf
->
rep
,
ranges
.
data
(),
ranges
.
size
(),
props
->
rep_
);
&
props
->
rep_
);
if
(
!
s
.
ok
())
{
SaveError
(
errptr
,
s
);
}
...
...
src/rocksdb.rs
View file @
9722aa63
...
...
@@ -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
,
new_table_properties_collection
};
const
DEFAULT_COLUMN_FAMILY
:
&
'static
str
=
"default"
;
...
...
@@ -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
=
new_table_properties_collection
();
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
=
new_table_properties_collection
();
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
=
new_table_properties_collection
();
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 @
9722aa63
...
...
@@ -19,11 +19,15 @@ use std::marker::PhantomData;
use
std
::
slice
;
use
std
::
str
;
pub
struct
TablePropertiesCollectionHandle
{
pub
fn
new_table_properties_collection
()
->
TablePropertiesCollection
{
TablePropertiesCollection
::
new
()
}
pub
struct
TablePropertiesCollection
{
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
);
...
...
@@ -31,24 +35,14 @@ impl Drop for TablePropertiesCollectionHandle {
}
}
impl
TablePropertiesCollection
Handle
{
pub
fn
new
()
->
TablePropertiesCollectionHandle
{
impl
TablePropertiesCollection
{
fn
new
()
->
TablePropertiesCollection
{
unsafe
{
TablePropertiesCollection
Handle
{
TablePropertiesCollection
{
inner
:
crocksdb_ffi
::
crocksdb_table_properties_collection_create
(),
}
}
}
}
pub
struct
TablePropertiesCollection
{
handle
:
TablePropertiesCollectionHandle
,
}
impl
TablePropertiesCollection
{
pub
fn
new
(
handle
:
TablePropertiesCollectionHandle
)
->
TablePropertiesCollection
{
TablePropertiesCollection
{
handle
:
handle
}
}
pub
fn
collect
(
&
self
)
->
HashMap
<&
str
,
TableProperties
>
{
let
mut
res
=
HashMap
::
new
();
...
...
@@ -77,10 +71,9 @@ impl<'a> Drop for TablePropertiesCollectionIter<'a> {
impl
<
'a
>
TablePropertiesCollectionIter
<
'a
>
{
fn
new
(
props
:
&
'a
TablePropertiesCollection
)
->
TablePropertiesCollectionIter
<
'a
>
{
unsafe
{
let
inner
=
props
.handle.inner
;
TablePropertiesCollectionIter
{
props
:
PhantomData
,
inner
:
crocksdb_ffi
::
crocksdb_table_properties_collection_iter_create
(
inner
),
inner
:
crocksdb_ffi
::
crocksdb_table_properties_collection_iter_create
(
props
.
inner
),
}
}
}
...
...
src/table_properties_collector.rs
View file @
9722aa63
...
...
@@ -61,8 +61,7 @@ extern "C" fn name(handle: *mut c_void) -> *const c_char {
extern
"C"
fn
destruct
(
handle
:
*
mut
c_void
)
{
unsafe
{
let
handle
=
&
mut
*
(
handle
as
*
mut
TablePropertiesCollectorHandle
);
Box
::
from_raw
(
handle
);
Box
::
from_raw
(
handle
as
*
mut
TablePropertiesCollectorHandle
);
}
}
...
...
tests/test_table_properties.rs
View file @
9722aa63
...
...
@@ -14,7 +14,6 @@
use
byteorder
::{
LittleEndian
,
ReadBytesExt
,
WriteBytesExt
};
use
rocksdb
::{
DB
,
Range
,
Options
,
Writable
,
DBEntryType
,
TablePropertiesCollection
,
TablePropertiesCollector
,
TablePropertiesCollectorFactory
};
use
std
::
cmp
::
Ordering
;
use
std
::
collections
::
HashMap
;
use
std
::
fmt
;
use
tempdir
::
TempDir
;
...
...
@@ -94,7 +93,7 @@ impl fmt::Display for ExampleCollector {
impl
TablePropertiesCollector
for
ExampleCollector
{
fn
add
(
&
mut
self
,
key
:
&
[
u8
],
_
:
&
[
u8
],
entry_type
:
DBEntryType
,
_
:
u64
,
_
:
u64
)
{
if
key
.cmp
(
&
self
.last_key
)
!=
Ordering
::
Equal
{
if
key
!=
self
.last_key
.as_slice
()
{
self
.num_keys
+=
1
;
self
.last_key
.clear
();
self
.last_key
.extend_from_slice
(
key
);
...
...
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