Ejemplo n.º 1
0
        /// <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;
			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;
		}
Ejemplo n.º 3
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();
            }
        }
Ejemplo n.º 4
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();
			}
		}