Skip to content

Commit

Permalink
Merge pull request #13 from mizrael/file-storage
Browse files Browse the repository at this point in the history
refactored streams file storage
  • Loading branch information
mizrael authored Feb 19, 2024
2 parents 9c61b3b + 533e9d1 commit f3cc6ae
Show file tree
Hide file tree
Showing 34 changed files with 410 additions and 500 deletions.
2 changes: 1 addition & 1 deletion src/EvenireDB.Benchmark/EvenireDB.Benchmark.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.8" />
<PackageReference Include="BenchmarkDotNet" Version="0.13.12" />
<PackageReference Include="System.Linq.Async" Version="6.0.1" />
<PackageReference Include="ObjectLayoutInspector" Version="0.1.4" />
</ItemGroup>
Expand Down
7 changes: 5 additions & 2 deletions src/EvenireDB.Benchmark/EventsProviderBenckmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using EvenireDB;
using EvenireDB.Common;
using EvenireDB.Extents;
using EvenireDB.Persistence;
using EvenireDB.Utils;
using Microsoft.Extensions.Logging.Abstractions;
using System.Threading.Channels;
Expand All @@ -29,7 +30,9 @@ public void GlobalSetup()

var repoConfig = new FileEventsRepositoryConfig();
var extentInfoProvider = new ExtentInfoProvider(new ExtentInfoProviderConfig(dataPath));
var repo = new FileEventsRepository(repoConfig, extentInfoProvider);
var dataRepo = new DataRepository();
var headersRepo = new HeadersRepository();
var repo = new EventsProvider(headersRepo, dataRepo, extentInfoProvider);

var cache = new EventsCache(
new NullLogger<EventsCache>(),
Expand All @@ -38,7 +41,7 @@ public void GlobalSetup()

var logger = new NullLogger<EventsReader>();

_sut = new EventsReader(EventsReaderConfig.Default, repo, cache, logger);
_sut = new EventsReader(EventsReaderConfig.Default, cache);

var events = Enumerable.Range(0, (int)this.EventsCount).Select(i => new Event(new EventId(i, 0), "lorem", _data)).ToArray();
Task.WaitAll(repo.AppendAsync(_streamId, events).AsTask());
Expand Down
45 changes: 0 additions & 45 deletions src/EvenireDB.Benchmark/FileEventsRepositoryWriteBenckmarks.cs

This file was deleted.

68 changes: 0 additions & 68 deletions src/EvenireDB.Benchmark/RawEventHeaderSerializationBenchmark.cs

This file was deleted.

6 changes: 3 additions & 3 deletions src/EvenireDB.Client/EvenireDB.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Google.Protobuf" Version="3.24.4" />
<PackageReference Include="Grpc.AspNetCore" Version="2.57.0" />
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="7.0.11" />
<PackageReference Include="Google.Protobuf" Version="3.25.3" />
<PackageReference Include="Grpc.AspNetCore" Version="2.60.0" />
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="8.0.2" />
<PackageReference Include="Polly.Contrib.WaitAndRetry" Version="1.1.1" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/EvenireDB.Grpc/EvenireDB.Grpc.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Grpc.AspNetCore" Version="2.32.0" />
<PackageReference Include="Grpc.AspNetCore" Version="2.60.0" />
</ItemGroup>

<ItemGroup>
Expand Down
8 changes: 4 additions & 4 deletions src/EvenireDB.Server/EvenireDB.Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Asp.Versioning.Http" Version="7.1.0" />
<PackageReference Include="Grpc.AspNetCore" Version="2.32.0" />
<PackageReference Include="Google.Protobuf" Version="3.24.4" />
<PackageReference Include="Grpc.AspNetCore.HealthChecks" Version="2.59.0" />
<PackageReference Include="Asp.Versioning.Http" Version="8.0.0" />
<PackageReference Include="Grpc.AspNetCore" Version="2.60.0" />
<PackageReference Include="Google.Protobuf" Version="3.25.3" />
<PackageReference Include="Grpc.AspNetCore.HealthChecks" Version="2.60.0" />
</ItemGroup>

<ItemGroup>
Expand Down
9 changes: 5 additions & 4 deletions src/EvenireDB/EvenireDB.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
<PackageReference Include="System.Linq.Async" Version="6.0.1" />
</ItemGroup>

<ItemGroup>
Expand All @@ -22,7 +23,7 @@
<InternalsVisibleTo Include="EvenireDB.Tests" />

<!-- Required for NSubstitute -->
<InternalsVisibleTo Include="DynamicProxyGenAssembly2"/>
<InternalsVisibleTo Include="DynamicProxyGenAssembly2" />
</ItemGroup>

</Project>
9 changes: 5 additions & 4 deletions src/EvenireDB/EventsCache.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using EvenireDB.Utils;
using EvenireDB.Persistence;
using EvenireDB.Utils;
using Microsoft.Extensions.Logging;

namespace EvenireDB
Expand All @@ -7,12 +8,12 @@ internal class EventsCache : IEventsCache
{
private readonly ICache<Guid, CachedEvents> _cache;
private readonly ILogger<EventsCache> _logger;
private readonly IEventsRepository _repo;
private readonly IEventsProvider _repo;

public EventsCache(
ILogger<EventsCache> logger,
ICache<Guid, CachedEvents> cache,
IEventsRepository repo)
IEventsProvider repo)
{
_logger = logger;
_cache = cache;
Expand All @@ -24,7 +25,7 @@ private async ValueTask<CachedEvents> Factory(Guid streamId, CancellationToken c
_logger.ReadingStreamFromRepository(streamId);

var persistedEvents = new List<Event>();
await foreach (var @event in _repo.ReadAsync(streamId, cancellationToken))
await foreach (var @event in _repo.ReadAsync(streamId, cancellationToken: cancellationToken))
persistedEvents.Add(@event);
return new CachedEvents(persistedEvents, new SemaphoreSlim(1));
}
Expand Down
13 changes: 4 additions & 9 deletions src/EvenireDB/EventsReader.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using EvenireDB.Common;
using EvenireDB.Persistence;
using Microsoft.Extensions.Logging;
using System.Runtime.CompilerServices;

Expand All @@ -8,19 +9,13 @@ internal class EventsReader : IEventsReader
{
private readonly IEventsCache _cache;
private readonly EventsReaderConfig _config;
private readonly IEventsRepository _repo;
private readonly ILogger<EventsReader> _logger;


public EventsReader(
EventsReaderConfig config,
IEventsRepository repo,
IEventsCache cache,
ILogger<EventsReader> logger)
EventsReaderConfig config,
IEventsCache cache)
{
_cache = cache ?? throw new ArgumentNullException(nameof(cache));
_config = config ?? throw new ArgumentNullException(nameof(config));
_repo = repo ?? throw new ArgumentNullException(nameof(repo));
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
}

public async IAsyncEnumerable<Event> ReadAsync(
Expand Down
2 changes: 1 addition & 1 deletion src/EvenireDB/Extents/ExtentInfoProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public ExtentInfoProvider(ExtentInfoProviderConfig config)
Directory.CreateDirectory(config.BasePath);
}

public ExtentInfo GetLatest(Guid streamId)
public ExtentInfo Get(Guid streamId)
{
// TODO: tests
var key = streamId.ToString("N");
Expand Down
2 changes: 1 addition & 1 deletion src/EvenireDB/Extents/IExtentInfoProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ namespace EvenireDB.Extents
{
public interface IExtentInfoProvider
{
ExtentInfo GetLatest(Guid streamId);
ExtentInfo Get(Guid streamId);
}
}
Loading

0 comments on commit f3cc6ae

Please sign in to comment.