/// <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);
		}
 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);
         }
     }
 }
Beispiel #3
0
		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>
 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);
		}
Beispiel #6
0
 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 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.");
        }
 /// <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>
		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);
		}
		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);
		}
Beispiel #12
0
        /// <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();
            }
        }
Beispiel #13
0
        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>
		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);
			}
		}
		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);
		}
		/// <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();
			}
		}
Beispiel #17
0
 /// <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);
 }