/// <exception cref="System.IO.IOException"></exception> private static void MoveToBackup(DefragmentConfig config) { IStorage origStorage = config.Db4oConfig().Storage; if (origStorage == config.BackupStorage()) { origStorage.Rename(config.OrigPath(), config.BackupPath()); return; } CopyBin(origStorage, config.BackupStorage(), config.OrigPath(), config.BackupPath ()); origStorage.Delete(config.OrigPath()); }
/// <exception cref="System.IO.IOException"></exception> private static void UpgradeFile(DefragmentConfig config) { CopyBin(config.BackupStorage(), config.BackupStorage(), config.BackupPath(), config .TempPath()); IConfiguration db4oConfig = (IConfiguration)((Config4Impl)config.Db4oConfig()).DeepClone (null); db4oConfig.Storage = config.BackupStorage(); db4oConfig.AllowVersionUpdates(true); IObjectContainer db = Db4oFactory.OpenFile(db4oConfig, config.TempPath()); db.Close(); }
/// <exception cref="System.IO.IOException"></exception> public DefragmentServicesImpl(DefragmentConfig defragConfig, IDefragmentListener listener) { _listener = listener; Config4Impl originalConfig = (Config4Impl)defragConfig.Db4oConfig(); IStorage storage = defragConfig.BackupStorage(); if (defragConfig.ReadOnly()) { storage = new NonFlushingStorage(storage); } Config4Impl sourceConfig = PrepareConfig(originalConfig, storage, defragConfig.ReadOnly ()); _sourceDb = (LocalObjectContainer)Db4oFactory.OpenFile(sourceConfig, defragConfig .TempPath()).Ext(); _sourceDb.ShowInternalClasses(true); defragConfig.Db4oConfig().BlockSize(_sourceDb.BlockSize()); if (!originalConfig.GenerateCommitTimestamps().DefiniteNo()) { defragConfig.Db4oConfig().GenerateCommitTimestamps(_sourceDb.Config().GenerateCommitTimestamps ().DefiniteYes()); } _targetDb = FreshTargetFile(defragConfig); _mapping = defragConfig.Mapping(); _mapping.Open(); _defragConfig = defragConfig; }
/// <exception cref="System.IO.IOException"></exception> public DefragmentServicesImpl(DefragmentConfig defragConfig, IDefragmentListener listener) { _listener = listener; var originalConfig = (Config4Impl) defragConfig.Db4oConfig(); var storage = defragConfig.BackupStorage(); if (defragConfig.ReadOnly()) { storage = new NonFlushingStorage(storage); } var sourceConfig = PrepareConfig(originalConfig, storage, defragConfig.ReadOnly ()); _sourceDb = (LocalObjectContainer) Db4oFactory.OpenFile(sourceConfig, defragConfig .TempPath()).Ext(); _sourceDb.ShowInternalClasses(true); defragConfig.Db4oConfig().BlockSize(_sourceDb.BlockSize()); if (!originalConfig.GenerateCommitTimestamps().DefiniteNo()) { defragConfig.Db4oConfig().GenerateCommitTimestamps(_sourceDb.Config().GenerateCommitTimestamps ().DefiniteYes()); } _targetDb = FreshTargetFile(defragConfig); _mapping = defragConfig.Mapping(); _mapping.Open(); _defragConfig = defragConfig; }
public void ChangeBackupStorage() { // #example: Use a separate storage for the backup DefragmentConfig config = new DefragmentConfig("database.db4o"); config.BackupStorage(new FileStorage()); Defragment.Defrag(config); // #end example }
/// <summary> /// Renames the file at the configured original path to the configured backup /// path and then builds a defragmented version of the file in the original /// place. /// </summary> /// <remarks> /// Renames the file at the configured original path to the configured backup /// path and then builds a defragmented version of the file in the original /// place. /// </remarks> /// <param name="config">The configuration for this defragmentation run.</param> /// <param name="listener"> /// A listener for status notifications during the defragmentation /// process. /// </param> /// <exception cref="System.IO.IOException">if the original file cannot be moved to the backup location /// </exception> public static void Defrag(DefragmentConfig config, IDefragmentListener listener) { IStorage storage = config.Db4oConfig().Storage; EnsureFileExists(storage, config.OrigPath()); IStorage backupStorage = config.BackupStorage(); if (backupStorage.Exists(config.BackupPath())) { if (!config.ForceBackupDelete()) { throw new IOException("Could not use '" + config.BackupPath() + "' as backup path - file exists." ); } } // Always delete, because !exists can indicate length == 0 backupStorage.Delete(config.BackupPath()); MoveToBackup(config); if (config.FileNeedsUpgrade()) { UpgradeFile(config); } DefragmentServicesImpl services = new DefragmentServicesImpl(config, listener); try { FirstPass(services, config); services.CommitIds(); SecondPass(services, config); services.CommitIds(); DefragUnindexed(services); services.CommitIds(); services.DefragIdToTimestampBtree(); services.ReplaceClassMetadataRepository(); } catch (CorruptionException exc) { Sharpen.Runtime.PrintStackTrace(exc); } finally { services.Close(); } }
private DefragmentConfig DefragmentConfig(MemoryStorage storage) { DefragmentConfig defragConfig = new DefragmentConfig(Uri, TempFile(), new InMemoryIdMapping ()); defragConfig.Db4oConfig(Config(storage)); defragConfig.BackupStorage(BackupStorage()); return defragConfig; }
/// <exception cref="System.IO.IOException"></exception> private static void UpgradeFile(DefragmentConfig config) { CopyBin(config.BackupStorage(), config.BackupStorage(), config.BackupPath(), config .TempPath()); IConfiguration db4oConfig = (IConfiguration)((Config4Impl)config.Db4oConfig()).DeepClone (null); db4oConfig.Storage = config.BackupStorage(); db4oConfig.AllowVersionUpdates(true); IObjectContainer db = Db4oFactory.OpenFile(db4oConfig, config.TempPath()); db.Close(); }
/// <exception cref="System.IO.IOException"></exception> private static void MoveToBackup(DefragmentConfig config) { IStorage origStorage = config.Db4oConfig().Storage; if (origStorage == config.BackupStorage()) { origStorage.Rename(config.OrigPath(), config.BackupPath()); return; } CopyBin(origStorage, config.BackupStorage(), config.OrigPath(), config.BackupPath ()); origStorage.Delete(config.OrigPath()); }
/// <summary> /// Renames the file at the configured original path to the configured backup /// path and then builds a defragmented version of the file in the original /// place. /// </summary> /// <remarks> /// Renames the file at the configured original path to the configured backup /// path and then builds a defragmented version of the file in the original /// place. /// </remarks> /// <param name="config">The configuration for this defragmentation run.</param> /// <param name="listener"> /// A listener for status notifications during the defragmentation /// process. /// </param> /// <exception cref="System.IO.IOException">if the original file cannot be moved to the backup location /// </exception> public static void Defrag(DefragmentConfig config, IDefragmentListener listener) { IStorage storage = config.Db4oConfig().Storage; EnsureFileExists(storage, config.OrigPath()); IStorage backupStorage = config.BackupStorage(); if (backupStorage.Exists(config.BackupPath())) { if (!config.ForceBackupDelete()) { throw new IOException("Could not use '" + config.BackupPath() + "' as backup path - file exists." ); } } // Always delete, because !exists can indicate length == 0 backupStorage.Delete(config.BackupPath()); MoveToBackup(config); if (config.FileNeedsUpgrade()) { UpgradeFile(config); } DefragmentServicesImpl services = new DefragmentServicesImpl(config, listener); try { FirstPass(services, config); services.CommitIds(); SecondPass(services, config); services.CommitIds(); DefragUnindexed(services); services.CommitIds(); services.DefragIdToTimestampBtree(); services.ReplaceClassMetadataRepository(); } catch (CorruptionException exc) { Sharpen.Runtime.PrintStackTrace(exc); } finally { services.Close(); } }