Skip to content

Force write journal to initialize when read journal is started #423

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

Merged
merged 6 commits into from
Jul 30, 2024

Conversation

Aaronontheweb
Copy link
Member

@Aaronontheweb Aaronontheweb commented Jul 29, 2024

Changes

close #344

Checklist

For significant changes, please ensure that the following have been completed (delete if not relevant):

Copy link
Member Author

@Aaronontheweb Aaronontheweb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Detailed my changes


namespace Akka.Persistence.Sql.Tests.Common.Query
{
public abstract class Bugfix344Spec<T> : Akka.TestKit.Xunit2.TestKit, IAsyncLifetime where T : ITestContainer
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Abstract spec to validate that this issue has been resolved, and that the ReadJournal will automatically start up the write journal and wait for it to initialize.

@@ -59,6 +59,11 @@ public class SqlReadJournal :
_system = system;

var connFact = new AkkaPersistenceDataConnectionFactory(_readJournalConfig);

// Fix for https://github.com/akkadotnet/Akka.Persistence.Sql/issues/344
var writeJournal = Persistence.Instance.Apply(system).JournalFor(writePluginId);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Start the SqlWriteJournal if it has not been started already - technically the _eventAdapters = Persistence.Instance.Apply(system).AdaptersFor(writePluginId); also does this implicitly.

// Fix for https://github.com/akkadotnet/Akka.Persistence.Sql/issues/344
var writeJournal = Persistence.Instance.Apply(system).JournalFor(writePluginId);
// we want to block, we want to crash if the journal is not available
var started = writeJournal.Ask<Initialized>(IsInitialized.Instance, TimeSpan.FromSeconds(5)).Result;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Block and wait until startup is complete - this should cover any cases of this issue where queries still get executed before the write journal fully finishes initializing.

Copy link
Contributor

@Arkatufus Arkatufus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Arkatufus Arkatufus enabled auto-merge (squash) July 29, 2024 21:22
@Aaronontheweb
Copy link
Member Author

Got the error to occur:

Failed: Expected a message of type Akka.Streams.TestKit.TestSubscriber+OnComplete, but received {TestSubscriber.OnError(One or more errors occurred. (42P01: relation "journal" does not exist


POSITION: 31))} (type Akka.Streams.TestKit.TestSubscriber+OnError) instead  from [akka://test/user/StreamSupervisor-1252/Flow-0-0-unknown-operation#440889324]

@Aaronontheweb Aaronontheweb disabled auto-merge July 30, 2024 15:38
@Aaronontheweb Aaronontheweb merged commit 8468332 into akkadotnet:dev Jul 30, 2024
1 of 3 checks passed
@Aaronontheweb Aaronontheweb deleted the fix-344-spec branch July 30, 2024 15:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Auto initialization of tables isn't supported from the read journal side.
2 participants