Пример #1
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();
            }
        }
Пример #2
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();
			}
		}