private void Defrag(IConfiguration config) { var origFile = new File(GetAbsolutePath()); if (origFile.Exists()) { try { var backupFile = GetAbsolutePath() + ".defrag.backup"; IIdMapping mapping = new InMemoryIdMapping(); // new // BTreeIDMapping(getAbsolutePath()+".defrag.mapping",4096,1,1000); var defragConfig = new DefragmentConfig(GetAbsolutePath(), backupFile , mapping); defragConfig.ForceBackupDelete(true); // FIXME Cloning is ugly - wrap original in Decorator within // DefragContext instead? var clonedConfig = (IConfiguration) ((IDeepClone) config).DeepClone(null ); defragConfig.Db4oConfig(clonedConfig); Db4objects.Db4o.Defragment.Defragment.Defrag(defragConfig, new _IDefragmentListener_64 ()); } catch (IOException e) { Runtime.PrintStackTrace(e); } } }
private DefragmentConfig NewDefragmentConfig(string sourceFile, string backupFile ) { var config = new DefragmentConfig(sourceFile, backupFile); config.Db4oConfig(NewConfiguration()); return config; }
/// <exception cref="System.IO.IOException"></exception> private void Defragment(bool registerTranslator) { DefragmentConfig defragConfig = new DefragmentConfig(TempFile()); defragConfig.Db4oConfig(Config(registerTranslator)); defragConfig.ForceBackupDelete(true); Db4objects.Db4o.Defragment.Defragment.Defrag(defragConfig); }
protected override IObjectContainer CreateDatabase(IConfiguration config) { Sharpen.IO.File origFile = new Sharpen.IO.File(GetAbsolutePath()); if (origFile.Exists()) { try { string backupFile = GetAbsolutePath() + ".defrag.backup"; IIdMapping mapping = new InMemoryIdMapping(); // new // BTreeIDMapping(getAbsolutePath()+".defrag.mapping",4096,1,1000); DefragmentConfig defragConfig = new DefragmentConfig(GetAbsolutePath(), backupFile , mapping); defragConfig.ForceBackupDelete(true); // FIXME Cloning is ugly - wrap original in Decorator within // DefragContext instead? IConfiguration clonedConfig = (IConfiguration)((IDeepClone)config).DeepClone(null ); defragConfig.Db4oConfig(clonedConfig); Db4objects.Db4o.Defragment.Defragment.Defrag(defragConfig, new _IDefragmentListener_30 ()); } catch (IOException e) { Sharpen.Runtime.PrintStackTrace(e); } } return base.CreateDatabase(config); }
/// <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="Db4objects.Db4o.CorruptionException"></exception> /// <exception cref="System.IO.IOException"></exception> private static void Pass(DefragmentServicesImpl context, DefragmentConfig config, IPassCommand command) { command.ProcessClassCollection(context); IStoredClass[] classes = context.StoredClasses(DefragmentServicesImpl.Sourcedb); for (int classIdx = 0; classIdx < classes.Length; classIdx++) { ClassMetadata classMetadata = (ClassMetadata)classes[classIdx]; if (!config.StoredClassFilter().Accept(classMetadata)) { continue; } ProcessClass(context, classMetadata, command); command.Flush(context); if (config.ObjectCommitFrequency() > 0) { context.TargetCommit(); } } BTree uuidIndex = context.SourceUuidIndex(); if (uuidIndex != null) { command.ProcessBTree(context, uuidIndex); } command.Flush(context); context.TargetCommit(); }
// #end example private static void DefragmentWithConfiguration() { CreateAndFillDatabase(); // #example: Defragment with configuration DefragmentConfig config = new DefragmentConfig("database.db4o"); Defragment.Defrag(config); // #end example }
/// <exception cref="System.IO.IOException"></exception> private void Defrag() { var backupPath = Path.GetTempFileName(); var config = new DefragmentConfig(TempFile(), backupPath); config.ForceBackupDelete(true); Defragment.Defragment.Defrag(config); Delete(backupPath); }
/// <exception cref="System.IO.IOException"></exception> private void Defrag() { string backupPath = Path.GetTempFileName(); DefragmentConfig config = new DefragmentConfig(TempFile(), backupPath); config.ForceBackupDelete(true); Db4objects.Db4o.Defragment.Defragment.Defrag(config); Delete(backupPath); }
/// <exception cref="System.IO.IOException"></exception> private void Defrag(string fname) { var config = new DefragmentConfig(fname); config.Db4oConfig(NewConfiguration()); config.StoredClassFilter(IgnoreClassFilter(typeof (SimpleClass ))); Db4o.Defragment.Defragment.Defrag(config); }
public void ConfigureBackupFile() { // #example: Configure the file and backup file DefragmentConfig config = new DefragmentConfig("database.db4o", "database.db4o.back"); Defragment.Defrag(config); // #end example }
public void ConfigureFile() { // #example: Configure the file DefragmentConfig config = new DefragmentConfig("database.db4o"); Defragment.Defrag(config); // #end example }
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 }
public static DefragmentConfig DefragConfig(string sourceFile, IEmbeddedConfiguration db4oConfig, bool forceBackupDelete) { var defragConfig = new DefragmentConfig(sourceFile, DefragmentTestCaseBase .BackupFileNameFor(sourceFile)); defragConfig.ForceBackupDelete(forceBackupDelete); defragConfig.Db4oConfig(Db4oConfig(db4oConfig)); return defragConfig; }
public void DeleteBackup() { // #example: Delete the backup after the defragmentation process DefragmentConfig config = new DefragmentConfig("database.db4o"); config.ForceBackupDelete(true); Defragment.Defrag(config); // #end example }
public void SetCommitFrequency() { // #example: Set the commit frequency DefragmentConfig config = new DefragmentConfig("database.db4o"); config.ObjectCommitFrequency(10000); Defragment.Defrag(config); // #end example }
public void SetMappingImplementation() { // #example: Choose a id mapping system IIdMapping mapping = new InMemoryIdMapping(); DefragmentConfig config = new DefragmentConfig("database.db4o", "database.db4o.back", mapping); Defragment.Defrag(config); // #end example }
public void DisableReadOnlyForBackup() { // #example: Disable readonly on backup DefragmentConfig config = new DefragmentConfig("database.db4o"); config.ReadOnly(false); Defragment.Defrag(config); // #end example }
/// <exception cref="System.IO.IOException"></exception> internal static LocalObjectContainer FreshTargetFile(DefragmentConfig config) { config.Db4oConfig().Storage.Delete(config.OrigPath()); IConfiguration clonedDb4oConfig = config.ClonedDb4oConfig(); clonedDb4oConfig.ReadOnly(false); return((LocalObjectContainer)Db4oFactory.OpenFile(clonedDb4oConfig, config.OrigPath ())); }
public void Test() { GenerateDatabaseFile(); var config = new DefragmentConfig(TempFile()); config.ForceBackupDelete(true); var e = Assert.Expect(typeof (InvalidOperationException), delegate { Defragment.Defragment.Defrag(config); }); Assert.IsTrue(e.Message.Contains("Thing"), "Message should contain the missing type name."); }
private static void DefragmentationWithIdMissing() { CreateAndFillDatabase(); // #example: Use a defragmentation listener DefragmentConfig config = new DefragmentConfig("database.db4o"); Defragment.Defrag(config, new DefragmentListener()); // #end example }
public void SetDb4OConfiguration() { // #example: Use the database-configuration DefragmentConfig config = new DefragmentConfig("database.db4o"); // It's best to use the very same configuration you use for the regular database IEmbeddedConfiguration configuration = Db4oEmbedded.NewConfiguration(); config.Db4oConfig(configuration); Defragment.Defrag(config); // #end example }
/// <exception cref="System.Exception"></exception> public virtual void TestCOR775() { Prepare(); VerifyDB(); var config = new DefragmentConfig(TempFile(), Defgared); config.ForceBackupDelete(true); //config.storedClassFilter(new AvailableClassFilter()); config.Db4oConfig(GetConfiguration()); Db4o.Defragment.Defragment.Defrag(config); VerifyDB(); }
/// <exception cref="System.IO.IOException"></exception> internal static LocalObjectContainer FreshTempFile(string fileName, int blockSize ) { FileStorage storage = new FileStorage(); storage.Delete(fileName); IConfiguration db4oConfig = DefragmentConfig.VanillaDb4oConfig(blockSize); db4oConfig.ObjectClass(typeof(IdSlotMapping)).ObjectField("_id").Indexed(true); db4oConfig.Storage = storage; return((LocalObjectContainer)Db4oFactory.OpenFile(db4oConfig, fileName).Ext()); }
public void TestDefragWorksAfterReopening() { Environment().InvokeInstanceMethod(GetType(), "CreateDatabase", db4oFilePath, true); using(var db = Db4oEmbedded.OpenFile(db4oFilePath)) { } var config = new DefragmentConfig(db4oFilePath); config.ForceBackupDelete(true); Defragment.Defragment.Defrag(config); }
/// <exception cref="System.IO.IOException"></exception> private void Defrag(TernaryBool generateCommitTimestamp) { DefragmentConfig config = new DefragmentConfig(SourceFile(), BackupFile()); config.Db4oConfig(NewConfiguration()); config.ForceBackupDelete(true); if (!generateCommitTimestamp.IsUnspecified()) { config.Db4oConfig().GenerateCommitTimestamps(generateCommitTimestamp.DefiniteYes( )); } Db4objects.Db4o.Defragment.Defragment.Defrag(config); }
/// <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(); }
/// <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 void Defrag(string fileName, int blockSize) { DefragmentConfig config = new DefragmentConfig(fileName); config.Db4oConfig(Config(blockSize)); config.ForceBackupDelete(true); Db4objects.Db4o.Defragment.Defragment.Defrag(config); }
/// <exception cref="Db4objects.Db4o.CorruptionException"></exception> /// <exception cref="System.IO.IOException"></exception> private static void SecondPass(DefragmentServicesImpl context, DefragmentConfig config ) { // System.out.println("SECOND"); Pass(context, config, new SecondPassCommand(config.ObjectCommitFrequency())); }
private DefragmentConfig DefragmentConfig(MemoryStorage storage) { DefragmentConfig defragConfig = new DefragmentConfig(Uri, TempFile(), new InMemoryIdMapping ()); defragConfig.Db4oConfig(Config(storage)); defragConfig.BackupStorage(BackupStorage()); return defragConfig; }
void DefragDatabase() { if (!File.Exists(DatabaseFile)) { return; } DateTime start = DateTime.UtcNow, stop; var backupFile = String.Format( "{0}.bak_{1}.{2}", DatabaseFile, Db4oVersion.Major, Db4oVersion.Minor ); var defragConfig = new DefragmentConfig( DatabaseFile, backupFile ); defragConfig.ForceBackupDelete(true); Defragment.Defrag(defragConfig); stop = DateTime.UtcNow; #if LOG4NET Logger.Debug( String.Format( "DefragDatabase(): defrag took: {0:0.0} ms", (stop - start).TotalMilliseconds ) ); #endif }
/// <exception cref="System.IO.IOException"></exception> internal static LocalObjectContainer FreshTargetFile(DefragmentConfig config) { config.Db4oConfig().Storage.Delete(config.OrigPath()); return((LocalObjectContainer)Db4oFactory.OpenFile(config.ClonedDb4oConfig(), config .OrigPath())); }
/// <exception cref="System.IO.IOException"></exception> public static void AssertIndex(string fieldName, string databaseFileName, IClosure4 configProvider) { ForceIndex(databaseFileName, ((IEmbeddedConfiguration) configProvider.Run())); var defragConfig = new DefragmentConfig(databaseFileName, DefragmentTestCaseBase .BackupFileNameFor(databaseFileName)); defragConfig.Db4oConfig(((IEmbeddedConfiguration) configProvider.Run())); Db4o.Defragment.Defragment.Defrag(defragConfig); IObjectContainer db = Db4oEmbedded.OpenFile(((IEmbeddedConfiguration) configProvider .Run()), databaseFileName); var query = db.Query(); query.Constrain(typeof (Data)); query.Descend(fieldName).Constrain(Value); var result = query.Execute(); Assert.AreEqual(1, result.Count); db.Close(); }
/// <exception cref="System.IO.IOException"></exception> private void RunDefrag(string testFileName) { IConfiguration config = Db4oFactory.NewConfiguration(); config.AllowVersionUpdates(true); ConfigureForTest(config); IObjectContainer oc = Db4oFactory.OpenFile(config, testFileName); oc.Close(); string backupFileName = Path.GetTempFileName(); try { DefragmentConfig defragConfig = new DefragmentConfig(testFileName, backupFileName ); defragConfig.ForceBackupDelete(true); ConfigureForTest(defragConfig.Db4oConfig()); defragConfig.ReadOnly(!DefragmentInReadWriteMode()); Db4objects.Db4o.Defragment.Defragment.Defrag(defragConfig); } finally { File4.Delete(backupFileName); } }
/// <exception cref="Db4objects.Db4o.CorruptionException"></exception> /// <exception cref="System.IO.IOException"></exception> private static void FirstPass(DefragmentServicesImpl context, DefragmentConfig config ) { // System.out.println("FIRST"); Pass(context, config, new FirstPassCommand()); }
/// <exception cref="System.Exception"></exception> protected virtual void Defragment(string fileName) { var targetFile = fileName + ".defrag.backup"; var defragConfig = new DefragmentConfig(fileName, targetFile); defragConfig.ForceBackupDelete(true); defragConfig.Db4oConfig(CloneConfiguration()); Db4objects.Db4o.Defragment.Defragment.Defrag(defragConfig); }
/// <exception cref="System.IO.IOException"></exception> internal static LocalObjectContainer FreshTargetFile(DefragmentConfig config) { config.Db4oConfig().Storage.Delete(config.OrigPath()); return (LocalObjectContainer)Db4oFactory.OpenFile(config.ClonedDb4oConfig(), 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> /// <exception cref="System.IO.IOException">if the original file cannot be moved to the backup location /// </exception> public static void Defrag(DefragmentConfig config) { Defrag(config, new Defragment.NullListener()); }