Skip to content

Commit 325842e

Browse files
committed
use bindgen's generated ffi rs code
Signed-off-by: fredchenbj <[email protected]>
1 parent 1ef6fe7 commit 325842e

21 files changed

+814
-2629
lines changed

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ valgrind = []
2323

2424
[dependencies]
2525
libc = "0.2.11"
26+
num = "0.2"
27+
num-derive = "0.3"
28+
num-traits = "0.2"
2629

2730
[dependencies.librocksdb_sys]
2831
path = "librocksdb_sys"

librocksdb_sys/bindings/x86_64-unknown-linux-gnu-bindings.rs

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -416,14 +416,13 @@ pub struct crocksdb_writestallinfo_t {
416416
}
417417
#[repr(C)]
418418
#[derive(Debug, Copy, Clone)]
419-
pub struct crocksdb_writestallcondition_t {
420-
_unused: [u8; 0],
421-
}
422-
#[repr(C)]
423-
#[derive(Debug, Copy, Clone)]
424419
pub struct crocksdb_map_property_t {
425420
_unused: [u8; 0],
426421
}
422+
pub const crocksdb_writestallcondition_t_Normal: crocksdb_writestallcondition_t = 0;
423+
pub const crocksdb_writestallcondition_t_Delayed: crocksdb_writestallcondition_t = 1;
424+
pub const crocksdb_writestallcondition_t_Stopped: crocksdb_writestallcondition_t = 2;
425+
pub type crocksdb_writestallcondition_t = u32;
427426
pub const crocksdb_table_property_t_kDataSize: crocksdb_table_property_t = 1;
428427
pub const crocksdb_table_property_t_kIndexSize: crocksdb_table_property_t = 2;
429428
pub const crocksdb_table_property_t_kFilterSize: crocksdb_table_property_t = 3;
@@ -451,6 +450,23 @@ pub const crocksdb_backgrounderrorreason_t_kCompaction: crocksdb_backgrounderror
451450
pub const crocksdb_backgrounderrorreason_t_kWriteCallback: crocksdb_backgrounderrorreason_t = 3;
452451
pub const crocksdb_backgrounderrorreason_t_kMemTable: crocksdb_backgrounderrorreason_t = 4;
453452
pub type crocksdb_backgrounderrorreason_t = u32;
453+
pub const crocksdb_compaction_reason_t_Unknown: crocksdb_compaction_reason_t = 0;
454+
pub const crocksdb_compaction_reason_t_LevelL0FilesNum: crocksdb_compaction_reason_t = 1;
455+
pub const crocksdb_compaction_reason_t_LevelMaxLevelSize: crocksdb_compaction_reason_t = 2;
456+
pub const crocksdb_compaction_reason_t_UniversalSizeAmplification: crocksdb_compaction_reason_t = 3;
457+
pub const crocksdb_compaction_reason_t_UniversalSizeRatio: crocksdb_compaction_reason_t = 4;
458+
pub const crocksdb_compaction_reason_t_UniversalSortedRunNum: crocksdb_compaction_reason_t = 5;
459+
pub const crocksdb_compaction_reason_t_FIFOMaxSize: crocksdb_compaction_reason_t = 6;
460+
pub const crocksdb_compaction_reason_t_FIFOReduceNumFiles: crocksdb_compaction_reason_t = 7;
461+
pub const crocksdb_compaction_reason_t_FIFOTtl: crocksdb_compaction_reason_t = 8;
462+
pub const crocksdb_compaction_reason_t_ManualCompaction: crocksdb_compaction_reason_t = 9;
463+
pub const crocksdb_compaction_reason_t_FilesMarkedForCompaction: crocksdb_compaction_reason_t = 10;
464+
pub const crocksdb_compaction_reason_t_BottommostFiles: crocksdb_compaction_reason_t = 11;
465+
pub const crocksdb_compaction_reason_t_Ttl: crocksdb_compaction_reason_t = 12;
466+
pub const crocksdb_compaction_reason_t_Flush: crocksdb_compaction_reason_t = 13;
467+
pub const crocksdb_compaction_reason_t_ExternalSstIngestion: crocksdb_compaction_reason_t = 14;
468+
pub const crocksdb_compaction_reason_t_NumOfReasons: crocksdb_compaction_reason_t = 15;
469+
pub type crocksdb_compaction_reason_t = u32;
454470
extern "C" {
455471
pub fn crocksdb_open(
456472
options: *const crocksdb_options_t,
@@ -1558,6 +1574,11 @@ extern "C" {
15581574
info: *const crocksdb_compactionjobinfo_t,
15591575
) -> u64;
15601576
}
1577+
extern "C" {
1578+
pub fn crocksdb_compactionjobinfo_compaction_reason(
1579+
info: *const crocksdb_compactionjobinfo_t,
1580+
) -> *const crocksdb_compaction_reason_t;
1581+
}
15611582
extern "C" {
15621583
pub fn crocksdb_externalfileingestioninfo_cf_name(
15631584
arg1: *const crocksdb_externalfileingestioninfo_t,

librocksdb_sys/crocksdb/c.cc

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,6 @@ struct crocksdb_pinnableslice_t { PinnableSlice rep; };
233233
struct crocksdb_flushjobinfo_t {
234234
FlushJobInfo rep;
235235
};
236-
struct crocksdb_writestallcondition_t {
237-
WriteStallCondition rep;
238-
};
239236
struct crocksdb_writestallinfo_t {
240237
WriteStallInfo rep;
241238
};
@@ -2003,9 +2000,11 @@ uint64_t crocksdb_compactionjobinfo_total_output_bytes(
20032000
return info->rep.stats.total_output_bytes;
20042001
}
20052002

2006-
CompactionReason crocksdb_compactionjobinfo_compaction_reason(
2003+
const crocksdb_compaction_reason_t*
2004+
crocksdb_compactionjobinfo_compaction_reason(
20072005
const crocksdb_compactionjobinfo_t* info) {
2008-
return info->rep.compaction_reason;
2006+
return reinterpret_cast<const crocksdb_compaction_reason_t*>(
2007+
&info->rep.compaction_reason);
20092008
}
20102009

20112010
/* ExternalFileIngestionInfo */

librocksdb_sys/crocksdb/crocksdb/c.h

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,14 @@ typedef struct crocksdb_compaction_options_t crocksdb_compaction_options_t;
145145
typedef struct crocksdb_perf_context_t crocksdb_perf_context_t;
146146
typedef struct crocksdb_iostats_context_t crocksdb_iostats_context_t;
147147
typedef struct crocksdb_writestallinfo_t crocksdb_writestallinfo_t;
148-
typedef struct crocksdb_writestallcondition_t crocksdb_writestallcondition_t;
149148
typedef struct crocksdb_map_property_t crocksdb_map_property_t;
150149

150+
typedef enum crocksdb_writestallcondition_t {
151+
Normal = 0,
152+
Delayed = 1,
153+
Stopped = 2,
154+
} crocksdb_writestallcondition_t;
155+
151156
typedef enum crocksdb_table_property_t {
152157
kDataSize = 1,
153158
kIndexSize = 2,
@@ -181,8 +186,26 @@ typedef enum crocksdb_backgrounderrorreason_t {
181186
kMemTable = 4,
182187
} crocksdb_backgrounderrorreason_t;
183188

184-
/* DB operations */
189+
typedef enum crocksdb_compaction_reason_t {
190+
Unknown = 0,
191+
LevelL0FilesNum = 1,
192+
LevelMaxLevelSize = 2,
193+
UniversalSizeAmplification = 3,
194+
UniversalSizeRatio = 4,
195+
UniversalSortedRunNum = 5,
196+
FIFOMaxSize = 6,
197+
FIFOReduceNumFiles = 7,
198+
FIFOTtl = 8,
199+
ManualCompaction = 9,
200+
FilesMarkedForCompaction = 10,
201+
BottommostFiles = 11,
202+
Ttl = 12,
203+
Flush = 13,
204+
ExternalSstIngestion = 14,
205+
NumOfReasons = 15,
206+
} crocksdb_compaction_reason_t;
185207

208+
/* DB operations */
186209
extern C_ROCKSDB_LIBRARY_API crocksdb_t* crocksdb_open(
187210
const crocksdb_options_t* options, const char* name, char** errptr);
188211

@@ -756,6 +779,9 @@ crocksdb_compactionjobinfo_total_input_bytes(
756779
extern C_ROCKSDB_LIBRARY_API uint64_t
757780
crocksdb_compactionjobinfo_total_output_bytes(
758781
const crocksdb_compactionjobinfo_t* info);
782+
extern C_ROCKSDB_LIBRARY_API const crocksdb_compaction_reason_t*
783+
crocksdb_compactionjobinfo_compaction_reason(
784+
const crocksdb_compactionjobinfo_t* info);
759785

760786
/* External file ingestion info */
761787
extern C_ROCKSDB_LIBRARY_API const char*

0 commit comments

Comments
 (0)