Repository navigation
fix(om): honor background posts requested while acknowledgement is pending #291
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
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 hidden or 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 hidden or 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
97 changes: 97 additions & 0 deletions
97
....Orleans.Messaging/test/Egil.Orleans.Messaging.Tests/Outboxes/GatedOutboxTimerRegistry.cs
This file contains hidden or 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,97 @@ | ||
| using Orleans.Timers; | ||
|
|
||
| namespace Egil.Orleans.Messaging.Tests.Outboxes; | ||
|
|
||
| internal sealed class GatedOutboxTimerRegistry(ITimerRegistry timers) : ITimerRegistry | ||
| { | ||
| public static void Install(IServiceCollection services) | ||
| { | ||
| var registration = services.Single(service => service.ServiceType == typeof(ITimerRegistry)); | ||
| services.Remove(registration); | ||
| services.AddSingleton<ITimerRegistry>(provider => new GatedOutboxTimerRegistry( | ||
| (ITimerRegistry)ActivatorUtilities.CreateInstance(provider, registration.ImplementationType!))); | ||
| } | ||
|
|
||
| [Obsolete("Use RegisterGrainTimer instead.")] | ||
| public IDisposable RegisterTimer(IGrainContext grainContext, Func<object?, Task> callback, object? state, TimeSpan dueTime, TimeSpan period) => | ||
| timers.RegisterTimer(grainContext, callback, state, dueTime, period); | ||
|
|
||
| public IGrainTimer RegisterGrainTimer<TState>( | ||
| IGrainContext grainContext, | ||
| Func<TState, CancellationToken, Task> callback, | ||
| TState state, | ||
| GrainTimerCreationOptions options) | ||
| { | ||
| if (grainContext.GrainInstance is not OutboxDrainRequestGrain grain) | ||
| { | ||
| return timers.RegisterGrainTimer(grainContext, callback, state, options); | ||
| } | ||
|
|
||
| var gate = grain.Gate; | ||
| // This test grain registers only the processor's two timers: dispatch | ||
| // repeats at RetryDelay, while acknowledgement is a single-shot timer. | ||
| // Decorate that runtime boundary without replacing either callback. | ||
| var acknowledgementTimer = options.Period == Timeout.InfiniteTimeSpan; | ||
| var timer = timers.RegisterGrainTimer(grainContext, async (timerState, cancellationToken) => | ||
| { | ||
| var requestedDispatchTick = !acknowledgementTimer && gate.DispatchTickRequested.Task.IsCompleted; | ||
| if (acknowledgementTimer && grain.HoldAcknowledgementTimer) | ||
| { | ||
| // Hold before the processor acquires its gate. The real Orleans | ||
| // dispatch timer can then hit the pending-batch defer branch, | ||
| // rather than merely wait behind an active acknowledgement. | ||
| gate.AcknowledgementTimerStarted.TrySetResult(); | ||
| await gate.AllowAcknowledgement.Task.WaitAsync(cancellationToken); | ||
| } | ||
|
|
||
| await callback(timerState, cancellationToken); | ||
| if (acknowledgementTimer) | ||
| { | ||
| gate.AcknowledgementCallbackCompleted.TrySetResult(); | ||
| } | ||
| else if (requestedDispatchTick) | ||
| { | ||
| gate.RequestedDispatchCompleted.TrySetResult(); | ||
| } | ||
| }, state, options); | ||
|
|
||
| if (!acknowledgementTimer) | ||
| { | ||
| gate.DispatchTimer = new GatedOutboxDispatchTimer(timer, options); | ||
| return gate.DispatchTimer; | ||
| } | ||
|
|
||
| return timer; | ||
| } | ||
| } | ||
|
|
||
| internal sealed class GatedOutboxDispatchTimer(IGrainTimer timer, GrainTimerCreationOptions options) : IGrainTimer | ||
| { | ||
| private TimeSpan dueTime = options.DueTime; | ||
| private TimeSpan period = options.Period; | ||
| private bool paused; | ||
|
|
||
| public void Change(TimeSpan dueTime, TimeSpan period) | ||
| { | ||
| this.dueTime = dueTime; | ||
| this.period = period; | ||
| timer.Change(paused ? Timeout.InfiniteTimeSpan : dueTime, period); | ||
| } | ||
|
|
||
| public void Pause() | ||
| { | ||
| // Retain schedule changes while suppressing their runtime wakeup. This | ||
| // lets a queued stale acknowledgement finish before the follow-up timer | ||
| // fires, without changing the processor or invoking its private methods. | ||
| paused = true; | ||
| timer.Change(Timeout.InfiniteTimeSpan, period); | ||
| } | ||
|
|
||
| public void Resume() | ||
| { | ||
| paused = false; | ||
| timer.Change(dueTime, period); | ||
| } | ||
|
|
||
| public void Dispose() => timer.Dispose(); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.