Permalink
Browse files

RavenDB-5800 Fixing Backup/Restore index madness

  • Loading branch information...
1 parent 67e175d commit b98ec79ca3c4312cfcbc5907e149f78618aeed90 @talweiss1982 talweiss1982 committed with ayende Dec 20, 2016
@@ -49,7 +49,7 @@ internal static string FindDatabaseDocument(string rootBackupPath)
return backupPath ?? Path.Combine(rootBackupPath, Constants.DatabaseDocumentFilename);
}
- public static void Restore(RavenConfiguration configuration, DatabaseRestoreRequest restoreRequest, Action<string> output)
+ public static void Restore(RavenConfiguration configuration, DatabaseRestoreRequest restoreRequest, Action<string> output, InMemoryRavenConfiguration globalConfiguration = null)
{
var databaseDocumentPath = FindDatabaseDocument(restoreRequest.BackupLocation);
if (File.Exists(databaseDocumentPath) == false)
@@ -80,10 +80,10 @@ public static void Restore(RavenConfiguration configuration, DatabaseRestoreRequ
{
configuration.DataDirectory = restoreRequest.DatabaseLocation;
}
-
+
using (var transactionalStorage = configuration.CreateTransactionalStorage(storage, () => { }, () => { }))
{
- transactionalStorage.Restore(restoreRequest, output);
+ transactionalStorage.Restore(restoreRequest, output, globalConfiguration);
}
}
@@ -361,7 +361,7 @@ protected override WindowsBuiltInRole[] AdditionalSupportedRoles
restoreStatus.Messages.Add(msg);
DatabasesLandlord.SystemDatabase.Documents.Put(RestoreStatus.RavenRestoreStatusDocumentKey, null,
RavenJObject.FromObject(restoreStatus), new RavenJObject(), null);
- });
+ }, SystemConfiguration);
if (databaseDocument == null)
return;
@@ -19,18 +19,34 @@ internal abstract class BaseRestoreOperation
protected readonly DatabaseRestoreRequest _restoreRequest;
protected readonly InMemoryRavenConfiguration Configuration;
- protected readonly string databaseLocation, indexLocation, journalLocation;
+ protected readonly string databaseLocation, indexLocation, indexDefinitionLocation, journalLocation;
- protected BaseRestoreOperation(DatabaseRestoreRequest restoreRequest, InMemoryRavenConfiguration configuration, Action<string> output)
+ protected BaseRestoreOperation(DatabaseRestoreRequest restoreRequest, InMemoryRavenConfiguration configuration, InMemoryRavenConfiguration globalConfiguration, Action<string> output)
{
_restoreRequest = restoreRequest;
backupLocation = restoreRequest.BackupLocation;
databaseLocation = _restoreRequest.DatabaseLocation.ToFullPath();
- indexLocation = (_restoreRequest.IndexesLocation ?? Path.Combine(_restoreRequest.DatabaseLocation, "Indexes")).ToFullPath();
+ indexLocation = GenerateIndexLocation(_restoreRequest, configuration, globalConfiguration).ToFullPath();
journalLocation = (_restoreRequest.JournalsLocation ?? _restoreRequest.DatabaseLocation).ToFullPath();
Configuration = configuration;
this.output = output;
}
+
+ private string GenerateIndexLocation(DatabaseRestoreRequest databaseRestoreRequest, InMemoryRavenConfiguration configuration, InMemoryRavenConfiguration globalConfiguration)
+ {
+ //If we got the index location in the request use that.
+ if (databaseRestoreRequest.IndexesLocation != null)
+ return databaseRestoreRequest.IndexesLocation;
+ //If the system database uses the <database-name>\Indexes\ folder then we did not change the global index folder
+ //We can safly create the index folder under the path of the database because this is where it is going to be looked for
+ if (globalConfiguration.IndexStoragePath.EndsWith("\\System\\Indexes"))
+ return Path.Combine(_restoreRequest.DatabaseLocation, "Indexes");
+ //system database restore with global config
+ if (string.IsNullOrEmpty(configuration.DatabaseName))
+ return globalConfiguration.IndexStoragePath;
+ //If we got here than the global config has a value for index storage path, will just use that folder
+ return $"{globalConfiguration.IndexStoragePath}\\Databases\\{configuration.DatabaseName}";
+ }
public abstract void Execute();
@@ -18,8 +18,8 @@ namespace Raven.Database.Storage.Esent.Backup
{
internal class RestoreOperation : BaseRestoreOperation
{
- public RestoreOperation(DatabaseRestoreRequest restoreRequest, InMemoryRavenConfiguration configuration, Action<string> operationOutputCallback)
- : base(restoreRequest, configuration, operationOutputCallback)
+ public RestoreOperation(DatabaseRestoreRequest restoreRequest, InMemoryRavenConfiguration configuration, InMemoryRavenConfiguration globalConfiguration, Action<string> operationOutputCallback)
+ : base(restoreRequest, configuration, globalConfiguration, operationOutputCallback)
{
}
@@ -219,9 +219,9 @@ public Task StartBackupOperation(DocumentDatabase docDb, string backupDestinatio
.StartNew(backupOperation.Execute);
}
- public void Restore(DatabaseRestoreRequest restoreRequest, Action<string> output)
+ public void Restore(DatabaseRestoreRequest restoreRequest, Action<string> output,InMemoryRavenConfiguration globalConfiguration)
{
- new RestoreOperation(restoreRequest, configuration, output).Execute();
+ new RestoreOperation(restoreRequest, configuration,globalConfiguration, output).Execute();
}
public DatabaseSizeInformation GetDatabaseSize()
@@ -36,7 +36,7 @@ public interface ITransactionalStorage : IDisposable
void ExecuteImmediatelyOrRegisterForSynchronization(Action action);
void Initialize(IUuidGenerator generator, OrderedPartCollection<AbstractDocumentCodec> documentCodecs, Action<string> putResourceMarker = null);
Task StartBackupOperation(DocumentDatabase database, string backupDestinationDirectory, bool incrementalBackup, DatabaseDocument documentDatabase, ResourceBackupState state, CancellationToken cts);
- void Restore(DatabaseRestoreRequest restoreRequest, Action<string> output);
+ void Restore(DatabaseRestoreRequest restoreRequest, Action<string> output, InMemoryRavenConfiguration globalConfiguration);
DatabaseSizeInformation GetDatabaseSize();
long GetDatabaseCacheSizeInBytes();
long GetDatabaseTransactionVersionSizeInBytes();
@@ -11,8 +11,8 @@ namespace Raven.Database.Storage.Voron.Backup
{
internal class RestoreOperation : BaseRestoreOperation
{
- public RestoreOperation(DatabaseRestoreRequest restoreRequest, InMemoryRavenConfiguration configuration, Action<string> operationOutputCallback)
- : base(restoreRequest, configuration, operationOutputCallback)
+ public RestoreOperation(DatabaseRestoreRequest restoreRequest, InMemoryRavenConfiguration configuration, InMemoryRavenConfiguration globalConfiguration, Action<string> operationOutputCallback)
+ : base(restoreRequest, configuration, globalConfiguration, operationOutputCallback)
{
}
@@ -501,9 +501,9 @@ private static StorageEnvironmentOptions CreateStorageOptionsFromConfiguration(I
});
}
- public void Restore(DatabaseRestoreRequest restoreRequest, Action<string> output)
+ public void Restore(DatabaseRestoreRequest restoreRequest, Action<string> output, InMemoryRavenConfiguration globalConfiguration)
{
- new RestoreOperation(restoreRequest, configuration, output).Execute();
+ new RestoreOperation(restoreRequest, configuration, globalConfiguration, output).Execute();
}
public DatabaseSizeInformation GetDatabaseSize()
@@ -758,7 +758,7 @@ private static void RunSystemDatabaseRestoreOperation(string backupLocation, str
BackupLocation = backupLocation,
DatabaseLocation = databaseLocation,
Defrag = defrag
- }, Console.WriteLine);
+ }, Console.WriteLine, ravenConfiguration);
}
catch (Exception e)
{

0 comments on commit b98ec79

Please sign in to comment.