CA-359700: Fixed issue whereby hotfixes applied after an upgrade in parallel were downloaded multiple times.

Signed-off-by: Konstantina Chremmou <konstantina.chremmou@citrix.com>
This commit is contained in:
Konstantina Chremmou 2021-10-12 21:15:00 +01:00 committed by Konstantina Chremmou
parent 2909a4996d
commit c694ed26d7
2 changed files with 23 additions and 6 deletions

View File

@ -40,6 +40,8 @@ namespace XenAdmin.Wizards.PatchingWizard.PlanActions
{
class DownloadPatchPlanAction : PlanActionWithSession
{
private static object _lock = new object();
private static readonly Dictionary<string, object> _patchLocks = new Dictionary<string, object>();
private readonly XenServerPatch patch;
private Dictionary<XenServerPatch, string> AllDownloadedPatches = new Dictionary<XenServerPatch, string>();
private KeyValuePair<XenServerPatch, string> patchFromDisk;
@ -57,16 +59,26 @@ namespace XenAdmin.Wizards.PatchingWizard.PlanActions
{
AddProgressStep(string.Format(Messages.PATCHINGWIZARD_DOWNLOADUPDATE_ACTION_TITLE_WAITING, patch.Name));
object patchLock;
lock (_lock)
{
if (!_patchLocks.TryGetValue(patch.Uuid, out patchLock))
{
patchLock = new object();
_patchLocks[patch.Uuid] = patchLock;
}
}
//if we are updating multiple pools at the same time, we only need to download the patch for
// the first pool, hence we lock it to prevent the plan action of the other pools to run
lock (patch)
lock (patchLock)
{
if (Cancelling)
return;
//skip the download if the patch has been already downloaded or we are using a patch from disk
if ((AllDownloadedPatches.ContainsKey(patch) && File.Exists(AllDownloadedPatches[patch]))
|| (patchFromDisk.Key == patch && File.Exists(patchFromDisk.Value)))
if (AllDownloadedPatches.ContainsKey(patch) && File.Exists(AllDownloadedPatches[patch])
|| patchFromDisk.Key == patch && File.Exists(patchFromDisk.Value))
{
ReplaceProgressStep(string.Format(Messages.PATCHINGWIZARD_DOWNLOADUPDATE_ACTION_TITLE_SKIPPING, patch.Name));
}

View File

@ -38,7 +38,7 @@ namespace XenAdmin.Core
[DebuggerDisplay("XenServerPatch (Name={Name}; Uuid={Uuid})")]
public class XenServerPatch : IEquatable<XenServerPatch>
{
private string _uuid;
private readonly string _uuid;
public readonly string Name;
public readonly string Description;
public readonly string Guidance;
@ -48,8 +48,8 @@ namespace XenAdmin.Core
public readonly string PatchUrl;
public readonly DateTime TimeStamp;
public readonly int Priority;
public readonly long InstallationSize; // installation size, in btyes
public readonly long DownloadSize; // download size, in btyes
public readonly long InstallationSize; // installation size, in bytes
public readonly long DownloadSize; // download size, in bytes
public readonly bool ContainsLivepatch;
public readonly List<string> ConflictingPatches;
@ -100,6 +100,11 @@ namespace XenAdmin.Core
return string.Equals(Uuid, other.Uuid, StringComparison.OrdinalIgnoreCase);
}
public override int GetHashCode()
{
return _uuid.GetHashCode();
}
public after_apply_guidance after_apply_guidance
{
get