From 057e0bac88539b808aee2b13c94525c972b6bf68 Mon Sep 17 00:00:00 2001 From: Reuben Bond Date: Wed, 25 Sep 2024 13:19:58 -0700 Subject: [PATCH] Calls issued from clients to StatelessWorker grains should be spread across silos (cherry picked from commit 81944a4933e05609f4c2b200343805d87b7f1f4f) --- .../Concurrency/GrainAttributeConcurrency.cs | 1 + .../Runtime/GrainReference.cs | 12 ++++++--- .../IMembershipTable.cs | 1 - .../SystemTargetInterfaces/IReminderTable.cs | 1 - .../CodegenTestInterfaces.cs | 1 - .../TestGrainInterfaces/IReentrancyGrain.cs | 10 ------- test/Grains/TestGrains/ReentrantGrain.cs | 21 --------------- .../General/GrainPlacementTests.cs | 4 +-- .../DisabledCallChainReentrancyTestRunner.cs | 26 ------------------- .../DisabledCallChainReentrancyTests.cs | 6 ----- 10 files changed, 11 insertions(+), 72 deletions(-) diff --git a/src/Orleans.Core.Abstractions/Concurrency/GrainAttributeConcurrency.cs b/src/Orleans.Core.Abstractions/Concurrency/GrainAttributeConcurrency.cs index a882583d21..dead900e35 100644 --- a/src/Orleans.Core.Abstractions/Concurrency/GrainAttributeConcurrency.cs +++ b/src/Orleans.Core.Abstractions/Concurrency/GrainAttributeConcurrency.cs @@ -43,6 +43,7 @@ public void Populate(IServiceProvider services, Type grainClass, GrainType grain /// messages is not significant. /// [AttributeUsage(AttributeTargets.Interface)] + [Obsolete("This attribute has no effect and should be removed.")] public sealed class UnorderedAttribute : Attribute { } diff --git a/src/Orleans.Core.Abstractions/Runtime/GrainReference.cs b/src/Orleans.Core.Abstractions/Runtime/GrainReference.cs index b585d68cbc..c3c854b0d0 100644 --- a/src/Orleans.Core.Abstractions/Runtime/GrainReference.cs +++ b/src/Orleans.Core.Abstractions/Runtime/GrainReference.cs @@ -274,6 +274,11 @@ public class GrainReference : IAddressable, IEquatable, ISpanFor /// internal IGrainReferenceRuntime Runtime => Shared.Runtime; + /// + /// Gets the flags for all calls made by this reference. + /// + internal InvokeMethodOptions InvokeMethodOptions => Shared.InvokeMethodOptions; + /// /// Gets the grain id. /// @@ -377,7 +382,6 @@ public uint GetUniformHashCode() { if (reference1 is null) return !(reference2 is null); - return !reference1.Equals(reference2); } @@ -409,7 +413,7 @@ bool ISpanFormattable.TryFormat(Span destination, out int charsWritten, Re /// The result of the invocation. protected ValueTask InvokeAsync(IRequest methodDescription) { - return this.Runtime.InvokeMethodAsync(this, methodDescription, methodDescription.Options); + return this.Runtime.InvokeMethodAsync(this, methodDescription, methodDescription.Options | InvokeMethodOptions); } /// @@ -419,7 +423,7 @@ protected ValueTask InvokeAsync(IRequest methodDescription) /// A representing the operation. protected ValueTask InvokeAsync(IRequest methodDescription) { - return this.Runtime.InvokeMethodAsync(this, methodDescription, methodDescription.Options); + return this.Runtime.InvokeMethodAsync(this, methodDescription, methodDescription.Options | InvokeMethodOptions); } /// @@ -428,7 +432,7 @@ protected ValueTask InvokeAsync(IRequest methodDescription) /// The method description. protected void Invoke(IRequest methodDescription) { - this.Runtime.InvokeMethod(this, methodDescription, methodDescription.Options); + this.Runtime.InvokeMethod(this, methodDescription, methodDescription.Options | InvokeMethodOptions); } } diff --git a/src/Orleans.Core/SystemTargetInterfaces/IMembershipTable.cs b/src/Orleans.Core/SystemTargetInterfaces/IMembershipTable.cs index d2cb296bb9..35043a5ae0 100644 --- a/src/Orleans.Core/SystemTargetInterfaces/IMembershipTable.cs +++ b/src/Orleans.Core/SystemTargetInterfaces/IMembershipTable.cs @@ -103,7 +103,6 @@ public interface IMembershipTable /// /// Membership table interface for system target based implementation. /// - [Unordered] public interface IMembershipTableSystemTarget : IMembershipTable, ISystemTarget { } diff --git a/src/Orleans.Reminders/SystemTargetInterfaces/IReminderTable.cs b/src/Orleans.Reminders/SystemTargetInterfaces/IReminderTable.cs index 5179ae3ba1..bae9f9c5ff 100644 --- a/src/Orleans.Reminders/SystemTargetInterfaces/IReminderTable.cs +++ b/src/Orleans.Reminders/SystemTargetInterfaces/IReminderTable.cs @@ -86,7 +86,6 @@ Task StartAsync(CancellationToken cancellationToken = default) /// /// Reminder table interface for grain based implementation. /// - [Unordered] internal interface IReminderTableGrain : IGrainWithIntegerKey { Task ReadRows(GrainId grainId); diff --git a/test/Grains/TestGrainInterfaces/CodegenTestInterfaces.cs b/test/Grains/TestGrainInterfaces/CodegenTestInterfaces.cs index 260cfd9046..8b660b623e 100644 --- a/test/Grains/TestGrainInterfaces/CodegenTestInterfaces.cs +++ b/test/Grains/TestGrainInterfaces/CodegenTestInterfaces.cs @@ -42,7 +42,6 @@ public interface ISomeGrain : IGrainWithIntegerKey Task Do(Outsider o); } - [Unordered] public interface ISomeGrainWithInvocationOptions : IGrainWithIntegerKey { [AlwaysInterleave] diff --git a/test/Grains/TestGrainInterfaces/IReentrancyGrain.cs b/test/Grains/TestGrainInterfaces/IReentrancyGrain.cs index 364f22053d..c2e58933a6 100644 --- a/test/Grains/TestGrainInterfaces/IReentrancyGrain.cs +++ b/test/Grains/TestGrainInterfaces/IReentrancyGrain.cs @@ -50,16 +50,6 @@ public interface IMayInterleaveInstancedPredicateGrain : IGrainWithIntegerKey Task SetSelf(IMayInterleaveInstancedPredicateGrain self); } - [Unordered] - public interface IUnorderedNonReentrantGrain : IGrainWithIntegerKey - { - Task One(); - - Task Two(); - - Task SetSelf(IUnorderedNonReentrantGrain self); - } - public interface IReentrantSelfManagedGrain : IGrainWithIntegerKey { Task GetCounter(); diff --git a/test/Grains/TestGrains/ReentrantGrain.cs b/test/Grains/TestGrains/ReentrantGrain.cs index 6535a00cb8..c20632c60e 100644 --- a/test/Grains/TestGrains/ReentrantGrain.cs +++ b/test/Grains/TestGrains/ReentrantGrain.cs @@ -239,27 +239,6 @@ public Task SetSelf(IMayInterleaveInstancedPredicateGrain self) } } - public class UnorderedNonRentrantGrain : Grain, IUnorderedNonReentrantGrain - { - private IUnorderedNonReentrantGrain Self { get; set; } - - public Task One() - { - return Task.FromResult("one"); - } - - public async Task Two() - { - return await Self.One() + " two"; - } - - public Task SetSelf(IUnorderedNonReentrantGrain self) - { - Self = self; - return Task.CompletedTask; - } - } - [Reentrant] public class ReentrantSelfManagedGrain1 : Grain, IReentrantSelfManagedGrain { private long destination; diff --git a/test/TesterInternal/General/GrainPlacementTests.cs b/test/TesterInternal/General/GrainPlacementTests.cs index 6d0c9cf86f..f4d39f4c1a 100644 --- a/test/TesterInternal/General/GrainPlacementTests.cs +++ b/test/TesterInternal/General/GrainPlacementTests.cs @@ -119,14 +119,14 @@ public async Task StatelessWorkerShouldCreateSpecifiedActivationCount() { // note: this amount should agree with both the specified minimum and maximum in the StatelessWorkerPlacement attribute // associated with ILocalPlacementTestGrain. - const int expected = 1; + var expected = 1 * _fixture.HostedCluster.Silos.Count; var grain = _fixture.GrainFactory.GetGrain(Guid.NewGuid()); int actual = await ActivationCount(grain, expected * 50); Assert.True(actual <= expected, $"Created more activations than the specified limit: {actual} > {expected}."); } { - const int expected = 2; + var expected = 2 * _fixture.HostedCluster.Silos.Count; var grain = _fixture.GrainFactory.GetGrain(Guid.NewGuid()); int actual = await ActivationCount(grain, expected * 50); Assert.True(actual <= expected, $"Created more activations than the specified limit: {actual} > {expected}."); diff --git a/test/TesterInternal/MessageScheduling/DisabledCallChainReentrancyTestRunner.cs b/test/TesterInternal/MessageScheduling/DisabledCallChainReentrancyTestRunner.cs index 465fe3d0c5..62189085bf 100644 --- a/test/TesterInternal/MessageScheduling/DisabledCallChainReentrancyTestRunner.cs +++ b/test/TesterInternal/MessageScheduling/DisabledCallChainReentrancyTestRunner.cs @@ -90,31 +90,5 @@ public void NonReentrantGrain_WithMayInterleaveInstancedPredicate_WhenPredicateR } this.logger.LogInformation("Reentrancy NonReentrantGrain_WithMayInterleaveInstancedPredicate_WhenPredicateReturnsFalse Test finished OK."); } - - public void UnorderedNonReentrantGrain(bool performDeadlockDetection) - { - IUnorderedNonReentrantGrain unonreentrant = this.grainFactory.GetGrain(OrleansTestingBase.GetRandomGrainId()); - unonreentrant.SetSelf(unonreentrant).Wait(); - bool timeout = false; - bool deadlock = false; - try - { - timeout = !unonreentrant.Two().Wait(2000); - } - catch (Exception exc) - { - Assert.Fail($"Unexpected exception {exc.Message}: {exc.StackTrace}"); - } - if (performDeadlockDetection) - { - Assert.True(deadlock, "Non-reentrant grain should deadlock"); - } - else - { - Assert.True(timeout, "Non-reentrant grain should timeout"); - } - - this.logger.LogInformation("Reentrancy UnorderedNonReentrantGrain Test finished OK."); - } } } \ No newline at end of file diff --git a/test/TesterInternal/MessageScheduling/DisabledCallChainReentrancyTests.cs b/test/TesterInternal/MessageScheduling/DisabledCallChainReentrancyTests.cs index 49d489d897..abd6bb71e1 100644 --- a/test/TesterInternal/MessageScheduling/DisabledCallChainReentrancyTests.cs +++ b/test/TesterInternal/MessageScheduling/DisabledCallChainReentrancyTests.cs @@ -38,11 +38,5 @@ public void NonReentrantGrain_WithMayInterleaveInstancedPredicate_WhenPredicateR { this.runner.NonReentrantGrain_WithMayInterleaveInstancedPredicate_WhenPredicateReturnsFalse(false); } - - [Fact, TestCategory("Functional"), TestCategory("Tasks"), TestCategory("Reentrancy")] - public void UnorderedNonReentrantGrain() - { - this.runner.UnorderedNonReentrantGrain(false); - } } } \ No newline at end of file