Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include repo etags in transactions #3860

Merged
merged 1 commit into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions Core/Net/Repo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,7 @@ public static RepoUpdateResult UpdateAllRepositories(RegistryManager registry_ma
.ToArray();

// Loading done, commit etags
foreach (var kvp in savedEtags)
{
var repo = repos.Where(r => r.uri == kvp.Key).FirstOrDefault();
var etag = kvp.Value;
if (repo != null)
{
log.DebugFormat("Setting etag for {0}: {1}", repo.name, etag);
repo.last_server_etag = etag;
}
}
registry_manager.registry.SetETags(savedEtags);

// Clean up temp files
foreach (var f in files)
Expand Down
23 changes: 23 additions & 0 deletions Core/Registry/Registry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,29 @@ private void EnlistWithTransaction()

#endregion

/// <summary>
/// Set the etag values of the repositories
/// Provided in the API so it can enlist us in the transaction
/// </summary>
/// <param name="savedEtags">Mapping from repo URLs to etags received from servers</param>
public void SetETags(Dictionary<Uri, string> savedEtags)
{
log.Debug("Setting repo etags");

// Make sure etags get reverted if the transaction fails
EnlistWithTransaction();

foreach (var kvp in savedEtags)
{
var etag = kvp.Value;
foreach (var repo in repositories.Values.Where(r => r.uri == kvp.Key))
{
log.DebugFormat("Setting etag for {0}: {1}", repo.name, etag);
repo.last_server_etag = etag;
}
}
}

public void SetAllAvailable(IEnumerable<CkanModule> newAvail)
{
log.DebugFormat(
Expand Down