Repository navigation
Fix scheduling of notification interfaces #3290
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| using System; | ||
| using System.Threading.Tasks; | ||
| using Orleans.Runtime.Scheduler; | ||
|
|
||
| namespace Orleans.Runtime | ||
| { | ||
| /// <summary> | ||
| /// Extensions for <see cref="SystemTarget"/>. | ||
| /// </summary> | ||
| public static class SystemTargetExtensions | ||
| { | ||
| /// <summary> | ||
| /// Schedules the provided <paramref name="action"/> on the <see cref="SystemTarget"/>'s <see cref="ISchedulingContext"/>. | ||
| /// </summary> | ||
| /// <param name="self">The <see cref="SystemTarget"/>.</param> | ||
| /// <param name="action">The action.</param> | ||
| /// <returns>A <see cref="Task"/> which completes when the <paramref name="action"/> has completed.</returns> | ||
| public static Task ScheduleTask(this SystemTarget self, Func<Task> action) | ||
| { | ||
| return self.RuntimeClient.Scheduler.RunOrQueueTask(action, self.SchedulingContext); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Schedules the provided <paramref name="action"/> on the <see cref="SystemTarget"/>'s <see cref="ISchedulingContext"/>. | ||
| /// </summary> | ||
| /// <param name="self">The <see cref="SystemTarget"/>.</param> | ||
| /// <param name="action">The action.</param> | ||
| /// <returns>A <see cref="Task"/> which completes when the <paramref name="action"/> has completed.</returns> | ||
| public static Task ScheduleTask(this SystemTarget self, Action action) | ||
| { | ||
| return self.RuntimeClient.Scheduler.RunOrQueueAction(action, self.SchedulingContext); | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -183,6 +183,11 @@ private void NotifyAllStatisticsChangeEventsSubscribers(SiloAddress silo, SiloRu | |
|
|
||
|
|
||
| public void SiloStatusChangeNotification(SiloAddress updatedSilo, SiloStatus status) | ||
| { | ||
| this.ScheduleTask(() => { Utils.SafeExecute(() => this.OnSiloStatusChange(updatedSilo, status), this.logger); }).Ignore(); | ||
|
Contributor
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 other example: when we were actually breaking isolation (as opposite to below, where we were not breaking isolation).
Member
Author
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. Is this breaking isolation? I'm not sure that SystemTargets ever had real isolation within a silo - isn't it more rare that we don't call using a mechanism similar to this one here? It seems that the vast majority of the time, calls to a system target follow this pattern: scheduler.QueueTask(() => sysTarget.CallMethod(), sysTarget.SchedulingContext).WaitBlah();Where I'm looking through the code now and unless I'm reading incorrectly, I can find 1 instance where we're not breaking isolation (streams related code) and maybe 40 or so instances where we are. Basing this on usages of Regardless, the reason I took this approach is what I mentioned in this comment above: #3290 (comment)
Member
Author
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. I do think that calling via some proxy is a better solution. The only problem is that Maybe that restriction can be relaxed and we can convert all of the code to make proxied calls. The problem is that it's not relaxed today and I feel like that's a larger change than we could stomach in a patch release. That kind of thing requires more thought - I'm sure the exception which caused this issue was not added lightheartedly, it's likely there to make sure scheduling contexts are being used correctly.
Contributor
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. Ohh, now maybe I see. Absolutely, definitely the original goal was to talk to system targets as grain - via grain ref, and not directly like here.
All the others can/should be replaced to grain calls to system targets. There may be some more exception, but I still think the rule is to use GR as much as possible. |
||
| } | ||
|
|
||
| private void OnSiloStatusChange(SiloAddress updatedSilo, SiloStatus status) | ||
| { | ||
| if (!status.IsTerminating()) return; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -89,8 +89,7 @@ public async Task Initialize(Immutable<IQueueAdapter> qAdapter) | |
| // Remove cast once we cleanup | ||
| queueAdapter = qAdapter.Value; | ||
| await this.queueBalancer.Initialize(this.streamProviderName, this.adapterFactory.GetStreamQueueMapper(), config.SiloMaturityPeriod, this.providerConfig); | ||
| var meAsQueueBalanceListener = this.AsReference<IStreamQueueBalanceListener>(); | ||
| queueBalancer.SubscribeToQueueDistributionChangeEvents(meAsQueueBalanceListener); | ||
| queueBalancer.SubscribeToQueueDistributionChangeEvents(this); | ||
|
Contributor
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. Why changing this? It used to be that the notification here were delivered as grain calls on this system target, which is the right way for system targets to communicate. There are some other examples when system targets call functions directly (breaking isolation), but this was not the case here. In this case it was done the right way.
Member
Author
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. How do you feel this general problem should be addressed?
Should the component marshal the notification onto an addressable context? I am in favor of the latter approach, since the first is difficult without some publicly exposed mechanism for doing so (eg, SystemTarget - which the SF code does not currently have access to) and also because it's the subscriber which knows what its requirements are - not the publisher.
Contributor
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. The former of course. |
||
|
|
||
| List<QueueId> myQueues = queueBalancer.GetMyQueues().ToList(); | ||
| Log(ErrorCode.PersistentStreamPullingManager_03, String.Format("Initialize: I am now responsible for {0} queues: {1}.", myQueues.Count, PrintQueues(myQueues))); | ||
|
|
@@ -140,6 +139,11 @@ public async Task StopAgents() | |
| /// and don't execute an older notification if a newer one was already delivered. | ||
| /// </summary> | ||
| public Task QueueDistributionChangeNotification() | ||
| { | ||
| return this.ScheduleTask(() => this.HandleQueueDistributionChangeNotification()); | ||
| } | ||
|
|
||
| public Task HandleQueueDistributionChangeNotification() | ||
| { | ||
| latestRingNotificationSequenceNumber++; | ||
| int notificationSeqNumber = latestRingNotificationSequenceNumber; | ||
|
|
||
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.
Happy to remove IAddressable from the interface. Never really liked it.
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.
It inherits from IAddressable so it can be implemented by system target and notification be called as grain call. The right and proper way to talk between components inside Orleans is via grain (system target) calls. Except for some small number of limited cases when we break isolation. But here is not such a case and thus I don't see a reason to avoid using grain calls for cross component communication and insist on breaking isolation (I call "invoking function directly, even if after that we enqueue an Task directly" as breaking isolation).