-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Cluster.JoinAsync / Cluster.JoinSeedNodesAsync #3196
Conversation
fb93037
to
64dddc4
Compare
src/core/Akka.Cluster/Cluster.cs
Outdated
var completion = new TaskCompletionSource<NotUsed>(); | ||
this.RegisterOnMemberUp(() => completion.TrySetResult(NotUsed.Instance)); | ||
this.RegisterOnMemberRemoved(() => completion.TrySetException( | ||
new ClusterJoinFailedException($"Node has been removed from the cluster before it managed to join {address}."))); |
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.
@Aaronontheweb question to you: does this RegisterOnMemberRemoved
has any sense from the perspective of joining to cluster? I've taken a look at cluster protocol description, and theoretically it's possible, however I've never run into such case.
Going to noodle on that one; the task has to fail in order for this to be useful. |
I've added a test case for failure scenario (simply joining to some random address, which isn't used by any cluster node). It passes - this way we have covered all cases: successful/failed async join and cancellation. |
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.
Need to add a pair of additional tests to ensure that this method is idempotent. I'm confident that based on its implementation that it should be but it's best to have specs that can prove it.
@@ -306,6 +308,140 @@ public void A_cluster_must_be_allowed_to_join_and_leave_with_local_address() | |||
} | |||
} | |||
|
|||
[Fact] | |||
public void A_cluster_must_be_able_to_JoinAsync() |
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.
@Horusiath need a spec here that tests for "what happens if this method is called when we're already connected to the cluster?"
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 will immediately complete with success (I've seen this in the impl), but I guess you're right. We probably should have tests for that.
} | ||
|
||
[Fact] | ||
public void A_cluster_must_be_able_to_join_async_to_seed_nodes() |
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.
@Horusiath need a spec here that tests for "what happens if this method is called when we're already connected to the cluster?"
I've added additional checks:
|
Motivation
So far we have only fire-and-forget version of
Cluster.Join
. If user wanted to be sure, that the current node actually joined the cluster, he/she had to define his/her logic inCluster.OnMemberUp
callback. Example:Proposal
This PR introduces two methods:
Task Cluster.JoinAsync(Address, CancellationToken = default(CancellationToken)
Task Cluster.JoinSeedNodesAsync(IEnumerable<Address>, CancellationToken = default(CancellationToken)
With them, we can asynchronously await until the current node will successfully join the cluster:
Concerns
One thing, I'm curious about (probably @Aaronontheweb will be able to answer) - in current implementation
JoinAsync
can be cancelled, but it cannot fail. How can we detect that nodes had failed to join the cluster? WillCluster.OnMemberRemoved
be helpful here? Could node be removed before it actually reaches member UP status?