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
f6788b64
Commit
f6788b64
authored
Nov 14, 2017
by
Huachao Huang
Committed by
zhangjinpeng1987
Nov 14, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add ExternalSstFileInfo (#158)
parent
c5c0b09e
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
166 additions
and
9 deletions
+166
-9
c.cc
librocksdb_sys/crocksdb/c.cc
+46
-2
c.h
librocksdb_sys/crocksdb/crocksdb/c.h
+21
-1
lib.rs
librocksdb_sys/src/lib.rs
+26
-1
rocksdb.rs
src/rocksdb.rs
+64
-4
test_ingest_external_file.rs
tests/test_ingest_external_file.rs
+9
-1
No files found.
librocksdb_sys/crocksdb/c.cc
View file @
f6788b64
...
@@ -82,6 +82,7 @@ using rocksdb::SliceParts;
...
@@ -82,6 +82,7 @@ using rocksdb::SliceParts;
using
rocksdb
::
SliceTransform
;
using
rocksdb
::
SliceTransform
;
using
rocksdb
::
Snapshot
;
using
rocksdb
::
Snapshot
;
using
rocksdb
::
SstFileWriter
;
using
rocksdb
::
SstFileWriter
;
using
rocksdb
::
ExternalSstFileInfo
;
using
rocksdb
::
Status
;
using
rocksdb
::
Status
;
using
rocksdb
::
WritableFile
;
using
rocksdb
::
WritableFile
;
using
rocksdb
::
WriteBatch
;
using
rocksdb
::
WriteBatch
;
...
@@ -145,6 +146,7 @@ struct crocksdb_column_family_handle_t { ColumnFamilyHandle* rep; };
...
@@ -145,6 +146,7 @@ struct crocksdb_column_family_handle_t { ColumnFamilyHandle* rep; };
struct
crocksdb_envoptions_t
{
EnvOptions
rep
;
};
struct
crocksdb_envoptions_t
{
EnvOptions
rep
;
};
struct
crocksdb_ingestexternalfileoptions_t
{
IngestExternalFileOptions
rep
;
};
struct
crocksdb_ingestexternalfileoptions_t
{
IngestExternalFileOptions
rep
;
};
struct
crocksdb_sstfilewriter_t
{
SstFileWriter
*
rep
;
};
struct
crocksdb_sstfilewriter_t
{
SstFileWriter
*
rep
;
};
struct
crocksdb_externalsstfileinfo_t
{
ExternalSstFileInfo
rep
;
};
struct
crocksdb_ratelimiter_t
{
RateLimiter
*
rep
;
};
struct
crocksdb_ratelimiter_t
{
RateLimiter
*
rep
;
};
struct
crocksdb_histogramdata_t
{
HistogramData
rep
;
};
struct
crocksdb_histogramdata_t
{
HistogramData
rep
;
};
struct
crocksdb_pinnableslice_t
{
PinnableSlice
rep
;
};
struct
crocksdb_pinnableslice_t
{
PinnableSlice
rep
;
};
...
@@ -2905,8 +2907,9 @@ void crocksdb_sstfilewriter_delete(crocksdb_sstfilewriter_t *writer,
...
@@ -2905,8 +2907,9 @@ void crocksdb_sstfilewriter_delete(crocksdb_sstfilewriter_t *writer,
}
}
void
crocksdb_sstfilewriter_finish
(
crocksdb_sstfilewriter_t
*
writer
,
void
crocksdb_sstfilewriter_finish
(
crocksdb_sstfilewriter_t
*
writer
,
char
**
errptr
)
{
crocksdb_externalsstfileinfo_t
*
info
,
SaveError
(
errptr
,
writer
->
rep
->
Finish
(
NULL
));
char
**
errptr
)
{
SaveError
(
errptr
,
writer
->
rep
->
Finish
(
&
info
->
rep
));
}
}
uint64_t
crocksdb_sstfilewriter_file_size
(
crocksdb_sstfilewriter_t
*
writer
)
{
uint64_t
crocksdb_sstfilewriter_file_size
(
crocksdb_sstfilewriter_t
*
writer
)
{
...
@@ -2918,6 +2921,47 @@ void crocksdb_sstfilewriter_destroy(crocksdb_sstfilewriter_t* writer) {
...
@@ -2918,6 +2921,47 @@ void crocksdb_sstfilewriter_destroy(crocksdb_sstfilewriter_t* writer) {
delete
writer
;
delete
writer
;
}
}
crocksdb_externalsstfileinfo_t
*
crocksdb_externalsstfileinfo_create
()
{
return
new
crocksdb_externalsstfileinfo_t
;
};
void
crocksdb_externalsstfileinfo_destroy
(
crocksdb_externalsstfileinfo_t
*
info
)
{
delete
info
;
}
const
char
*
crocksdb_externalsstfileinfo_file_path
(
crocksdb_externalsstfileinfo_t
*
info
,
size_t
*
size
)
{
*
size
=
info
->
rep
.
file_path
.
size
();
return
info
->
rep
.
file_path
.
c_str
();
}
const
char
*
crocksdb_externalsstfileinfo_smallest_key
(
crocksdb_externalsstfileinfo_t
*
info
,
size_t
*
size
)
{
*
size
=
info
->
rep
.
smallest_key
.
size
();
return
info
->
rep
.
smallest_key
.
c_str
();
}
const
char
*
crocksdb_externalsstfileinfo_largest_key
(
crocksdb_externalsstfileinfo_t
*
info
,
size_t
*
size
)
{
*
size
=
info
->
rep
.
largest_key
.
size
();
return
info
->
rep
.
largest_key
.
c_str
();
}
uint64_t
crocksdb_externalsstfileinfo_sequence_number
(
crocksdb_externalsstfileinfo_t
*
info
)
{
return
info
->
rep
.
sequence_number
;
}
uint64_t
crocksdb_externalsstfileinfo_file_size
(
crocksdb_externalsstfileinfo_t
*
info
)
{
return
info
->
rep
.
file_size
;
}
uint64_t
crocksdb_externalsstfileinfo_num_entries
(
crocksdb_externalsstfileinfo_t
*
info
)
{
return
info
->
rep
.
num_entries
;
}
crocksdb_ingestexternalfileoptions_t
*
crocksdb_ingestexternalfileoptions_t
*
crocksdb_ingestexternalfileoptions_create
()
{
crocksdb_ingestexternalfileoptions_create
()
{
crocksdb_ingestexternalfileoptions_t
*
opt
=
crocksdb_ingestexternalfileoptions_t
*
opt
=
...
...
librocksdb_sys/crocksdb/crocksdb/c.h
View file @
f6788b64
...
@@ -109,6 +109,7 @@ typedef struct crocksdb_column_family_handle_t crocksdb_column_family_handle_t;
...
@@ -109,6 +109,7 @@ typedef struct crocksdb_column_family_handle_t crocksdb_column_family_handle_t;
typedef
struct
crocksdb_envoptions_t
crocksdb_envoptions_t
;
typedef
struct
crocksdb_envoptions_t
crocksdb_envoptions_t
;
typedef
struct
crocksdb_ingestexternalfileoptions_t
crocksdb_ingestexternalfileoptions_t
;
typedef
struct
crocksdb_ingestexternalfileoptions_t
crocksdb_ingestexternalfileoptions_t
;
typedef
struct
crocksdb_sstfilewriter_t
crocksdb_sstfilewriter_t
;
typedef
struct
crocksdb_sstfilewriter_t
crocksdb_sstfilewriter_t
;
typedef
struct
crocksdb_externalsstfileinfo_t
crocksdb_externalsstfileinfo_t
;
typedef
struct
crocksdb_ratelimiter_t
crocksdb_ratelimiter_t
;
typedef
struct
crocksdb_ratelimiter_t
crocksdb_ratelimiter_t
;
typedef
struct
crocksdb_pinnableslice_t
crocksdb_pinnableslice_t
;
typedef
struct
crocksdb_pinnableslice_t
crocksdb_pinnableslice_t
;
typedef
struct
crocksdb_user_collected_properties_t
typedef
struct
crocksdb_user_collected_properties_t
...
@@ -1219,12 +1220,31 @@ extern C_ROCKSDB_LIBRARY_API void
...
@@ -1219,12 +1220,31 @@ extern C_ROCKSDB_LIBRARY_API void
crocksdb_sstfilewriter_delete
(
crocksdb_sstfilewriter_t
*
writer
,
const
char
*
key
,
crocksdb_sstfilewriter_delete
(
crocksdb_sstfilewriter_t
*
writer
,
const
char
*
key
,
size_t
keylen
,
char
**
errptr
);
size_t
keylen
,
char
**
errptr
);
extern
C_ROCKSDB_LIBRARY_API
void
crocksdb_sstfilewriter_finish
(
extern
C_ROCKSDB_LIBRARY_API
void
crocksdb_sstfilewriter_finish
(
crocksdb_sstfilewriter_t
*
writer
,
char
**
errptr
);
crocksdb_sstfilewriter_t
*
writer
,
c
rocksdb_externalsstfileinfo_t
*
info
,
c
har
**
errptr
);
extern
C_ROCKSDB_LIBRARY_API
uint64_t
crocksdb_sstfilewriter_file_size
(
extern
C_ROCKSDB_LIBRARY_API
uint64_t
crocksdb_sstfilewriter_file_size
(
crocksdb_sstfilewriter_t
*
writer
);
crocksdb_sstfilewriter_t
*
writer
);
extern
C_ROCKSDB_LIBRARY_API
void
crocksdb_sstfilewriter_destroy
(
extern
C_ROCKSDB_LIBRARY_API
void
crocksdb_sstfilewriter_destroy
(
crocksdb_sstfilewriter_t
*
writer
);
crocksdb_sstfilewriter_t
*
writer
);
/* ExternalSstFileInfo */
extern
C_ROCKSDB_LIBRARY_API
crocksdb_externalsstfileinfo_t
*
crocksdb_externalsstfileinfo_create
();
extern
C_ROCKSDB_LIBRARY_API
void
crocksdb_externalsstfileinfo_destroy
(
crocksdb_externalsstfileinfo_t
*
);
extern
C_ROCKSDB_LIBRARY_API
const
char
*
crocksdb_externalsstfileinfo_file_path
(
crocksdb_externalsstfileinfo_t
*
,
size_t
*
);
extern
C_ROCKSDB_LIBRARY_API
const
char
*
crocksdb_externalsstfileinfo_smallest_key
(
crocksdb_externalsstfileinfo_t
*
,
size_t
*
);
extern
C_ROCKSDB_LIBRARY_API
const
char
*
crocksdb_externalsstfileinfo_largest_key
(
crocksdb_externalsstfileinfo_t
*
,
size_t
*
);
extern
C_ROCKSDB_LIBRARY_API
uint64_t
crocksdb_externalsstfileinfo_sequence_number
(
crocksdb_externalsstfileinfo_t
*
);
extern
C_ROCKSDB_LIBRARY_API
uint64_t
crocksdb_externalsstfileinfo_file_size
(
crocksdb_externalsstfileinfo_t
*
);
extern
C_ROCKSDB_LIBRARY_API
uint64_t
crocksdb_externalsstfileinfo_num_entries
(
crocksdb_externalsstfileinfo_t
*
);
extern
C_ROCKSDB_LIBRARY_API
crocksdb_ingestexternalfileoptions_t
*
extern
C_ROCKSDB_LIBRARY_API
crocksdb_ingestexternalfileoptions_t
*
crocksdb_ingestexternalfileoptions_create
();
crocksdb_ingestexternalfileoptions_create
();
extern
C_ROCKSDB_LIBRARY_API
void
extern
C_ROCKSDB_LIBRARY_API
void
...
...
librocksdb_sys/src/lib.rs
View file @
f6788b64
...
@@ -37,6 +37,7 @@ pub enum DBFlushOptions {}
...
@@ -37,6 +37,7 @@ pub enum DBFlushOptions {}
pub
enum
DBCompactionFilter
{}
pub
enum
DBCompactionFilter
{}
pub
enum
EnvOptions
{}
pub
enum
EnvOptions
{}
pub
enum
SstFileWriter
{}
pub
enum
SstFileWriter
{}
pub
enum
ExternalSstFileInfo
{}
pub
enum
IngestExternalFileOptions
{}
pub
enum
IngestExternalFileOptions
{}
pub
enum
DBBackupEngine
{}
pub
enum
DBBackupEngine
{}
pub
enum
DBRestoreOptions
{}
pub
enum
DBRestoreOptions
{}
...
@@ -1118,10 +1119,34 @@ extern "C" {
...
@@ -1118,10 +1119,34 @@ extern "C" {
key_len
:
size_t
,
key_len
:
size_t
,
err
:
*
mut
*
mut
c_char
,
err
:
*
mut
*
mut
c_char
,
);
);
pub
fn
crocksdb_sstfilewriter_finish
(
writer
:
*
mut
SstFileWriter
,
err
:
*
mut
*
mut
c_char
);
pub
fn
crocksdb_sstfilewriter_finish
(
writer
:
*
mut
SstFileWriter
,
info
:
*
mut
ExternalSstFileInfo
,
err
:
*
mut
*
mut
c_char
,
);
pub
fn
crocksdb_sstfilewriter_file_size
(
writer
:
*
mut
SstFileWriter
)
->
uint64_t
;
pub
fn
crocksdb_sstfilewriter_file_size
(
writer
:
*
mut
SstFileWriter
)
->
uint64_t
;
pub
fn
crocksdb_sstfilewriter_destroy
(
writer
:
*
mut
SstFileWriter
);
pub
fn
crocksdb_sstfilewriter_destroy
(
writer
:
*
mut
SstFileWriter
);
// ExternalSstFileInfo
pub
fn
crocksdb_externalsstfileinfo_create
()
->
*
mut
ExternalSstFileInfo
;
pub
fn
crocksdb_externalsstfileinfo_destroy
(
info
:
*
mut
ExternalSstFileInfo
);
pub
fn
crocksdb_externalsstfileinfo_file_path
(
info
:
*
mut
ExternalSstFileInfo
,
size
:
*
mut
size_t
,
)
->
*
const
uint8_t
;
pub
fn
crocksdb_externalsstfileinfo_smallest_key
(
info
:
*
mut
ExternalSstFileInfo
,
size
:
*
mut
size_t
,
)
->
*
const
uint8_t
;
pub
fn
crocksdb_externalsstfileinfo_largest_key
(
info
:
*
mut
ExternalSstFileInfo
,
size
:
*
mut
size_t
,
)
->
*
const
uint8_t
;
pub
fn
crocksdb_externalsstfileinfo_sequence_number
(
info
:
*
mut
ExternalSstFileInfo
)
->
uint64_t
;
pub
fn
crocksdb_externalsstfileinfo_file_size
(
info
:
*
mut
ExternalSstFileInfo
)
->
uint64_t
;
pub
fn
crocksdb_externalsstfileinfo_num_entries
(
info
:
*
mut
ExternalSstFileInfo
)
->
uint64_t
;
pub
fn
crocksdb_ingest_external_file
(
pub
fn
crocksdb_ingest_external_file
(
db
:
*
mut
DBInstance
,
db
:
*
mut
DBInstance
,
file_list
:
*
const
*
const
c_char
,
file_list
:
*
const
*
const
c_char
,
...
...
src/rocksdb.rs
View file @
f6788b64
...
@@ -26,7 +26,7 @@ use std::collections::btree_map::Entry;
...
@@ -26,7 +26,7 @@ use std::collections::btree_map::Entry;
use
std
::
ffi
::{
CStr
,
CString
};
use
std
::
ffi
::{
CStr
,
CString
};
use
std
::
fmt
::{
self
,
Debug
,
Formatter
};
use
std
::
fmt
::{
self
,
Debug
,
Formatter
};
use
std
::
ops
::
Deref
;
use
std
::
ops
::
Deref
;
use
std
::
path
::
Path
;
use
std
::
path
::
{
Path
,
PathBuf
}
;
use
std
::
str
::
from_utf8
;
use
std
::
str
::
from_utf8
;
use
table_properties
::
TablePropertiesCollection
;
use
table_properties
::
TablePropertiesCollection
;
...
@@ -1761,11 +1761,12 @@ impl SstFileWriter {
...
@@ -1761,11 +1761,12 @@ impl SstFileWriter {
}
}
/// Finalize writing to sst file and close file.
/// Finalize writing to sst file and close file.
pub
fn
finish
(
&
mut
self
)
->
Result
<
(),
String
>
{
pub
fn
finish
(
&
mut
self
)
->
Result
<
ExternalSstFileInfo
,
String
>
{
let
info
=
ExternalSstFileInfo
::
new
();
unsafe
{
unsafe
{
ffi_try!
(
crocksdb_sstfilewriter_finish
(
self
.inner
));
ffi_try!
(
crocksdb_sstfilewriter_finish
(
self
.inner
,
info
.inner
));
Ok
(())
}
}
Ok
(
info
)
}
}
pub
fn
file_size
(
&
mut
self
)
->
u64
{
pub
fn
file_size
(
&
mut
self
)
->
u64
{
...
@@ -1779,6 +1780,65 @@ impl Drop for SstFileWriter {
...
@@ -1779,6 +1780,65 @@ impl Drop for SstFileWriter {
}
}
}
}
pub
struct
ExternalSstFileInfo
{
inner
:
*
mut
crocksdb_ffi
::
ExternalSstFileInfo
,
}
impl
ExternalSstFileInfo
{
pub
fn
new
()
->
ExternalSstFileInfo
{
unsafe
{
ExternalSstFileInfo
{
inner
:
crocksdb_ffi
::
crocksdb_externalsstfileinfo_create
(),
}
}
}
pub
fn
file_path
(
&
self
)
->
PathBuf
{
let
mut
len
:
size_t
=
0
;
unsafe
{
let
ptr
=
crocksdb_ffi
::
crocksdb_externalsstfileinfo_file_path
(
self
.inner
,
&
mut
len
);
let
bytes
=
slice
::
from_raw_parts
(
ptr
,
len
as
usize
);
PathBuf
::
from
(
String
::
from_utf8
(
bytes
.to_owned
())
.unwrap
())
}
}
pub
fn
smallest_key
(
&
self
)
->
&
[
u8
]
{
let
mut
len
:
size_t
=
0
;
unsafe
{
let
ptr
=
crocksdb_ffi
::
crocksdb_externalsstfileinfo_smallest_key
(
self
.inner
,
&
mut
len
);
slice
::
from_raw_parts
(
ptr
,
len
as
usize
)
}
}
pub
fn
largest_key
(
&
self
)
->
&
[
u8
]
{
let
mut
len
:
size_t
=
0
;
unsafe
{
let
ptr
=
crocksdb_ffi
::
crocksdb_externalsstfileinfo_largest_key
(
self
.inner
,
&
mut
len
);
slice
::
from_raw_parts
(
ptr
,
len
as
usize
)
}
}
pub
fn
sequence_number
(
&
self
)
->
u64
{
unsafe
{
crocksdb_ffi
::
crocksdb_externalsstfileinfo_sequence_number
(
self
.inner
)
as
u64
}
}
pub
fn
file_size
(
&
self
)
->
u64
{
unsafe
{
crocksdb_ffi
::
crocksdb_externalsstfileinfo_file_size
(
self
.inner
)
as
u64
}
}
pub
fn
num_entries
(
&
self
)
->
u64
{
unsafe
{
crocksdb_ffi
::
crocksdb_externalsstfileinfo_num_entries
(
self
.inner
)
as
u64
}
}
}
impl
Drop
for
ExternalSstFileInfo
{
fn
drop
(
&
mut
self
)
{
unsafe
{
crocksdb_ffi
::
crocksdb_externalsstfileinfo_destroy
(
self
.inner
);
}
}
}
pub
fn
supported_compression
()
->
Vec
<
DBCompressionType
>
{
pub
fn
supported_compression
()
->
Vec
<
DBCompressionType
>
{
unsafe
{
unsafe
{
let
size
=
crocksdb_ffi
::
crocksdb_get_supported_compression_number
()
as
usize
;
let
size
=
crocksdb_ffi
::
crocksdb_get_supported_compression_number
()
as
usize
;
...
...
tests/test_ingest_external_file.rs
View file @
f6788b64
...
@@ -281,7 +281,15 @@ fn gen_sst_from_cf(opt: ColumnFamilyOptions, db: &DB, cf: &CFHandle, path: &str)
...
@@ -281,7 +281,15 @@ fn gen_sst_from_cf(opt: ColumnFamilyOptions, db: &DB, cf: &CFHandle, path: &str)
writer
.put
(
iter
.key
(),
iter
.value
())
.unwrap
();
writer
.put
(
iter
.key
(),
iter
.value
())
.unwrap
();
iter
.next
();
iter
.next
();
}
}
writer
.finish
()
.unwrap
();
let
info
=
writer
.finish
()
.unwrap
();
assert_eq!
(
info
.file_path
()
.to_str
()
.unwrap
(),
path
);
iter
.seek
(
SeekKey
::
Start
);
assert_eq!
(
info
.smallest_key
(),
iter
.key
());
iter
.seek
(
SeekKey
::
End
);
assert_eq!
(
info
.largest_key
(),
iter
.key
());
assert_eq!
(
info
.sequence_number
(),
0
);
assert
!
(
info
.file_size
()
>
0
);
assert
!
(
info
.num_entries
()
>
0
);
}
}
fn
create_default_database
(
path
:
&
TempDir
)
->
DB
{
fn
create_default_database
(
path
:
&
TempDir
)
->
DB
{
...
...
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