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

Fixed cluster group router UseRole ignored bug #3303

Merged

Conversation

Aaronontheweb
Copy link
Member

Addresses #3294

@@ -272,7 +272,7 @@ private void A_cluster_must_group_local_on_role_b()
var router = Sys.ActorOf(
new ClusterRouterGroup(
new RoundRobinGroup(paths: null),
new ClusterRouterGroupSettings(6, ImmutableHashSet.Create("/user/foo", "/user/bar"), allowLocalRoutees: false, useRole: role)).Props(),
new ClusterRouterGroupSettings(6, ImmutableHashSet.Create("/user/foo", "/user/bar"), allowLocalRoutees: true, useRole: role)).Props(),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As it turns out, this is a bug. allowLocalRoutees is supposed to be set for true for this part of the spec, per the JVM implementation for router-3b:

https://github.com/akka/akka/blob/a94f7cdc98332875e21900017c7eac52dbfa2bbd/akka-cluster/src/multi-jvm/scala/akka/cluster/routing/UseRoleIgnoredSpec.scala#L193

          ClusterRouterGroupSettings(totalInstances = 6, routeesPaths = List("/user/foo", "/user/bar"),
            allowLocalRoutees = true, useRole = role)).props,
          "router-3b")

This is why this spec didn't catch the bug earlier. The two bugs cancelled eachother out.

/// </summary>
[Obsolete("Deprecated since Akka.NET v1.1. Use Paths(ActorSystem) instead.")]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added note to indicate that this method is now obsolete, which it is.

@Aaronontheweb
Copy link
Member Author

Error logs upon re-running this spec with my changes:

[Node1:first][FAIL] Akka.Cluster.Tests.MultiNode.Routing.UseRoleIgnoredSpec.UseRoleIgnoredSpecs
[Node1:first][FAIL-EXCEPTION] Type: Xunit.Sdk.XunitException
--> [Node1:first][FAIL-EXCEPTION] Message: Expected value to be 4, but found 6.
--> [Node1:first][FAIL-EXCEPTION] StackTrace:    at FluentAssertions.Execution.XUnit2TestFramework.Throw(String message)
   at FluentAssertions.Execution.AssertionScope.FailWith(String message, Object[] args)
   at FluentAssertions.Numeric.NumericAssertions`1.Be(T expected, String because, Object[] becauseArgs)
   at Akka.TestKit.TestKitBase.AwaitAssert(Action assertion, Nullable`1 duration, Nullable`1 interval) in C:\Repositories\olympus\akka.net\src\core\Akka.TestKit\TestKitBase_AwaitAssert.cs:line 51
   at Akka.Cluster.Tests.MultiNode.Routing.UseRoleIgnoredSpec.<A_cluster_must_group_local_on_role_b>b__11_0() in C:\Repositories\olympus\akka.net\src\core\Akka.Cluster.Tests.MultiNode\Routing\UseRoleIgnoredSpec.cs:line 281
   at Akka.Remote.TestKit.MultiNodeSpec.RunOn(Action thunk, RoleName[] nodes) in C:\Repositories\olympus\akka.net\src\core\Akka.Remote.TestKit\MultiNodeSpec.cs:line 508
   at Akka.Cluster.Tests.MultiNode.Routing.UseRoleIgnoredSpec.A_cluster_must_group_local_on_role_b() in C:\Repositories\olympus\akka.net\src\core\Akka.Cluster.Tests.MultiNode\Routing\UseRoleIgnoredSpec.cs:line 295
   at Akka.Cluster.Tests.MultiNode.Routing.UseRoleIgnoredSpec.UseRoleIgnoredSpecs() in C:\Repositories\olympus\akka.net\src\core\Akka.Cluster.Tests.MultiNode\Routing\UseRoleIgnoredSpec.cs:line 136

[ERROR][1/29/2018 10:34:16 PM][Thread 0049][akka://NoteTestRunner-0/system/IO-TCP/$a] Monitored actor [[akka://NoteTestRunner-0/user/$a#1543076061]] terminated
Cause: Akka.Actor.DeathPactException: Monitored actor [[akka://NoteTestRunner-0/user/$a#1543076061]] terminated
   at Akka.Actor.ActorBase.Unhandled(Object message) in C:\Repositories\olympus\akka.net\src\core\Akka\Actor\ActorBase.cs:line 193
   at Akka.Actor.ActorBase.AroundReceive(Receive receive, Object message) in C:\Repositories\olympus\akka.net\src\core\Akka\Actor\ActorBase.cs:line 158
   at Akka.Actor.ActorCell.ReceiveMessage(Object message) in C:\Repositories\olympus\akka.net\src\core\Akka\Actor\ActorCell.DefaultMessages.cs:line 179
   at Akka.Actor.ActorCell.AutoReceiveMessage(Envelope envelope) in C:\Repositories\olympus\akka.net\src\core\Akka\Actor\ActorCell.DefaultMessages.cs:line 145
   at Akka.Actor.ActorCell.Invoke(Envelope envelope) in C:\Repositories\olympus\akka.net\src\core\Akka\Actor\ActorCell.DefaultMessages.cs:line 77

@Aaronontheweb Aaronontheweb changed the title [WIP] fixing cluster group router UseRole ignored bug Fixed cluster group router UseRole ignored bug Jan 30, 2018
@@ -145,13 +145,20 @@ public abstract class Group : RouterConfig, IEquatable<Group>
/// <param name="routerDispatcher">TBD</param>
protected Group(IEnumerable<string> paths, string routerDispatcher) : base(routerDispatcher)
{
Paths = paths;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the real fix here. Needed to stop using the deprecated Paths property so the router will fall back to calling the GetPaths(ActorSystem) method instead, which does the right thing. Created a protected _paths property to hold onto the value that will be used inside that method in most built-in routers, which is identical to what the JVM has.

@@ -4061,7 +4061,9 @@ namespace Akka.Routing
}
public abstract class Group : Akka.Routing.RouterConfig, System.IEquatable<Akka.Routing.Group>
{
protected readonly string[] _paths;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it really intended? ;)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep - the value has to be stored somewhere in order to be propagated inside local routers. We kind of effed ourselves by using an automatic property to set the value before.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's intended to work this way, please correct the naming conventions.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Horusiath done - renamed it to fix the ReSharper conventions.

@@ -167,7 +167,7 @@ public override void Start()
var deprecatedPaths = group.Paths;

var paths = deprecatedPaths == null
? group.GetPaths(System).ToArray()
? group.GetPaths(System)?.ToArray()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The next line is call to paths.NonEmpty() - if we're accepting to have paths to be potentially null, this could end with NRE.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

paths.NonEmpty() has a null-check built into it.

@Aaronontheweb
Copy link
Member Author

Bah, forgot to do API approvals

@Aaronontheweb Aaronontheweb merged commit f45adfa into akkadotnet:dev Jan 31, 2018
@Aaronontheweb Aaronontheweb deleted the fix-3294-use-role-ignored-group branch January 31, 2018 17:27
Aaronontheweb added a commit that referenced this pull request Feb 1, 2018
* fixed bug in UseRoleIgnoredSpec

* close #3294 - fixed usages of GetPaths inside all Group router implementations
Aaronontheweb added a commit that referenced this pull request Feb 19, 2018
* fixed bug in UseRoleIgnoredSpec

* close #3294 - fixed usages of GetPaths inside all Group router implementations
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants