@@ -2691,6 +2691,7 @@ internal sealed class JoinSeedNodeProcess : UntypedActor
2691
2691
private readonly ILoggingAdapter _log = Context . GetLogger ( ) ;
2692
2692
2693
2693
private readonly ImmutableList < Address > _seeds ;
2694
+ private readonly ImmutableList < Address > _otherSeeds ;
2694
2695
private readonly Address _selfAddress ;
2695
2696
private int _attempts = 0 ;
2696
2697
@@ -2706,6 +2707,7 @@ public JoinSeedNodeProcess(ImmutableList<Address> seeds)
2706
2707
{
2707
2708
_selfAddress = Cluster . Get ( Context . System ) . SelfAddress ;
2708
2709
_seeds = seeds ;
2710
+ _otherSeeds = _seeds . Remove ( _selfAddress ) ;
2709
2711
if ( seeds . IsEmpty || seeds . Head ( ) == _selfAddress )
2710
2712
throw new ArgumentException ( "Join seed node should not be done" ) ;
2711
2713
Context . SetReceiveTimeout ( Cluster . Get ( Context . System ) . Settings . SeedNodeTimeout ) ;
@@ -2725,46 +2727,53 @@ protected override void PreStart()
2725
2727
/// <param name="message">TBD</param>
2726
2728
protected override void OnReceive ( object message )
2727
2729
{
2728
- if ( message is InternalClusterAction . JoinSeenNode )
2730
+ switch ( message )
2729
2731
{
2730
- //send InitJoin to all seed nodes (except myself)
2731
- foreach ( var path in _seeds . Where ( x => x != _selfAddress )
2732
- . Select ( y => Context . ActorSelection ( Context . Parent . Path . ToStringWithAddress ( y ) ) ) )
2732
+ case InternalClusterAction . JoinSeenNode _:
2733
2733
{
2734
- path . Tell ( new InternalClusterAction . InitJoin ( ) ) ;
2734
+ //send InitJoin to all seed nodes (except myself)
2735
+ foreach ( var path in _otherSeeds
2736
+ . Select ( y => Context . ActorSelection ( Context . Parent . Path . ToStringWithAddress ( y ) ) ) )
2737
+ {
2738
+ path . Tell ( new InternalClusterAction . InitJoin ( ) ) ;
2739
+ }
2740
+ _attempts ++ ;
2741
+ break ;
2735
2742
}
2736
- _attempts ++ ;
2737
- }
2738
- else if ( message is InternalClusterAction . InitJoinAck )
2739
- {
2740
- //first InitJoinAck reply
2741
- var initJoinAck = ( InternalClusterAction . InitJoinAck ) message ;
2742
- Context . Parent . Tell ( new ClusterUserAction . JoinTo ( initJoinAck . Address ) ) ;
2743
- Context . Become ( Done ) ;
2744
- }
2745
- else if ( message is InternalClusterAction . InitJoinNack ) { } //that seed was uninitialized
2746
- else if ( message is ReceiveTimeout )
2747
- {
2748
- if ( _attempts >= 2 )
2749
- _log . Warning (
2750
- "Couldn't join seed nodes after [{0}] attempts, will try again. seed-nodes=[{1}]" ,
2751
- _attempts , string . Join ( "," , _seeds . Where ( x => ! x . Equals ( _selfAddress ) ) ) ) ;
2752
- //no InitJoinAck received - try again
2753
- Self . Tell ( new InternalClusterAction . JoinSeenNode ( ) ) ;
2754
- }
2755
- else
2756
- {
2757
- Unhandled ( message ) ;
2743
+ case InternalClusterAction . InitJoinAck initJoinAck :
2744
+ //first InitJoinAck reply
2745
+ Context . Parent . Tell ( new ClusterUserAction . JoinTo ( initJoinAck . Address ) ) ;
2746
+ Context . Become ( Done ) ;
2747
+ break ;
2748
+ case InternalClusterAction . InitJoinNack _:
2749
+ break ; //that seed was uninitialized
2750
+ case ReceiveTimeout _:
2751
+ {
2752
+ if ( _attempts >= 2 )
2753
+ _log . Warning (
2754
+ "Couldn't join seed nodes after [{0}] attempts, will try again. seed-nodes=[{1}]" ,
2755
+ _attempts , string . Join ( "," , _seeds . Where ( x => ! x . Equals ( _selfAddress ) ) ) ) ;
2756
+ //no InitJoinAck received - try again
2757
+ Self . Tell ( new InternalClusterAction . JoinSeenNode ( ) ) ;
2758
+ break ;
2759
+ }
2760
+ default :
2761
+ Unhandled ( message ) ;
2762
+ break ;
2758
2763
}
2759
2764
}
2760
2765
2761
2766
private void Done ( object message )
2762
2767
{
2763
- if ( message is InternalClusterAction . InitJoinAck )
2768
+ switch ( message )
2764
2769
{
2765
- //already received one, skip the rest
2770
+ case InternalClusterAction . InitJoinAck _:
2771
+ //already received one, skip the rest
2772
+ break ;
2773
+ case ReceiveTimeout _:
2774
+ Context . Stop ( Self ) ;
2775
+ break ;
2766
2776
}
2767
- else if ( message is ReceiveTimeout ) Context . Stop ( Self ) ;
2768
2777
}
2769
2778
}
2770
2779
@@ -2784,16 +2793,17 @@ internal sealed class FirstSeedNodeProcess : UntypedActor
2784
2793
{
2785
2794
private readonly ILoggingAdapter _log = Context . GetLogger ( ) ;
2786
2795
2796
+ private readonly ImmutableList < Address > _seeds ;
2787
2797
private ImmutableList < Address > _remainingSeeds ;
2788
2798
private readonly Address _selfAddress ;
2789
2799
private readonly Cluster _cluster ;
2790
2800
private readonly Deadline _timeout ;
2791
2801
private readonly ICancelable _retryTaskToken ;
2792
2802
2793
2803
/// <summary>
2794
- /// TBD
2804
+ /// Launches a new instance of the "first seed node" joining process.
2795
2805
/// </summary>
2796
- /// <param name="seeds">TBD </param>
2806
+ /// <param name="seeds">The set of seed nodes to join. </param>
2797
2807
/// <exception cref="ArgumentException">
2798
2808
/// This exception is thrown when either the number of specified <paramref name="seeds"/> is less than or equal to 1
2799
2809
/// or the first listed seed is a reference to the <see cref="IActorContext.System">IUntypedActorContext.System</see>'s address.
@@ -2806,63 +2816,63 @@ public FirstSeedNodeProcess(ImmutableList<Address> seeds)
2806
2816
if ( seeds . Count <= 1 || seeds . Head ( ) != _selfAddress )
2807
2817
throw new ArgumentException ( "Join seed node should not be done" ) ;
2808
2818
2819
+ _seeds = seeds ;
2809
2820
_remainingSeeds = seeds . Remove ( _selfAddress ) ;
2810
2821
_timeout = Deadline . Now + _cluster . Settings . SeedNodeTimeout ;
2811
2822
_retryTaskToken = Context . System . Scheduler . ScheduleTellRepeatedlyCancelable ( TimeSpan . FromSeconds ( 1 ) , TimeSpan . FromSeconds ( 1 ) , Self , new InternalClusterAction . JoinSeenNode ( ) , Self ) ;
2812
2823
Self . Tell ( new InternalClusterAction . JoinSeenNode ( ) ) ;
2813
2824
}
2814
2825
2815
- /// <summary>
2816
- /// TBD
2817
- /// </summary>
2818
2826
protected override void PostStop ( )
2819
2827
{
2820
2828
_retryTaskToken . Cancel ( ) ;
2821
2829
}
2822
2830
2823
- /// <summary>
2824
- /// TBD
2825
- /// </summary>
2826
- /// <param name="message">TBD</param>
2827
2831
protected override void OnReceive ( object message )
2828
2832
{
2829
- if ( message is InternalClusterAction . JoinSeenNode )
2833
+ switch ( message )
2830
2834
{
2831
- if ( _timeout . HasTimeLeft )
2835
+ case InternalClusterAction . JoinSeenNode _ when _timeout . HasTimeLeft :
2832
2836
{
2833
2837
// send InitJoin to remaining seed nodes (except myself)
2834
2838
foreach ( var seed in _remainingSeeds . Select (
2835
- x => Context . ActorSelection ( Context . Parent . Path . ToStringWithAddress ( x ) ) ) )
2839
+ x => Context . ActorSelection ( Context . Parent . Path . ToStringWithAddress ( x ) ) ) )
2836
2840
seed . Tell ( new InternalClusterAction . InitJoin ( ) ) ;
2841
+ break ;
2837
2842
}
2838
- else
2843
+ case InternalClusterAction . JoinSeenNode _ :
2839
2844
{
2845
+ if ( _log . IsDebugEnabled )
2846
+ {
2847
+ _log . Debug ( "Couldn't join other seed nodes, will join myself. seed-nodes=[{0}]" , string . Join ( "," , _seeds ) ) ;
2848
+ }
2840
2849
// no InitJoinAck received, initialize new cluster by joining myself
2841
2850
Context . Parent . Tell ( new ClusterUserAction . JoinTo ( _selfAddress ) ) ;
2842
2851
Context . Stop ( Self ) ;
2852
+ break ;
2843
2853
}
2844
- }
2845
- else if ( message is InternalClusterAction . InitJoinAck )
2846
- {
2847
- // first InitJoinAck reply, join existing cluster
2848
- var initJoinAck = ( InternalClusterAction . InitJoinAck ) message ;
2849
- Context . Parent . Tell ( new ClusterUserAction . JoinTo ( initJoinAck . Address ) ) ;
2850
- Context . Stop ( Self ) ;
2851
- }
2852
- else if ( message is InternalClusterAction . InitJoinNack )
2853
- {
2854
- var initJoinNack = ( InternalClusterAction . InitJoinNack ) message ;
2855
- _remainingSeeds = _remainingSeeds . Remove ( initJoinNack . Address ) ;
2856
- if ( _remainingSeeds . IsEmpty )
2857
- {
2858
- // initialize new cluster by joining myself when nacks from all other seed nodes
2859
- Context . Parent . Tell ( new ClusterUserAction . JoinTo ( _selfAddress ) ) ;
2854
+ case InternalClusterAction . InitJoinAck initJoinAck :
2855
+ _log . Info ( "Received InitJoinAck message from [{0}] to [{1}]" , initJoinAck . Address , _selfAddress ) ;
2856
+ // first InitJoinAck reply, join existing cluster
2857
+ Context . Parent . Tell ( new ClusterUserAction . JoinTo ( initJoinAck . Address ) ) ;
2860
2858
Context . Stop ( Self ) ;
2859
+ break ;
2860
+ case InternalClusterAction . InitJoinNack initJoinNack :
2861
+ {
2862
+ _log . Info ( "Received InitJoinNack message from [{0}] to [{1}]" , initJoinNack . Address , _selfAddress ) ;
2863
+ _remainingSeeds = _remainingSeeds . Remove ( initJoinNack . Address ) ;
2864
+ if ( _remainingSeeds . IsEmpty )
2865
+ {
2866
+ // initialize new cluster by joining myself when nacks from all other seed nodes
2867
+ Context . Parent . Tell ( new ClusterUserAction . JoinTo ( _selfAddress ) ) ;
2868
+ Context . Stop ( Self ) ;
2869
+ }
2870
+
2871
+ break ;
2861
2872
}
2862
- }
2863
- else
2864
- {
2865
- Unhandled ( message ) ;
2873
+ default :
2874
+ Unhandled ( message ) ;
2875
+ break ;
2866
2876
}
2867
2877
}
2868
2878
}
0 commit comments