Skip to content

Commit

Permalink
RavenDB-20095 added file name and counts to restore progres
Browse files Browse the repository at this point in the history
  • Loading branch information
ppekrol authored and ml054 committed Jun 30, 2023
1 parent 77cc516 commit b06bec2
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 7 deletions.
27 changes: 22 additions & 5 deletions src/Raven.Client/Documents/Smuggler/SmugglerResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ public class DatabaseRecordProgress : Counts
public bool OlapEtlsUpdated { get; set; }

public bool OlapConnectionStringsUpdated { get; set; }

public bool ElasticSearchEtlsUpdated { get; set; }

public bool ElasticSearchConnectionStringsUpdated { get; set; }
Expand All @@ -297,7 +297,7 @@ public class DatabaseRecordProgress : Counts
public bool QueueEtlsUpdated { get; set; }

public bool QueueConnectionStringsUpdated { get; set; }

public bool IndexesHistoryUpdated { get; set; }

public override DynamicJsonValue ToJson()
Expand Down Expand Up @@ -366,7 +366,7 @@ public override DynamicJsonValue ToJson()

if (OlapEtlsUpdated)
json[nameof(OlapEtlsUpdated)] = OlapEtlsUpdated;

if (ElasticSearchConnectionStringsUpdated)
json[nameof(ElasticSearchConnectionStringsUpdated)] = ElasticSearchConnectionStringsUpdated;

Expand All @@ -384,7 +384,7 @@ public override DynamicJsonValue ToJson()

if (IndexesHistoryUpdated)
json[nameof(IndexesHistoryUpdated)] = IndexesHistoryUpdated;

return json;
}

Expand Down Expand Up @@ -453,7 +453,7 @@ public override string ToString()

if (OlapEtlsUpdated)
sb.AppendLine("- OLAP ETLs");

if (ElasticSearchConnectionStringsUpdated)
sb.AppendLine("- ElasticSearch Connection Strings");

Expand Down Expand Up @@ -481,6 +481,23 @@ public override string ToString()
}
}

public class FileCounts
{
public string CurrentFileName { get; set; }
public long CurrentFile { get; set; }
public long FileCount { get; set; }

public DynamicJsonValue ToJson()
{
return new DynamicJsonValue
{
[nameof(CurrentFileName)] = CurrentFileName,
[nameof(CurrentFile)] = CurrentFile,
[nameof(FileCount)] = FileCount
};
}
}

public class Counts
{
public DateTime? StartTime { get; set; }
Expand Down
3 changes: 3 additions & 0 deletions src/Raven.Client/ServerWide/Operations/RestoreProgress.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ public class RestoreProgress : SmugglerResult.SmugglerProgress
{
public Counts SnapshotRestore => ((RestoreResult)_result).SnapshotRestore;

public FileCounts SmugglerRestore => ((RestoreResult)_result).SmugglerRestore;

public RestoreProgress(RestoreResult result) : base(result)
{

Expand All @@ -16,6 +18,7 @@ public override DynamicJsonValue ToJson()
{
var json = base.ToJson();
json[nameof(SnapshotRestore)] = SnapshotRestore.ToJson();
json[nameof(SmugglerRestore)] = SmugglerRestore.ToJson();
return json;
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/Raven.Client/ServerWide/Operations/RestoreResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ public class RestoreResult : SmugglerResult

public Counts SnapshotRestore { get; set; }

public FileCounts SmugglerRestore { get; set; }

public RestoreResult()
{
_progress = new RestoreProgress(this);
SnapshotRestore = new Counts();
SmugglerRestore = new FileCounts();
}

public override DynamicJsonValue ToJson()
Expand All @@ -23,6 +26,7 @@ public override DynamicJsonValue ToJson()
json[nameof(DataDirectory)] = DataDirectory;
json[nameof(JournalStoragePath)] = JournalStoragePath;
json[nameof(SnapshotRestore)] = SnapshotRestore.ToJson();
json[nameof(SmugglerRestore)] = SmugglerRestore.ToJson();
return json;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,8 @@ protected async Task SmugglerRestore(DocumentDatabase database, List<string> fil
if (filesToRestore.Count == 0)
return;

result.SmugglerRestore.FileCount = filesToRestore.Count;

// we do have at least one smuggler backup, we'll take the indexes from the last file
databaseRecord.AutoIndexes = new Dictionary<string, AutoIndexDefinition>();
databaseRecord.Indexes = new Dictionary<string, IndexDefinition>();
Expand All @@ -675,9 +677,14 @@ protected async Task SmugglerRestore(DocumentDatabase database, List<string> fil
for (var i = 0; i < filesToRestore.Count - 1; i++)
{
result.AddInfo($"Restoring file {(i + 1):#,#;;0}/{filesToRestore.Count:#,#;;0}");

var fileName = filesToRestore[i];
result.SmugglerRestore.CurrentFileName = fileName;
result.SmugglerRestore.CurrentFile = i + 1;

onProgress.Invoke(result.Progress);

var filePath = GetBackupPath(filesToRestore[i]);
var filePath = GetBackupPath(fileName);
await ImportSingleBackupFile(database, onProgress, result, filePath, context, destination, options, isLastFile: false,
onDatabaseRecordAction: smugglerDatabaseRecord =>
{
Expand All @@ -687,12 +694,18 @@ await ImportSingleBackupFile(database, onProgress, result, filePath, context, de
}

options.OperateOnTypes = oldOperateOnTypes;
var lastFilePath = GetBackupPath(filesToRestore.Last());

result.AddInfo($"Restoring file {filesToRestore.Count:#,#;;0}/{filesToRestore.Count:#,#;;0}");

var lastFileName = filesToRestore.Last();
result.SmugglerRestore.CurrentFileName = lastFileName;
result.SmugglerRestore.CurrentFile = filesToRestore.Count;

result.Indexes.Skipped = RestoreFromConfiguration.SkipIndexes;

onProgress.Invoke(result.Progress);

var lastFilePath = GetBackupPath(lastFileName);
await ImportSingleBackupFile(database, onProgress, result, lastFilePath, context, destination, options, isLastFile: true,
onIndexAction: indexAndType =>
{
Expand Down Expand Up @@ -756,6 +769,8 @@ await ImportSingleBackupFile(database, onProgress, result, lastFilePath, context
database.DocumentsStorage.RevisionsStorage.InitializeFromDatabaseRecord(smugglerDatabaseRecord);
});

result.SmugglerRestore.CurrentFileName = null;

long totalExecutedCommands = 0;

//when restoring from a backup, the database doesn't exist yet and we cannot rely on the DocumentDatabase to execute the database cluster transaction commands
Expand Down

0 comments on commit b06bec2

Please sign in to comment.