-
Notifications
You must be signed in to change notification settings - Fork 1k
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 PersistenceIdsPublisher hung on failure messages #6374
Merged
Aaronontheweb
merged 3 commits into
akkadotnet:dev
from
Arkatufus:Fix_#6365_frozen-PersistenceIdsPublisher-actor
Jan 30, 2023
Merged
Changes from all commits
Commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
|
||
using System; | ||
using Akka.Actor; | ||
using Akka.Event; | ||
using Akka.Persistence.Sql.Common.Journal; | ||
using Akka.Streams.Actors; | ||
|
||
|
@@ -22,26 +23,32 @@ public static Props Props(string writeJournalPluginId) | |
private readonly IActorRef _journalRef; | ||
|
||
private readonly DeliveryBuffer<string> _buffer; | ||
private readonly ILoggingAdapter _log; | ||
|
||
public IStash Stash { get; set; } | ||
|
||
public CurrentPersistenceIdsPublisher(string writeJournalPluginId) | ||
{ | ||
_buffer = new DeliveryBuffer<string>(OnNext); | ||
_journalRef = Persistence.Instance.Apply(Context.System).JournalFor(writeJournalPluginId); | ||
_log = Context.GetLogger(); | ||
} | ||
|
||
protected override bool Receive(object message) | ||
{ | ||
switch (message) | ||
{ | ||
case Request _: | ||
_journalRef.Tell(new SelectCurrentPersistenceIds(0, Self)); | ||
Become(Initializing); | ||
_journalRef | ||
.Ask<CurrentPersistenceIds>(new SelectCurrentPersistenceIds(0, Self)) | ||
.PipeTo(Self); | ||
return true; | ||
|
||
case Cancel _: | ||
Context.Stop(Self); | ||
return true; | ||
|
||
default: | ||
return false; | ||
} | ||
|
@@ -64,9 +71,26 @@ private bool Initializing(object message) | |
Become(Active); | ||
Stash.UnstashAll(); | ||
return true; | ||
|
||
case Cancel _: | ||
Context.Stop(Self); | ||
return true; | ||
|
||
case Status.Failure msg: | ||
if (msg.Cause is AskTimeoutException e) | ||
{ | ||
_log.Info(e, "Current persistence id query timed out, retrying"); | ||
} | ||
else | ||
{ | ||
_log.Info(msg.Cause, "Current persistence id query failed, retrying"); | ||
} | ||
|
||
_journalRef | ||
.Ask<CurrentPersistenceIds>(new SelectCurrentPersistenceIds(0, Self)) | ||
.PipeTo(Self); | ||
return true; | ||
|
||
default: | ||
Stash.Stash(); | ||
return true; | ||
|
@@ -77,14 +101,20 @@ private bool Active(object message) | |
{ | ||
switch (message) | ||
{ | ||
case CurrentPersistenceIds _: | ||
// Ignore duplicate CurrentPersistenceIds response | ||
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. LGTM |
||
return true; | ||
|
||
case Request _: | ||
_buffer.DeliverBuffer(TotalDemand); | ||
if (_buffer.IsEmpty) | ||
OnCompleteThenStop(); | ||
return true; | ||
|
||
case Cancel _: | ||
Context.Stop(Self); | ||
return true; | ||
|
||
default: | ||
return false; | ||
} | ||
|
@@ -93,7 +123,7 @@ private bool Active(object message) | |
|
||
internal sealed class LivePersistenceIdsPublisher : ActorPublisher<string>, IWithUnboundedStash | ||
{ | ||
private class Continue | ||
private sealed class Continue | ||
{ | ||
public static readonly Continue Instance = new Continue(); | ||
|
||
|
@@ -109,11 +139,13 @@ public static Props Props(TimeSpan refreshInterval, string writeJournalPluginId) | |
private readonly ICancelable _tickCancelable; | ||
private readonly IActorRef _journalRef; | ||
private readonly DeliveryBuffer<string> _buffer; | ||
private readonly ILoggingAdapter _log; | ||
|
||
public IStash Stash { get; set; } | ||
|
||
public LivePersistenceIdsPublisher(TimeSpan refreshInterval, string writeJournalPluginId) | ||
{ | ||
_log = Context.GetLogger(); | ||
_tickCancelable = Context.System.Scheduler.ScheduleTellRepeatedlyCancelable( | ||
refreshInterval, | ||
refreshInterval, | ||
|
@@ -135,14 +167,19 @@ protected override bool Receive(object message) | |
switch (message) | ||
{ | ||
case Request _: | ||
_journalRef.Tell(new SelectCurrentPersistenceIds(0, Self)); | ||
Become(Waiting); | ||
_journalRef | ||
.Ask<CurrentPersistenceIds>(new SelectCurrentPersistenceIds(_lastOrderingOffset, Self)) | ||
.PipeTo(Self); | ||
return true; | ||
|
||
case Continue _: | ||
return true; | ||
|
||
case Cancel _: | ||
Context.Stop(Self); | ||
return true; | ||
|
||
default: | ||
return false; | ||
} | ||
|
@@ -160,11 +197,28 @@ private bool Waiting(object message) | |
Become(Active); | ||
Stash.UnstashAll(); | ||
return true; | ||
|
||
case Continue _: | ||
return true; | ||
|
||
case Cancel _: | ||
Context.Stop(Self); | ||
return true; | ||
|
||
case Status.Failure msg: | ||
if (msg.Cause is AskTimeoutException e) | ||
{ | ||
_log.Info(e, $"Current persistence id query timed out, retrying. Offset: {_lastOrderingOffset}"); | ||
} | ||
else | ||
{ | ||
_log.Info(msg.Cause, $"Current persistence id query failed, retrying. Offset: {_lastOrderingOffset}"); | ||
} | ||
|
||
Become(Active); | ||
Stash.UnstashAll(); | ||
return true; | ||
|
||
default: | ||
Stash.Stash(); | ||
return true; | ||
|
@@ -175,16 +229,29 @@ private bool Active(object message) | |
{ | ||
switch (message) | ||
{ | ||
case CurrentPersistenceIds _: | ||
// Ignore duplicate CurrentPersistenceIds response | ||
return true; | ||
|
||
case Request _: | ||
_buffer.DeliverBuffer(TotalDemand); | ||
return true; | ||
|
||
case Continue _: | ||
_journalRef.Tell(new SelectCurrentPersistenceIds(_lastOrderingOffset, Self)); | ||
Become(Waiting); | ||
_journalRef | ||
.Ask<CurrentPersistenceIds>(new SelectCurrentPersistenceIds(_lastOrderingOffset, Self)) | ||
.PipeTo(Self); | ||
return true; | ||
|
||
case Cancel _: | ||
Context.Stop(Self); | ||
return true; | ||
|
||
case Status.Failure msg: | ||
_log.Info(msg.Cause, "Unexpected failure received"); | ||
return true; | ||
|
||
default: | ||
return false; | ||
} | ||
|
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 |
---|---|---|
|
@@ -6,7 +6,6 @@ | |
//----------------------------------------------------------------------- | ||
|
||
using System; | ||
using System.Threading; | ||
using Reactive.Streams; | ||
using Akka.Actor; | ||
using Akka.Configuration; | ||
|
@@ -26,7 +25,7 @@ public class SqlReadJournal : | |
IAllEventsQuery, | ||
ICurrentAllEventsQuery | ||
{ | ||
public static string Identifier = "akka.persistence.query.journal.sql"; | ||
public const string Identifier = "akka.persistence.query.journal.sql"; | ||
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. LGTM |
||
|
||
/// <summary> | ||
/// Returns a default query configuration for akka persistence SQLite-based journals and snapshot stores. | ||
|
@@ -52,7 +51,6 @@ public SqlReadJournal(ExtendedActorSystem system, Config config) | |
_maxBufferSize = config.GetInt("max-buffer-size", 0); | ||
_system = system; | ||
|
||
_lock = new ReaderWriterLockSlim(); | ||
_persistenceIdsPublisher = null; | ||
} | ||
|
||
|
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
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.
LGTM