Automatic compaction selection on Linux (#2785)
* add auto compaction types * pass db paths * detect drive type on Linux * use base db path * add docstring * limit the test to be side effect free * use base db path * more docs * fix parsing test * update error * detect only on Linux * make test Linux only * add second device letter, update cli doc * use spaces in cli doc * import only on linux * default->auto
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use std::str::FromStr;
|
||||
use std::path::Path;
|
||||
pub use std::time::Duration;
|
||||
pub use blockchain::Config as BlockChainConfig;
|
||||
pub use trace::Config as TraceConfig;
|
||||
@@ -26,23 +27,26 @@ use util::{journaldb, CompactionProfile};
|
||||
/// Client state db compaction profile
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum DatabaseCompactionProfile {
|
||||
/// Default compaction profile
|
||||
Default,
|
||||
/// Try to determine compaction profile automatically
|
||||
Auto,
|
||||
/// SSD compaction profile
|
||||
SSD,
|
||||
/// HDD or other slow storage io compaction profile
|
||||
HDD,
|
||||
}
|
||||
|
||||
impl Default for DatabaseCompactionProfile {
|
||||
fn default() -> Self {
|
||||
DatabaseCompactionProfile::Default
|
||||
DatabaseCompactionProfile::Auto
|
||||
}
|
||||
}
|
||||
|
||||
impl DatabaseCompactionProfile {
|
||||
/// Returns corresponding compaction profile.
|
||||
pub fn compaction_profile(&self) -> CompactionProfile {
|
||||
pub fn compaction_profile(&self, db_path: &Path) -> CompactionProfile {
|
||||
match *self {
|
||||
DatabaseCompactionProfile::Default => Default::default(),
|
||||
DatabaseCompactionProfile::Auto => CompactionProfile::auto(db_path),
|
||||
DatabaseCompactionProfile::SSD => CompactionProfile::ssd(),
|
||||
DatabaseCompactionProfile::HDD => CompactionProfile::hdd(),
|
||||
}
|
||||
}
|
||||
@@ -53,9 +57,10 @@ impl FromStr for DatabaseCompactionProfile {
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
match s {
|
||||
"ssd" | "default" => Ok(DatabaseCompactionProfile::Default),
|
||||
"auto" => Ok(DatabaseCompactionProfile::Auto),
|
||||
"ssd" => Ok(DatabaseCompactionProfile::SSD),
|
||||
"hdd" => Ok(DatabaseCompactionProfile::HDD),
|
||||
_ => Err("Invalid compaction profile given. Expected hdd/ssd (default).".into()),
|
||||
_ => Err("Invalid compaction profile given. Expected default/hdd/ssd.".into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -120,13 +125,13 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn test_default_compaction_profile() {
|
||||
assert_eq!(DatabaseCompactionProfile::default(), DatabaseCompactionProfile::Default);
|
||||
assert_eq!(DatabaseCompactionProfile::default(), DatabaseCompactionProfile::Auto);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parsing_compaction_profile() {
|
||||
assert_eq!(DatabaseCompactionProfile::Default, "ssd".parse().unwrap());
|
||||
assert_eq!(DatabaseCompactionProfile::Default, "default".parse().unwrap());
|
||||
assert_eq!(DatabaseCompactionProfile::Auto, "auto".parse().unwrap());
|
||||
assert_eq!(DatabaseCompactionProfile::SSD, "ssd".parse().unwrap());
|
||||
assert_eq!(DatabaseCompactionProfile::HDD, "hdd".parse().unwrap());
|
||||
}
|
||||
|
||||
|
||||
@@ -87,7 +87,7 @@ impl ClientService {
|
||||
db_config.set_cache(::db::COL_STATE, size);
|
||||
}
|
||||
|
||||
db_config.compaction = config.db_compaction.compaction_profile();
|
||||
db_config.compaction = config.db_compaction.compaction_profile(&client_path);
|
||||
db_config.wal = config.db_wal;
|
||||
|
||||
let pruning = config.pruning;
|
||||
|
||||
Reference in New Issue
Block a user