Skip to content
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

Calls issued from clients to StatelessWorker grains should be spread across silos #9153

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public void Populate(IServiceProvider services, Type grainClass, GrainType grain
/// messages is not significant.
/// </summary>
[AttributeUsage(AttributeTargets.Interface)]
[Obsolete("This attribute has no effect and should be removed.")]
public sealed class UnorderedAttribute : Attribute
{
}
Expand Down
12 changes: 8 additions & 4 deletions src/Orleans.Core.Abstractions/Runtime/GrainReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,11 @@ public class GrainReference : IAddressable, IEquatable<GrainReference>, ISpanFor
/// </summary>
internal IGrainReferenceRuntime Runtime => Shared.Runtime;

/// <summary>
/// Gets the flags for all calls made by this reference.
/// </summary>
internal InvokeMethodOptions InvokeMethodOptions => Shared.InvokeMethodOptions;

/// <summary>
/// Gets the grain id.
/// </summary>
Expand Down Expand Up @@ -377,7 +382,6 @@ public uint GetUniformHashCode()
{
if (reference1 is null) return !(reference2 is null);


return !reference1.Equals(reference2);
}

Expand Down Expand Up @@ -409,7 +413,7 @@ bool ISpanFormattable.TryFormat(Span<char> destination, out int charsWritten, Re
/// <returns>The result of the invocation.</returns>
protected ValueTask<T> InvokeAsync<T>(IRequest methodDescription)
{
return this.Runtime.InvokeMethodAsync<T>(this, methodDescription, methodDescription.Options);
return this.Runtime.InvokeMethodAsync<T>(this, methodDescription, methodDescription.Options | InvokeMethodOptions);
}

/// <summary>
Expand All @@ -419,7 +423,7 @@ protected ValueTask<T> InvokeAsync<T>(IRequest methodDescription)
/// <returns>A <see cref="ValueTask"/> representing the operation.</returns>
protected ValueTask InvokeAsync(IRequest methodDescription)
{
return this.Runtime.InvokeMethodAsync(this, methodDescription, methodDescription.Options);
return this.Runtime.InvokeMethodAsync(this, methodDescription, methodDescription.Options | InvokeMethodOptions);
}

/// <summary>
Expand All @@ -428,7 +432,7 @@ protected ValueTask InvokeAsync(IRequest methodDescription)
/// <param name="methodDescription">The method description.</param>
protected void Invoke(IRequest methodDescription)
{
this.Runtime.InvokeMethod(this, methodDescription, methodDescription.Options);
this.Runtime.InvokeMethod(this, methodDescription, methodDescription.Options | InvokeMethodOptions);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ public interface IMembershipTable
/// <summary>
/// Membership table interface for system target based implementation.
/// </summary>
[Unordered]
public interface IMembershipTableSystemTarget : IMembershipTable, ISystemTarget
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ Task StartAsync(CancellationToken cancellationToken = default)
/// <summary>
/// Reminder table interface for grain based implementation.
/// </summary>
[Unordered]
internal interface IReminderTableGrain : IGrainWithIntegerKey
{
Task<ReminderTableData> ReadRows(GrainId grainId);
Expand Down
1 change: 0 additions & 1 deletion test/Grains/TestGrainInterfaces/CodegenTestInterfaces.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public interface ISomeGrain : IGrainWithIntegerKey
Task Do(Outsider o);
}

[Unordered]
public interface ISomeGrainWithInvocationOptions : IGrainWithIntegerKey
{
[AlwaysInterleave]
Expand Down
10 changes: 0 additions & 10 deletions test/Grains/TestGrainInterfaces/IReentrancyGrain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,6 @@ public interface IMayInterleaveInstancedPredicateGrain : IGrainWithIntegerKey
Task SetSelf(IMayInterleaveInstancedPredicateGrain self);
}

[Unordered]
public interface IUnorderedNonReentrantGrain : IGrainWithIntegerKey
{
Task<string> One();

Task<string> Two();

Task SetSelf(IUnorderedNonReentrantGrain self);
}

public interface IReentrantSelfManagedGrain : IGrainWithIntegerKey
{
Task<int> GetCounter();
Expand Down
21 changes: 0 additions & 21 deletions test/Grains/TestGrains/ReentrantGrain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,27 +239,6 @@ public Task SetSelf(IMayInterleaveInstancedPredicateGrain self)
}
}

public class UnorderedNonRentrantGrain : Grain, IUnorderedNonReentrantGrain
{
private IUnorderedNonReentrantGrain Self { get; set; }

public Task<string> One()
{
return Task.FromResult("one");
}

public async Task<string> 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;
Expand Down
4 changes: 2 additions & 2 deletions test/TesterInternal/General/GrainPlacementTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IStatelessWorkerPlacementTestGrain>(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<IOtherStatelessWorkerPlacementTestGrain>(Guid.NewGuid());
int actual = await ActivationCount(grain, expected * 50);
Assert.True(actual <= expected, $"Created more activations than the specified limit: {actual} > {expected}.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<IUnorderedNonReentrantGrain>(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.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Loading