Skip to content

Commit

Permalink
use bindgen's generated ffi rs code
Browse files Browse the repository at this point in the history
Signed-off-by: fredchenbj <[email protected]>
  • Loading branch information
fredbjer committed Jan 7, 2020
1 parent 1ef6fe7 commit 325842e
Show file tree
Hide file tree
Showing 21 changed files with 814 additions and 2,629 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ valgrind = []

[dependencies]
libc = "0.2.11"
num = "0.2"
num-derive = "0.3"
num-traits = "0.2"

[dependencies.librocksdb_sys]
path = "librocksdb_sys"
Expand Down
31 changes: 26 additions & 5 deletions librocksdb_sys/bindings/x86_64-unknown-linux-gnu-bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,14 +416,13 @@ pub struct crocksdb_writestallinfo_t {
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct crocksdb_writestallcondition_t {
_unused: [u8; 0],
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct crocksdb_map_property_t {
_unused: [u8; 0],
}
pub const crocksdb_writestallcondition_t_Normal: crocksdb_writestallcondition_t = 0;
pub const crocksdb_writestallcondition_t_Delayed: crocksdb_writestallcondition_t = 1;
pub const crocksdb_writestallcondition_t_Stopped: crocksdb_writestallcondition_t = 2;
pub type crocksdb_writestallcondition_t = u32;
pub const crocksdb_table_property_t_kDataSize: crocksdb_table_property_t = 1;
pub const crocksdb_table_property_t_kIndexSize: crocksdb_table_property_t = 2;
pub const crocksdb_table_property_t_kFilterSize: crocksdb_table_property_t = 3;
Expand Down Expand Up @@ -451,6 +450,23 @@ pub const crocksdb_backgrounderrorreason_t_kCompaction: crocksdb_backgrounderror
pub const crocksdb_backgrounderrorreason_t_kWriteCallback: crocksdb_backgrounderrorreason_t = 3;
pub const crocksdb_backgrounderrorreason_t_kMemTable: crocksdb_backgrounderrorreason_t = 4;
pub type crocksdb_backgrounderrorreason_t = u32;
pub const crocksdb_compaction_reason_t_Unknown: crocksdb_compaction_reason_t = 0;
pub const crocksdb_compaction_reason_t_LevelL0FilesNum: crocksdb_compaction_reason_t = 1;
pub const crocksdb_compaction_reason_t_LevelMaxLevelSize: crocksdb_compaction_reason_t = 2;
pub const crocksdb_compaction_reason_t_UniversalSizeAmplification: crocksdb_compaction_reason_t = 3;
pub const crocksdb_compaction_reason_t_UniversalSizeRatio: crocksdb_compaction_reason_t = 4;
pub const crocksdb_compaction_reason_t_UniversalSortedRunNum: crocksdb_compaction_reason_t = 5;
pub const crocksdb_compaction_reason_t_FIFOMaxSize: crocksdb_compaction_reason_t = 6;
pub const crocksdb_compaction_reason_t_FIFOReduceNumFiles: crocksdb_compaction_reason_t = 7;
pub const crocksdb_compaction_reason_t_FIFOTtl: crocksdb_compaction_reason_t = 8;
pub const crocksdb_compaction_reason_t_ManualCompaction: crocksdb_compaction_reason_t = 9;
pub const crocksdb_compaction_reason_t_FilesMarkedForCompaction: crocksdb_compaction_reason_t = 10;
pub const crocksdb_compaction_reason_t_BottommostFiles: crocksdb_compaction_reason_t = 11;
pub const crocksdb_compaction_reason_t_Ttl: crocksdb_compaction_reason_t = 12;
pub const crocksdb_compaction_reason_t_Flush: crocksdb_compaction_reason_t = 13;
pub const crocksdb_compaction_reason_t_ExternalSstIngestion: crocksdb_compaction_reason_t = 14;
pub const crocksdb_compaction_reason_t_NumOfReasons: crocksdb_compaction_reason_t = 15;
pub type crocksdb_compaction_reason_t = u32;
extern "C" {
pub fn crocksdb_open(
options: *const crocksdb_options_t,
Expand Down Expand Up @@ -1558,6 +1574,11 @@ extern "C" {
info: *const crocksdb_compactionjobinfo_t,
) -> u64;
}
extern "C" {
pub fn crocksdb_compactionjobinfo_compaction_reason(
info: *const crocksdb_compactionjobinfo_t,
) -> *const crocksdb_compaction_reason_t;
}
extern "C" {
pub fn crocksdb_externalfileingestioninfo_cf_name(
arg1: *const crocksdb_externalfileingestioninfo_t,
Expand Down
9 changes: 4 additions & 5 deletions librocksdb_sys/crocksdb/c.cc
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,6 @@ struct crocksdb_pinnableslice_t { PinnableSlice rep; };
struct crocksdb_flushjobinfo_t {
FlushJobInfo rep;
};
struct crocksdb_writestallcondition_t {
WriteStallCondition rep;
};
struct crocksdb_writestallinfo_t {
WriteStallInfo rep;
};
Expand Down Expand Up @@ -2003,9 +2000,11 @@ uint64_t crocksdb_compactionjobinfo_total_output_bytes(
return info->rep.stats.total_output_bytes;
}

CompactionReason crocksdb_compactionjobinfo_compaction_reason(
const crocksdb_compaction_reason_t*
crocksdb_compactionjobinfo_compaction_reason(
const crocksdb_compactionjobinfo_t* info) {
return info->rep.compaction_reason;
return reinterpret_cast<const crocksdb_compaction_reason_t*>(
&info->rep.compaction_reason);
}

/* ExternalFileIngestionInfo */
Expand Down
30 changes: 28 additions & 2 deletions librocksdb_sys/crocksdb/crocksdb/c.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,14 @@ typedef struct crocksdb_compaction_options_t crocksdb_compaction_options_t;
typedef struct crocksdb_perf_context_t crocksdb_perf_context_t;
typedef struct crocksdb_iostats_context_t crocksdb_iostats_context_t;
typedef struct crocksdb_writestallinfo_t crocksdb_writestallinfo_t;
typedef struct crocksdb_writestallcondition_t crocksdb_writestallcondition_t;
typedef struct crocksdb_map_property_t crocksdb_map_property_t;

typedef enum crocksdb_writestallcondition_t {
Normal = 0,
Delayed = 1,
Stopped = 2,
} crocksdb_writestallcondition_t;

typedef enum crocksdb_table_property_t {
kDataSize = 1,
kIndexSize = 2,
Expand Down Expand Up @@ -181,8 +186,26 @@ typedef enum crocksdb_backgrounderrorreason_t {
kMemTable = 4,
} crocksdb_backgrounderrorreason_t;

/* DB operations */
typedef enum crocksdb_compaction_reason_t {
Unknown = 0,
LevelL0FilesNum = 1,
LevelMaxLevelSize = 2,
UniversalSizeAmplification = 3,
UniversalSizeRatio = 4,
UniversalSortedRunNum = 5,
FIFOMaxSize = 6,
FIFOReduceNumFiles = 7,
FIFOTtl = 8,
ManualCompaction = 9,
FilesMarkedForCompaction = 10,
BottommostFiles = 11,
Ttl = 12,
Flush = 13,
ExternalSstIngestion = 14,
NumOfReasons = 15,
} crocksdb_compaction_reason_t;

/* DB operations */
extern C_ROCKSDB_LIBRARY_API crocksdb_t* crocksdb_open(
const crocksdb_options_t* options, const char* name, char** errptr);

Expand Down Expand Up @@ -756,6 +779,9 @@ crocksdb_compactionjobinfo_total_input_bytes(
extern C_ROCKSDB_LIBRARY_API uint64_t
crocksdb_compactionjobinfo_total_output_bytes(
const crocksdb_compactionjobinfo_t* info);
extern C_ROCKSDB_LIBRARY_API const crocksdb_compaction_reason_t*
crocksdb_compactionjobinfo_compaction_reason(
const crocksdb_compactionjobinfo_t* info);

/* External file ingestion info */
extern C_ROCKSDB_LIBRARY_API const char*
Expand Down
Loading

0 comments on commit 325842e

Please sign in to comment.