Skip to content
Prev Previous commit
Next Next commit
Fix upload, try ConcurrentDictionary
  • Loading branch information
jalauzon-msft committed Nov 5, 2024
commit ce0dc96ff195b4a334fc211ddb127fefee3943bd
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Tests:
- --size 1073741824 --count 5 --duration 120 --concurrency 64

- Test: upload
Class: UploadDireactory
Class: UploadDirectory
Arguments: *sizes

- Test: copy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License.

using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Threading;
Expand All @@ -27,7 +28,7 @@ internal class JobPlanFile : IDisposable
/// <summary>
/// List of Job Part Plan Files associated with this job.
/// </summary>
public Dictionary<int, JobPartPlanFile> JobParts { get; private set; }
public ConcurrentDictionary<int, JobPartPlanFile> JobParts { get; private set; }

/// <summary>
/// Lock for the memory mapped file to allow only one writer.
Expand All @@ -40,7 +41,7 @@ private JobPlanFile(string id, string filePath)
{
Id = id;
FilePath = filePath;
JobParts = new Dictionary<int, JobPartPlanFile>();
JobParts = new();
WriteLock = new SemaphoreSlim(1);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,10 @@ public override async Task AddNewJobPartAsync(
// Add the job part into the current state
if (_transferStates.ContainsKey(transferId))
{
_transferStates[transferId].JobParts.Add(partNumber, mappedFile);
if (!_transferStates[transferId].JobParts.TryAdd(partNumber, mappedFile))
{
throw Errors.CollisionJobPart(transferId, partNumber);
}
}
else
{
Expand Down Expand Up @@ -415,7 +418,7 @@ private void InitializeExistingCheckpointer()
// Job plan file should already exist since we already iterated job plan files
if (_transferStates.TryGetValue(partPlanFileName.Id, out JobPlanFile jobPlanFile))
{
jobPlanFile.JobParts.Add(
jobPlanFile.JobParts.TryAdd(
partPlanFileName.JobPartNumber,
JobPartPlanFile.CreateExistingPartPlanFile(partPlanFileName));
}
Expand Down