Skip to content

Commit

Permalink
added semaphore to writer
Browse files Browse the repository at this point in the history
  • Loading branch information
mizrael committed Jun 7, 2024
1 parent ef5093e commit e164d9a
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/EvenireDB/Persistence/EventsProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,17 @@ public async ValueTask AppendAsync(
{
var extentInfo = _extentInfoProvider.Get(streamId);

var inHeaders = _dataRepo.AppendAsync(extentInfo, events, cancellationToken);
await _headersRepo.AppendAsync(extentInfo, inHeaders, cancellationToken);
var semaphore = _streamLocks.GetOrAdd(streamId, _ => new SemaphoreSlim(1, 1));
await semaphore.WaitAsync(cancellationToken);

try
{
var inHeaders = _dataRepo.AppendAsync(extentInfo, events, cancellationToken);
await _headersRepo.AppendAsync(extentInfo, inHeaders, cancellationToken);
}
finally
{
semaphore.Release();
}
}
}

0 comments on commit e164d9a

Please sign in to comment.