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
5f49f9ef
Commit
5f49f9ef
authored
Feb 19, 2019
by
dorianzheng
Committed by
Huachao Huang
Feb 19, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add blob index encoder (#272)
parent
2088c8d4
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
61 additions
and
3 deletions
+61
-3
c.cc
librocksdb_sys/crocksdb/c.cc
+12
-0
c.h
librocksdb_sys/crocksdb/crocksdb/c.h
+3
-0
rocksdb
librocksdb_sys/rocksdb
+1
-1
lib.rs
librocksdb_sys/src/lib.rs
+5
-0
titan.rs
src/titan.rs
+24
-1
test_titan.rs
tests/cases/test_titan.rs
+16
-1
No files found.
librocksdb_sys/crocksdb/c.cc
View file @
5f49f9ef
...
...
@@ -4988,6 +4988,18 @@ void ctitandb_decode_blob_index(const char* value, size_t value_size,
index
->
blob_size
=
bi
.
blob_handle
.
size
;
}
void
ctitandb_encode_blob_index
(
const
ctitandb_blob_index_t
&
index
,
char
**
value
,
size_t
*
value_size
)
{
BlobIndex
bi
;
bi
.
file_number
=
index
.
file_number
;
bi
.
blob_handle
.
offset
=
index
.
blob_offset
;
bi
.
blob_handle
.
size
=
index
.
blob_size
;
std
::
string
result
;
bi
.
EncodeTo
(
&
result
);
*
value
=
CopyString
(
result
);
*
value_size
=
result
.
size
();
}
void
ctitandb_options_set_disable_background_gc
(
ctitandb_options_t
*
options
,
unsigned
char
disable
)
{
options
->
rep
.
disable_background_gc
=
disable
;
...
...
librocksdb_sys/crocksdb/crocksdb/c.h
View file @
5f49f9ef
...
...
@@ -1986,6 +1986,9 @@ extern C_ROCKSDB_LIBRARY_API void ctitandb_decode_blob_index(
const
char
*
value
,
size_t
value_size
,
ctitandb_blob_index_t
*
index
,
char
**
errptr
);
extern
C_ROCKSDB_LIBRARY_API
void
ctitandb_encode_blob_index
(
const
ctitandb_blob_index_t
&
index
,
char
**
value
,
size_t
*
value_size
);
extern
C_ROCKSDB_LIBRARY_API
void
ctitandb_options_set_disable_background_gc
(
ctitandb_options_t
*
options
,
unsigned
char
disable
);
...
...
rocksdb
@
c96bfa2e
Subproject commit
da05929b46cf5e5129b75c1b95feb6d0c41da27c
Subproject commit
c96bfa2e2e75f8fddbfa9362ba072d07b453df20
librocksdb_sys/src/lib.rs
View file @
5f49f9ef
...
...
@@ -1822,6 +1822,11 @@ extern "C" {
index
:
*
mut
DBTitanBlobIndex
,
errptr
:
*
mut
*
mut
c_char
,
);
pub
fn
ctitandb_encode_blob_index
(
index
:
&
DBTitanBlobIndex
,
value
:
*
mut
*
mut
u8
,
value_size
:
*
mut
u64
,
);
pub
fn
ctitandb_options_set_disable_background_gc
(
opts
:
*
mut
DBTitanDBOptions
,
disable
:
bool
);
pub
fn
ctitandb_options_set_max_background_gc
(
opts
:
*
mut
DBTitanDBOptions
,
size
:
i32
);
...
...
src/titan.rs
View file @
5f49f9ef
...
...
@@ -2,9 +2,14 @@ use std::ffi::{CStr, CString};
use
std
::
ops
::
Deref
;
use
crocksdb_ffi
::{
self
,
DBCompressionType
,
DBTitanBlobIndex
,
DBTitanDBOptions
};
use
librocksdb_sys
::
ctitandb_encode_blob_index
;
use
std
::
ffi
::
c_void
;
use
std
::
ops
::
DerefMut
;
use
std
::
os
::
raw
::
c_double
;
use
std
::
os
::
raw
::
c_int
;
use
std
::
os
::
raw
::
c_uchar
;
use
std
::
ptr
;
use
std
::
slice
;
pub
struct
TitanDBOptions
{
pub
inner
:
*
mut
DBTitanDBOptions
,
...
...
@@ -124,7 +129,7 @@ pub struct TitanBlobIndex {
}
impl
TitanBlobIndex
{
pub
fn
decode
_from
(
value
:
&
[
u8
])
->
Result
<
Self
,
String
>
{
pub
fn
decode
(
value
:
&
[
u8
])
->
Result
<
Self
,
String
>
{
let
mut
index
=
Self
::
default
();
unsafe
{
ffi_try!
(
ctitandb_decode_blob_index
(
...
...
@@ -135,6 +140,18 @@ impl TitanBlobIndex {
}
Ok
(
index
)
}
pub
fn
encode
(
&
self
)
->
Vec
<
u8
>
{
let
mut
value
=
ptr
::
null_mut
();
let
mut
value_size
:
u64
=
0
;
unsafe
{
ctitandb_encode_blob_index
(
&
self
.inner
,
&
mut
value
,
&
mut
value_size
);
let
slice
=
slice
::
from_raw_parts
(
value
,
value_size
as
usize
);
let
vec
=
slice
.to_vec
();
libc
::
free
(
value
as
*
mut
c_void
);
vec
}
}
}
impl
Deref
for
TitanBlobIndex
{
...
...
@@ -143,3 +160,9 @@ impl Deref for TitanBlobIndex {
&
self
.inner
}
}
impl
DerefMut
for
TitanBlobIndex
{
fn
deref_mut
(
&
mut
self
)
->
&
mut
Self
::
Target
{
&
mut
self
.inner
}
}
tests/cases/test_titan.rs
View file @
5f49f9ef
...
...
@@ -16,6 +16,7 @@ use std::collections::HashMap;
use
byteorder
::{
LittleEndian
,
ReadBytesExt
,
WriteBytesExt
};
use
tempdir
::
TempDir
;
use
rand
::
Rng
;
use
rocksdb
::{
ColumnFamilyOptions
,
DBCompressionType
,
DBEntryType
,
DBOptions
,
SeekKey
,
TablePropertiesCollector
,
TablePropertiesCollectorFactory
,
TitanBlobIndex
,
TitanDBOptions
,
...
...
@@ -64,7 +65,7 @@ impl TablePropertiesCollector for TitanCollector {
self
.num_entries
+=
1
;
if
let
DBEntryType
::
BlobIndex
=
entry_type
{
self
.num_blobs
+=
1
;
let
index
=
TitanBlobIndex
::
decode
_from
(
value
)
.unwrap
();
let
index
=
TitanBlobIndex
::
decode
(
value
)
.unwrap
();
assert
!
(
index
.file_number
>
0
);
assert
!
(
index
.blob_size
>
0
);
}
...
...
@@ -150,3 +151,17 @@ fn test_titandb() {
let
num_entries
=
n
as
u32
*
max_value_size
as
u32
;
check_table_properties
(
&
db
,
num_entries
/
2
,
num_entries
);
}
#[test]
fn
test_titan_blob_index
()
{
let
mut
index
=
TitanBlobIndex
::
default
();
let
mut
rng
=
rand
::
thread_rng
();
index
.file_number
=
rng
.gen
();
index
.blob_size
=
rng
.gen
();
index
.blob_offset
=
rng
.gen
();
let
value
=
index
.encode
();
let
index2
=
TitanBlobIndex
::
decode
(
&
value
)
.unwrap
();
assert_eq!
(
index2
.file_number
,
index
.file_number
);
assert_eq!
(
index2
.blob_size
,
index
.blob_size
);
assert_eq!
(
index2
.blob_offset
,
index
.blob_offset
);
}
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