change migration to v11 to be faster
This commit is contained in:
parent
3cc007b4d6
commit
c2c699abb9
@ -28,4 +28,4 @@ mod v10;
|
|||||||
pub use self::v10::ToV10;
|
pub use self::v10::ToV10;
|
||||||
|
|
||||||
mod v11;
|
mod v11;
|
||||||
pub use self::v11::ToV11;
|
pub use self::v11::TO_V11;
|
||||||
|
@ -14,33 +14,13 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
//! Adds a seventh column for node information.
|
//! Adds a seventh column for node information.
|
||||||
|
|
||||||
use util::kvdb::Database;
|
use util::migration::ChangeColumns;
|
||||||
use util::migration::{Batch, Config, Error, Migration, Progress};
|
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
/// Copies over data for all existing columns.
|
/// The migration from v10 to v11.
|
||||||
#[derive(Default)]
|
pub const TO_V11: ChangeColumns = ChangeColumns {
|
||||||
pub struct ToV11(Progress);
|
pre_columns: Some(6),
|
||||||
|
post_columns: Some(7),
|
||||||
|
version: 11,
|
||||||
impl Migration for ToV11 {
|
};
|
||||||
fn pre_columns(&self) -> Option<u32> { Some(6) }
|
|
||||||
fn columns(&self) -> Option<u32> { Some(7) }
|
|
||||||
|
|
||||||
fn version(&self) -> u32 { 11 }
|
|
||||||
|
|
||||||
fn migrate(&mut self, source: Arc<Database>, config: &Config, dest: &mut Database, col: Option<u32>) -> 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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -146,7 +146,7 @@ pub fn default_migration_settings(compaction_profile: &CompactionProfile) -> Mig
|
|||||||
fn consolidated_database_migrations(compaction_profile: &CompactionProfile) -> Result<MigrationManager, Error> {
|
fn consolidated_database_migrations(compaction_profile: &CompactionProfile) -> Result<MigrationManager, Error> {
|
||||||
let mut manager = MigrationManager::new(default_migration_settings(compaction_profile));
|
let mut manager = MigrationManager::new(default_migration_settings(compaction_profile));
|
||||||
manager.add_migration(migrations::ToV10::new()).map_err(|_| Error::MigrationImpossible)?;
|
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)
|
Ok(manager)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,6 +167,23 @@ impl<T: SimpleMigration> Migration for T {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// An even simpler migration which just changes the number of columns.
|
||||||
|
pub struct ChangeColumns {
|
||||||
|
pub pre_columns: Option<u32>,
|
||||||
|
pub post_columns: Option<u32>,
|
||||||
|
pub version: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Migration for ChangeColumns {
|
||||||
|
fn pre_columns(&self) -> Option<u32> { self.pre_columns }
|
||||||
|
fn columns(&self) -> Option<u32> { self.post_columns }
|
||||||
|
fn version(&self) -> u32 { self.version }
|
||||||
|
fn alters_existing(&self) -> bool { false }
|
||||||
|
fn migrate(&mut self, _: Arc<Database>, _: &Config, _: &mut Database, _: Option<u32>) -> Result<(), Error> {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Get the path where all databases reside.
|
/// Get the path where all databases reside.
|
||||||
fn database_path(path: &Path) -> PathBuf {
|
fn database_path(path: &Path) -> PathBuf {
|
||||||
let mut temp_path = path.to_owned();
|
let mut temp_path = path.to_owned();
|
||||||
|
Loading…
Reference in New Issue
Block a user