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
fcf0dfd6
Commit
fcf0dfd6
authored
Jun 01, 2017
by
zhangjinpeng1987
Committed by
GitHub
Jun 01, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
export get pinnable slice (#62)
parent
328fa017
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
99 additions
and
39 deletions
+99
-39
c.cc
librocksdb_sys/crocksdb/c.cc
+43
-0
c.h
librocksdb_sys/crocksdb/rocksdb/c.h
+18
-4
lib.rs
librocksdb_sys/src/lib.rs
+19
-0
rocksdb.rs
src/rocksdb.rs
+19
-35
No files found.
librocksdb_sys/crocksdb/c.cc
View file @
fcf0dfd6
...
...
@@ -80,6 +80,7 @@ using rocksdb::CompactRangeOptions;
using
rocksdb
::
RateLimiter
;
using
rocksdb
::
NewGenericRateLimiter
;
using
rocksdb
::
HistogramData
;
using
rocksdb
::
PinnableSlice
;
using
std
::
shared_ptr
;
...
...
@@ -120,6 +121,7 @@ struct crocksdb_ingestexternalfileoptions_t { IngestExternalFileOptions rep; };
struct
crocksdb_sstfilewriter_t
{
SstFileWriter
*
rep
;
};
struct
crocksdb_ratelimiter_t
{
RateLimiter
*
rep
;
};
struct
crocksdb_histogramdata_t
{
HistogramData
rep
;
};
struct
crocksdb_pinnableslice_t
{
PinnableSlice
rep
;
};
struct
crocksdb_compactionfiltercontext_t
{
CompactionFilter
::
Context
rep
;
...
...
@@ -2853,4 +2855,45 @@ crocksdb_logger_t *crocksdb_create_log_from_options(const char *path,
void
crocksdb_log_destroy
(
crocksdb_logger_t
*
logger
)
{
delete
logger
;
}
crocksdb_pinnableslice_t
*
crocksdb_get_pinned
(
crocksdb_t
*
db
,
const
crocksdb_readoptions_t
*
options
,
const
char
*
key
,
size_t
keylen
,
char
**
errptr
)
{
crocksdb_pinnableslice_t
*
v
=
new
(
crocksdb_pinnableslice_t
);
Status
s
=
db
->
rep
->
Get
(
options
->
rep
,
db
->
rep
->
DefaultColumnFamily
(),
Slice
(
key
,
keylen
),
&
v
->
rep
);
if
(
!
s
.
ok
())
{
delete
(
v
);
if
(
!
s
.
IsNotFound
())
{
SaveError
(
errptr
,
s
);
}
return
NULL
;
}
return
v
;
}
crocksdb_pinnableslice_t
*
crocksdb_get_pinned_cf
(
crocksdb_t
*
db
,
const
crocksdb_readoptions_t
*
options
,
crocksdb_column_family_handle_t
*
column_family
,
const
char
*
key
,
size_t
keylen
,
char
**
errptr
)
{
crocksdb_pinnableslice_t
*
v
=
new
(
crocksdb_pinnableslice_t
);
Status
s
=
db
->
rep
->
Get
(
options
->
rep
,
column_family
->
rep
,
Slice
(
key
,
keylen
),
&
v
->
rep
);
if
(
!
s
.
ok
())
{
delete
v
;
if
(
!
s
.
IsNotFound
())
{
SaveError
(
errptr
,
s
);
}
return
NULL
;
}
return
v
;
}
void
crocksdb_pinnableslice_destroy
(
crocksdb_pinnableslice_t
*
v
)
{
delete
v
;
}
const
char
*
crocksdb_pinnableslice_value
(
const
crocksdb_pinnableslice_t
*
v
,
size_t
*
vlen
)
{
// v can't be null.
*
vlen
=
v
->
rep
.
size
();
return
v
->
rep
.
data
();
}
}
// end extern "C"
librocksdb_sys/crocksdb/rocksdb/c.h
View file @
fcf0dfd6
...
...
@@ -110,6 +110,7 @@ typedef struct crocksdb_envoptions_t crocksdb_envoptions_t;
typedef
struct
crocksdb_ingestexternalfileoptions_t
crocksdb_ingestexternalfileoptions_t
;
typedef
struct
crocksdb_sstfilewriter_t
crocksdb_sstfilewriter_t
;
typedef
struct
crocksdb_ratelimiter_t
crocksdb_ratelimiter_t
;
typedef
struct
crocksdb_pinnableslice_t
crocksdb_pinnableslice_t
;
/* DB operations */
...
...
@@ -404,8 +405,8 @@ extern C_ROCKSDB_LIBRARY_API void crocksdb_iter_get_error(
/* Write batch */
extern
C_ROCKSDB_LIBRARY_API
crocksdb_writebatch_t
*
crocksdb_writebatch_create
();
extern
C_ROCKSDB_LIBRARY_API
crocksdb_writebatch_t
*
crocksdb_writebatch_create_with_capacity
(
size_t
reserved_bytes
);
extern
C_ROCKSDB_LIBRARY_API
crocksdb_writebatch_t
*
crocksdb_writebatch_create_with_capacity
(
size_t
reserved_bytes
);
extern
C_ROCKSDB_LIBRARY_API
crocksdb_writebatch_t
*
crocksdb_writebatch_create_from
(
const
char
*
rep
,
size_t
size
);
extern
C_ROCKSDB_LIBRARY_API
void
crocksdb_writebatch_destroy
(
...
...
@@ -793,8 +794,8 @@ extern C_ROCKSDB_LIBRARY_API void crocksdb_options_set_report_bg_io_stats(
crocksdb_options_t
*
,
int
);
extern
C_ROCKSDB_LIBRARY_API
void
crocksdb_options_set_compaction_readahead_size
(
crocksdb_options_t
*
,
size_t
);
extern
C_ROCKSDB_LIBRARY_API
void
crocksdb_options_set_max_subcompactions
(
crocksdb_options_t
*
,
uint32_t
);
extern
C_ROCKSDB_LIBRARY_API
void
crocksdb_options_set_max_subcompactions
(
crocksdb_options_t
*
,
uint32_t
);
extern
C_ROCKSDB_LIBRARY_API
void
crocksdb_options_set_wal_bytes_per_sync
(
crocksdb_options_t
*
,
uint64_t
);
...
...
@@ -1148,6 +1149,19 @@ extern C_ROCKSDB_LIBRARY_API crocksdb_logger_t *
crocksdb_create_log_from_options
(
const
char
*
path
,
crocksdb_options_t
*
opts
,
char
**
errptr
);
extern
C_ROCKSDB_LIBRARY_API
void
crocksdb_log_destroy
(
crocksdb_logger_t
*
);
extern
C_ROCKSDB_LIBRARY_API
crocksdb_pinnableslice_t
*
crocksdb_get_pinned
(
crocksdb_t
*
db
,
const
crocksdb_readoptions_t
*
options
,
const
char
*
key
,
size_t
keylen
,
char
**
errptr
);
extern
C_ROCKSDB_LIBRARY_API
crocksdb_pinnableslice_t
*
crocksdb_get_pinned_cf
(
crocksdb_t
*
db
,
const
crocksdb_readoptions_t
*
options
,
crocksdb_column_family_handle_t
*
column_family
,
const
char
*
key
,
size_t
keylen
,
char
**
errptr
);
extern
C_ROCKSDB_LIBRARY_API
void
crocksdb_pinnableslice_destroy
(
crocksdb_pinnableslice_t
*
v
);
extern
C_ROCKSDB_LIBRARY_API
const
char
*
crocksdb_pinnableslice_value
(
const
crocksdb_pinnableslice_t
*
t
,
size_t
*
vlen
);
#ifdef __cplusplus
}
/* end extern "C" */
#endif
...
...
librocksdb_sys/src/lib.rs
View file @
fcf0dfd6
...
...
@@ -44,6 +44,7 @@ pub enum DBSliceTransform {}
pub
enum
DBRateLimiter
{}
pub
enum
DBLogger
{}
pub
enum
DBCompactOptions
{}
pub
enum
DBPinnableSlice
{}
pub
fn
new_bloom_filter
(
bits
:
c_int
)
->
*
mut
DBFilterPolicy
{
unsafe
{
crocksdb_filterpolicy_create_bloom
(
bits
)
}
...
...
@@ -764,6 +765,24 @@ extern "C" {
err
:
*
mut
*
mut
c_char
)
->
*
mut
DBLogger
;
pub
fn
crocksdb_log_destroy
(
logger
:
*
mut
DBLogger
);
pub
fn
crocksdb_get_pinned
(
db
:
*
mut
DBInstance
,
readopts
:
*
const
DBReadOptions
,
k
:
*
const
u8
,
kLen
:
size_t
,
err
:
*
mut
*
mut
c_char
)
->
*
mut
DBPinnableSlice
;
pub
fn
crocksdb_get_pinned_cf
(
db
:
*
mut
DBInstance
,
readopts
:
*
const
DBReadOptions
,
cf_handle
:
*
mut
DBCFHandle
,
k
:
*
const
u8
,
kLen
:
size_t
,
err
:
*
mut
*
mut
c_char
)
->
*
mut
DBPinnableSlice
;
pub
fn
crocksdb_pinnableslice_value
(
s
:
*
const
DBPinnableSlice
,
valLen
:
*
mut
size_t
)
->
*
const
u8
;
pub
fn
crocksdb_pinnableslice_destroy
(
v
:
*
mut
DBPinnableSlice
);
}
#[cfg(test)]
...
...
src/rocksdb.rs
View file @
fcf0dfd6
...
...
@@ -14,7 +14,7 @@
//
use
crocksdb_ffi
::{
self
,
DBWriteBatch
,
DBCFHandle
,
DBInstance
,
DBBackupEngine
,
DBStatisticsTickerType
,
DBStatisticsHistogramType
};
DBStatisticsTickerType
,
DBStatisticsHistogramType
,
DBPinnableSlice
};
use
libc
::{
self
,
c_int
,
c_void
,
size_t
};
use
rocksdb_options
::{
Options
,
ReadOptions
,
UnsafeSnap
,
WriteOptions
,
FlushOptions
,
EnvOptions
,
RestoreOptions
,
IngestExternalFileOptions
,
HistogramData
,
CompactOptions
};
...
...
@@ -468,17 +468,14 @@ impl DB {
pub
fn
get_opt
(
&
self
,
key
:
&
[
u8
],
readopts
:
&
ReadOptions
)
->
Result
<
Option
<
DBVector
>
,
String
>
{
unsafe
{
let
val_len
:
size_t
=
0
;
let
val_len_ptr
=
&
val_len
as
*
const
size_t
;
let
val
=
ffi_try!
(
crocksdb_get
(
self
.inner
,
let
val
=
ffi_try!
(
crocksdb_get_pinned
(
self
.inner
,
readopts
.get_inner
(),
key
.as_ptr
(),
key
.len
()
as
size_t
,
val_len_ptr
));
key
.len
()
as
size_t
));
if
val
.is_null
()
{
Ok
(
None
)
}
else
{
Ok
(
Some
(
DBVector
::
from_
c
(
val
,
val_len
)))
Ok
(
Some
(
DBVector
::
from_
pinned_slice
(
val
)))
}
}
}
...
...
@@ -493,18 +490,15 @@ impl DB {
readopts
:
&
ReadOptions
)
->
Result
<
Option
<
DBVector
>
,
String
>
{
unsafe
{
let
val_len
:
size_t
=
0
;
let
val_len_ptr
=
&
val_len
as
*
const
size_t
;
let
val
=
ffi_try!
(
crocksdb_get_cf
(
self
.inner
,
let
val
=
ffi_try!
(
crocksdb_get_pinned_cf
(
self
.inner
,
readopts
.get_inner
(),
cf
.inner
,
key
.as_ptr
(),
key
.len
()
as
size_t
,
val_len_ptr
));
key
.len
()
as
size_t
));
if
val
.is_null
()
{
Ok
(
None
)
}
else
{
Ok
(
Some
(
DBVector
::
from_
c
(
val
,
val_len
)))
Ok
(
Some
(
DBVector
::
from_
pinned_slice
(
val
)))
}
}
}
...
...
@@ -1270,54 +1264,44 @@ impl Writable for WriteBatch {
}
pub
struct
DBVector
{
base
:
*
mut
u8
,
len
:
usize
,
pinned_slice
:
*
mut
DBPinnableSlice
,
}
impl
Debug
for
DBVector
{
fn
fmt
(
&
self
,
formatter
:
&
mut
Formatter
)
->
fmt
::
Result
{
unsafe
{
write!
(
formatter
,
"{:?}"
,
slice
::
from_raw_parts
(
self
.base
,
self
.len
))
}
write!
(
formatter
,
"{:?}"
,
&**
self
)
}
}
impl
<
'a
>
PartialEq
<&
'a
[
u8
]
>
for
DBVector
{
fn
eq
(
&
self
,
rhs
:
&&
[
u8
])
->
bool
{
if
self
.len
!=
rhs
.len
()
{
return
false
;
}
unsafe
{
libc
::
memcmp
(
self
.base
as
*
mut
c_void
,
rhs
.as_ptr
()
as
*
mut
c_void
,
self
.len
)
==
0
}
**
rhs
==
**
self
}
}
impl
Deref
for
DBVector
{
type
Target
=
[
u8
];
fn
deref
(
&
self
)
->
&
[
u8
]
{
unsafe
{
slice
::
from_raw_parts
(
self
.base
,
self
.len
)
}
let
mut
val_len
:
size_t
=
0
;
let
val_len_ptr
=
&
mut
val_len
as
*
mut
size_t
;
unsafe
{
let
val
=
crocksdb_ffi
::
crocksdb_pinnableslice_value
(
self
.pinned_slice
,
val_len_ptr
);
slice
::
from_raw_parts
(
val
,
val_len
)
}
}
}
impl
Drop
for
DBVector
{
fn
drop
(
&
mut
self
)
{
unsafe
{
libc
::
free
(
self
.base
as
*
mut
c_void
);
crocksdb_ffi
::
crocksdb_pinnableslice_destroy
(
self
.pinned_slice
);
}
}
}
impl
DBVector
{
pub
fn
from_c
(
val
:
*
mut
u8
,
val_len
:
size_t
)
->
DBVector
{
DBVector
{
base
:
val
,
len
:
val_len
as
usize
,
}
pub
fn
from_pinned_slice
(
s
:
*
mut
DBPinnableSlice
)
->
DBVector
{
DBVector
{
pinned_slice
:
s
}
}
pub
fn
to_utf8
(
&
self
)
->
Option
<&
str
>
{
...
...
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