diff --git a/ethcore/src/migrations/mod.rs b/ethcore/src/migrations/mod.rs
index b9a00a15e..6cc4a13a8 100644
--- a/ethcore/src/migrations/mod.rs
+++ b/ethcore/src/migrations/mod.rs
@@ -28,4 +28,4 @@ mod v10;
pub use self::v10::ToV10;
mod v11;
-pub use self::v11::ToV11;
+pub use self::v11::TO_V11;
diff --git a/ethcore/src/migrations/v11.rs b/ethcore/src/migrations/v11.rs
index 8795cf364..e33de6170 100644
--- a/ethcore/src/migrations/v11.rs
+++ b/ethcore/src/migrations/v11.rs
@@ -14,33 +14,13 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see .
-
//! Adds a seventh column for node information.
-use util::kvdb::Database;
-use util::migration::{Batch, Config, Error, Migration, Progress};
-use std::sync::Arc;
+use util::migration::ChangeColumns;
-/// Copies over data for all existing columns.
-#[derive(Default)]
-pub struct ToV11(Progress);
-
-
-impl Migration for ToV11 {
- fn pre_columns(&self) -> Option { Some(6) }
- fn columns(&self) -> Option { Some(7) }
-
- fn version(&self) -> u32 { 11 }
-
- fn migrate(&mut self, source: Arc, config: &Config, dest: &mut Database, col: Option) -> Result<(), Error> {
- // just copy everything over.
- let mut batch = Batch::new(config, col);
-
- for (key, value) in source.iter(col) {
- self.0.tick();
- batch.insert(key.to_vec(), value.to_vec(), dest)?
- }
-
- batch.commit(dest)
- }
-}
+/// The migration from v10 to v11.
+pub const TO_V11: ChangeColumns = ChangeColumns {
+ pre_columns: Some(6),
+ post_columns: Some(7),
+ version: 11,
+};
diff --git a/parity/migration.rs b/parity/migration.rs
index c2d5c0797..445724325 100644
--- a/parity/migration.rs
+++ b/parity/migration.rs
@@ -146,7 +146,7 @@ pub fn default_migration_settings(compaction_profile: &CompactionProfile) -> Mig
fn consolidated_database_migrations(compaction_profile: &CompactionProfile) -> Result {
let mut manager = MigrationManager::new(default_migration_settings(compaction_profile));
manager.add_migration(migrations::ToV10::new()).map_err(|_| Error::MigrationImpossible)?;
- manager.add_migration(migrations::ToV11::default()).map_err(|_| Error::MigrationImpossible)?;
+ manager.add_migration(migrations::TO_V11).map_err(|_| Error::MigrationImpossible)?;
Ok(manager)
}
@@ -201,6 +201,10 @@ fn migrate_database(version: u32, db_path: PathBuf, mut migrations: MigrationMan
// migrate old database to the new one
let temp_path = migrations.execute(&db_path, version)?;
+ // completely in-place migration leads to the paths being equal.
+ // in that case, no need to shuffle directories.
+ if temp_path == db_path { return Ok(()) }
+
// create backup
fs::rename(&db_path, &backup_path)?;
@@ -212,9 +216,7 @@ fn migrate_database(version: u32, db_path: PathBuf, mut migrations: MigrationMan
}
// remove backup
- fs::remove_dir_all(&backup_path)?;
-
- Ok(())
+ fs::remove_dir_all(&backup_path).map_err(Into::into)
}
fn exists(path: &Path) -> bool {
diff --git a/util/src/kvdb.rs b/util/src/kvdb.rs
index 1714ce22f..043b3d983 100644
--- a/util/src/kvdb.rs
+++ b/util/src/kvdb.rs
@@ -410,6 +410,29 @@ struct DBAndColumns {
cfs: Vec,
}
+// get column family configuration from database config.
+fn col_config(col: u32, config: &DatabaseConfig) -> Options {
+ // default cache size for columns not specified.
+ const DEFAULT_CACHE: usize = 2;
+
+ let mut opts = Options::new();
+ opts.set_compaction_style(DBCompactionStyle::DBUniversalCompaction);
+ opts.set_target_file_size_base(config.compaction.initial_file_size);
+ opts.set_target_file_size_multiplier(config.compaction.file_size_multiplier);
+
+ let col_opt = config.columns.map(|_| col);
+
+ {
+ let cache_size = config.cache_sizes.get(&col_opt).cloned().unwrap_or(DEFAULT_CACHE);
+ let mut block_opts = BlockBasedOptions::new();
+ // all goes to read cache.
+ block_opts.set_cache(Cache::new(cache_size * 1024 * 1024));
+ opts.set_block_based_table_factory(&block_opts);
+ }
+
+ opts
+}
+
/// Key-Value database.
pub struct Database {
db: RwLock