Commit 19ac3a9c authored by Wallace's avatar Wallace Committed by yiwu-arbug

add io stall stats interface (#353)

Signed-off-by: Little-Wallace bupt2013211450@gmail.com

Add interface to get count of each write stall reason.
parent 3cd18c44
......@@ -22,6 +22,7 @@ env:
cache: false
before_script:
- rustup default nightly-2019-09-05
- rustup component add rustfmt-preview
script:
......
......@@ -267,6 +267,10 @@ struct crocksdb_compaction_options_t {
CompactionOptions rep;
};
struct crocksdb_map_property_t {
std::map<std::string, std::string> rep;
};
struct crocksdb_compactionfilter_t : public CompactionFilter {
void* state_;
void (*destructor_)(void*);
......@@ -1127,6 +1131,44 @@ uint64_t crocksdb_get_snapshot_sequence_number(
return snapshot->rep->GetSequenceNumber();
}
crocksdb_map_property_t* crocksdb_create_map_property() {
return new crocksdb_map_property_t;
}
void crocksdb_destroy_map_property(crocksdb_map_property_t* info) {
delete info;
}
bool crocksdb_get_map_property_cf(
crocksdb_t* db,
crocksdb_column_family_handle_t* column_family,
const char* property,
crocksdb_map_property_t* info) {
return db->rep->GetMapProperty(column_family->rep, property, &info->rep);
}
char* crocksdb_map_property_value(
crocksdb_map_property_t* info,
const char* propname) {
auto iter = info->rep.find(std::string(propname));
if (iter != info->rep.end()) {
return strdup(iter->second.c_str());
} else {
return nullptr;
}
}
uint64_t crocksdb_map_property_int_value(
crocksdb_map_property_t* info,
const char* propname) {
auto iter = info->rep.find(std::string(propname));
if (iter != info->rep.end()) {
return (uint64_t)stoll(iter->second, nullptr);
} else {
return 0;
}
}
char* crocksdb_property_value(
crocksdb_t* db,
const char* propname) {
......
......@@ -146,6 +146,7 @@ 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_table_property_t {
kDataSize = 1,
......@@ -397,6 +398,21 @@ crocksdb_get_snapshot_sequence_number(const crocksdb_snapshot_t* snapshot);
/* Returns NULL if property name is unknown.
Else returns a pointer to a malloc()-ed null-terminated value. */
extern C_ROCKSDB_LIBRARY_API crocksdb_map_property_t* crocksdb_create_map_property();
extern C_ROCKSDB_LIBRARY_API void crocksdb_destroy_map_property(crocksdb_map_property_t* info);
extern C_ROCKSDB_LIBRARY_API bool crocksdb_get_map_property_cf(
crocksdb_t* db, crocksdb_column_family_handle_t* column_family,
const char* property, crocksdb_map_property_t* data);
extern C_ROCKSDB_LIBRARY_API char* crocksdb_map_property_value(
crocksdb_map_property_t* info,
const char* propname);
extern C_ROCKSDB_LIBRARY_API uint64_t crocksdb_map_property_int_value(
crocksdb_map_property_t* info, const char* propname);
extern C_ROCKSDB_LIBRARY_API char* crocksdb_property_value(crocksdb_t* db,
const char* propname);
......
......@@ -75,6 +75,7 @@ pub enum DBPerfContext {}
pub enum DBIOStatsContext {}
pub enum DBWriteStallInfo {}
pub enum DBStatusPtr {}
pub enum DBMapProperty {}
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
#[repr(C)]
......@@ -1206,6 +1207,25 @@ extern "C" {
include_end: bool,
errptr: *mut *mut c_char,
);
pub fn crocksdb_create_map_property() -> *mut DBMapProperty;
pub fn crocksdb_destroy_map_property(info: *mut DBMapProperty);
pub fn crocksdb_get_map_property_cf(
db: *mut DBInstance,
cf: *mut DBCFHandle,
name: *const c_char,
info: *mut DBMapProperty,
) -> bool;
pub fn crocksdb_map_property_value(
info: *const DBMapProperty,
propname: *const c_char,
) -> *mut c_char;
pub fn crocksdb_map_property_int_value(
info: *const DBMapProperty,
propname: *const c_char,
) -> uint64_t;
pub fn crocksdb_property_value(db: *mut DBInstance, propname: *const c_char) -> *mut c_char;
pub fn crocksdb_property_value_cf(
db: *mut DBInstance,
......
......@@ -35,8 +35,8 @@ pub use metadata::{ColumnFamilyMetaData, LevelMetaData, SstFileMetaData};
pub use perf_context::{get_perf_level, set_perf_level, IOStatsContext, PerfContext, PerfLevel};
pub use rocksdb::{
load_latest_options, run_ldb_tool, set_external_sst_file_global_seq_no, BackupEngine, CFHandle,
Cache, DBIterator, DBVector, Env, ExternalSstFileInfo, Kv, MemoryAllocator, Range, SeekKey,
SequentialFile, SstFileReader, SstFileWriter, Writable, WriteBatch, DB,
Cache, DBIterator, DBVector, Env, ExternalSstFileInfo, Kv, MapProperty, MemoryAllocator, Range,
SeekKey, SequentialFile, SstFileReader, SstFileWriter, Writable, WriteBatch, DB,
};
pub use rocksdb_options::{
BlockBasedOptions, CColumnFamilyDescriptor, ColumnFamilyOptions, CompactOptions,
......
......@@ -13,7 +13,7 @@
// limitations under the License.
use crocksdb_ffi::{
self, DBBackupEngine, DBCFHandle, DBCache, DBCompressionType, DBEnv, DBInstance,
self, DBBackupEngine, DBCFHandle, DBCache, DBCompressionType, DBEnv, DBInstance, DBMapProperty,
DBPinnableSlice, DBSequentialFile, DBStatisticsHistogramType, DBStatisticsTickerType,
DBTitanDBOptions, DBWriteBatch,
};
......@@ -87,6 +87,45 @@ fn build_cstring_list(str_list: &[&str]) -> Vec<CString> {
.collect()
}
pub struct MapProperty {
inner: *mut DBMapProperty,
}
impl Drop for MapProperty {
fn drop(&mut self) {
unsafe {
crocksdb_ffi::crocksdb_destroy_map_property(self.inner);
}
}
}
impl MapProperty {
pub fn new() -> MapProperty {
unsafe {
MapProperty {
inner: crocksdb_ffi::crocksdb_create_map_property(),
}
}
}
pub fn get_property_value(&self, property: &str) -> String {
let propname = CString::new(property.as_bytes()).unwrap();
unsafe {
let value = crocksdb_ffi::crocksdb_map_property_value(self.inner, propname.as_ptr());
return CStr::from_ptr(value).to_str().unwrap().to_owned();
}
}
pub fn get_property_int_value(&self, property: &str) -> u64 {
let propname = CString::new(property.as_bytes()).unwrap();
unsafe {
let value =
crocksdb_ffi::crocksdb_map_property_int_value(self.inner, propname.as_ptr());
return value as u64;
}
}
}
pub struct DB {
inner: *mut DBInstance,
cfs: BTreeMap<String, CFHandle>,
......@@ -1386,6 +1425,22 @@ impl DB {
}
}
pub fn get_map_property_cf(&self, cf: &CFHandle, name: &str) -> Option<MapProperty> {
unsafe {
let info = MapProperty::new();
let cname = CString::new(name.as_bytes()).unwrap();
if !crocksdb_ffi::crocksdb_get_map_property_cf(
self.inner,
cf.inner,
cname.as_ptr(),
info.inner,
) {
return None;
}
Some(info)
}
}
pub fn set_db_options(&self, options: &[(&str, &str)]) -> Result<(), String> {
unsafe {
let name_strs: Vec<_> = options
......@@ -3111,4 +3166,18 @@ mod test {
let seq2 = db.get_latest_sequence_number();
assert!(seq2 > seq1);
}
#[test]
fn test_map_property() {
let path = TempDir::new("_rust_rocksdb_get_map_property").expect("");
let dbpath = path.path().to_str().unwrap().clone();
let mut opts = DBOptions::new();
opts.create_if_missing(true);
let mut db = DB::open(opts, dbpath).unwrap();
let cf_handle = db.cf_handle("default").unwrap();
let mp = db.get_map_property_cf(cf_handle, "rocksdb.cfstats");
assert!(mp.is_some());
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment