-
Notifications
You must be signed in to change notification settings - Fork 11
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
Fix missing default query configuration #317
Merged
Aaronontheweb
merged 2 commits into
akkadotnet:dev
from
Arkatufus:Fix-missing-query-config
Sep 14, 2023
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,29 +12,17 @@ namespace Akka.Persistence.Sql.Query | |
public class SqlReadJournalProvider : IReadJournalProvider | ||
{ | ||
private readonly Configuration.Config _config; | ||
private readonly string _configPath; | ||
private readonly ExtendedActorSystem _system; | ||
|
||
public SqlReadJournalProvider( | ||
ExtendedActorSystem system, | ||
Configuration.Config config) | ||
{ | ||
_system = system; | ||
_config = config; | ||
_configPath = "sql"; | ||
} | ||
|
||
public SqlReadJournalProvider( | ||
ExtendedActorSystem system, | ||
Configuration.Config config, | ||
string configPath) | ||
{ | ||
_system = system; | ||
_config = config; | ||
_configPath = configPath; | ||
_config = config.WithFallback(SqlPersistence.DefaultQueryConfiguration); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the actual fix There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it, ok thank you. |
||
} | ||
|
||
public IReadJournal GetReadJournal() | ||
=> new SqlReadJournal(_system, _config, _configPath); | ||
=> new SqlReadJournal(_system, _config); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\Akka.Persistence.Sql\Akka.Persistence.Sql.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Data.Sqlite" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Update="db\test.db"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// See https://aka.ms/new-console-template for more information | ||
|
||
using Akka.Actor; | ||
using Akka.Persistence; | ||
using Akka.Persistence.Query; | ||
using Akka.Persistence.Sql.Query; | ||
using Akka.Streams; | ||
using Akka.Streams.Dsl; | ||
using HoconConfiguration; | ||
|
||
const string config = | ||
""" | ||
akka.persistence { | ||
journal { | ||
plugin = "akka.persistence.journal.sql" | ||
sql { | ||
class = "Akka.Persistence.Sql.Journal.SqlWriteJournal, Akka.Persistence.Sql" | ||
connection-string = "DataSource=db/test.db;" | ||
provider-name = "SQLite.MS" | ||
} | ||
} | ||
query.journal.sql { | ||
class = "Akka.Persistence.Sql.Query.SqlReadJournalProvider, Akka.Persistence.Sql" | ||
connection-string = "DataSource=db/test.db;" | ||
provider-name = "SQLite.MS" | ||
} | ||
snapshot-store { | ||
plugin = "akka.persistence.snapshot-store.sql" | ||
sql { | ||
class = "Akka.Persistence.Sql.Snapshot.SqlSnapshotStore, Akka.Persistence.Sql" | ||
connection-string = "DataSource=db/test.db;" | ||
provider-name = "SQLite.MS" | ||
} | ||
} | ||
} | ||
"""; | ||
|
||
var sys = ActorSystem.Create("my-system", config); | ||
var actor = sys.ActorOf(TestPersistenceActor.Props("test")); | ||
var reader = sys.ReadJournalFor<SqlReadJournal>("akka.persistence.query.journal.sql"); | ||
|
||
foreach (var i in Enumerable.Range(0, 200)) | ||
{ | ||
var chr = (char)(65 + i % 26); | ||
actor.Tell(new string(new []{chr})); | ||
await Task.Delay(TimeSpan.FromSeconds(0.05)); | ||
} | ||
|
||
_ = reader.CurrentAllEvents(Offset.NoOffset()) | ||
.Select(e => | ||
{ | ||
Console.WriteLine($"New event: {e.Event}"); | ||
return e; | ||
}).RunWith(Sink.Ignore<EventEnvelope>(), sys.Materializer()); | ||
|
||
Console.ReadKey(); | ||
|
||
await sys.Terminate(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// ----------------------------------------------------------------------- | ||
// <copyright file="PersistenceActor.cs" company="Akka.NET Project"> | ||
// Copyright (C) 2013-2023 .NET Foundation <https://github.com/akkadotnet/akka.net> | ||
// </copyright> | ||
// ----------------------------------------------------------------------- | ||
|
||
using Akka.Actor; | ||
using Akka.Event; | ||
using Akka.Persistence; | ||
|
||
namespace HoconConfiguration | ||
{ | ||
public class TestPersistenceActor: ReceivePersistentActor | ||
{ | ||
public static Props Props(string id) => Akka.Actor.Props.Create(() => new TestPersistenceActor(id)); | ||
|
||
public override string PersistenceId { get; } | ||
|
||
private int _counter; | ||
private string _state = string.Empty; | ||
|
||
public TestPersistenceActor(string persistenceId) | ||
{ | ||
PersistenceId = persistenceId; | ||
var log = Context.GetLogger(); | ||
|
||
Recover<SnapshotOffer>(s => _state = (string)s.Snapshot); | ||
Recover<string>(s => _state += s); | ||
|
||
Command<string>( | ||
msg => | ||
{ | ||
Persist(msg, | ||
s => | ||
{ | ||
_state += s; | ||
_counter++; | ||
if(_counter % 25 == 0) | ||
SaveSnapshot(_state); | ||
log.Info($"Persisted message: {s}"); | ||
}); | ||
}); | ||
Command<SaveSnapshotSuccess>( | ||
_ => | ||
{ | ||
log.Info($"Snapshot persisted. State: {_state}"); | ||
}); | ||
} | ||
} | ||
} |
Empty file.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What was the fix here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was not the fix, the
SqlReadJournal
is a bit different in that it creates a materializer, which none of our other read journal does.It tries to create a single materializer by appending the "config path".
The problem is that "config path" were never being passed into the provider, the provider was created through reflection magic and none of the activator code passes in the "config path".
So I just remove that ambiguous code and replace it with a GUID