5959import java .util .Map ;
6060import java .util .Optional ;
6161import java .util .Set ;
62+ import java .util .concurrent .atomic .AtomicReference ;
6263import java .util .function .BiConsumer ;
6364import java .util .function .Function ;
6465import java .util .function .LongSupplier ;
@@ -84,7 +85,7 @@ public class JoinHelper {
8485
8586 final Set <Tuple <DiscoveryNode , JoinRequest >> pendingOutgoingJoins = ConcurrentCollections .newConcurrentSet ();
8687
87- private volatile FailedJoinAttempt lastFailedJoinAttempt ;
88+ private AtomicReference < FailedJoinAttempt > lastFailedJoinAttempt = new AtomicReference <>() ;
8889
8990 JoinHelper (Settings settings , AllocationService allocationService , MasterService masterService ,
9091 TransportService transportService , LongSupplier currentTermSupplier , Supplier <ClusterState > currentStateSupplier ,
@@ -217,9 +218,10 @@ void logWarnWithTimestamp() {
217218
218219
219220 void logLastFailedJoinAttempt () {
220- FailedJoinAttempt attempt = lastFailedJoinAttempt ;
221+ FailedJoinAttempt attempt = lastFailedJoinAttempt . get () ;
221222 if (attempt != null ) {
222223 attempt .logWarnWithTimestamp ();
224+ lastFailedJoinAttempt .compareAndSet (attempt , null );
223225 }
224226 }
225227
@@ -241,15 +243,15 @@ public Empty read(StreamInput in) {
241243 public void handleResponse (Empty response ) {
242244 pendingOutgoingJoins .remove (dedupKey );
243245 logger .debug ("successfully joined {} with {}" , destination , joinRequest );
244- lastFailedJoinAttempt = null ;
246+ lastFailedJoinAttempt . set ( null ) ;
245247 }
246248
247249 @ Override
248250 public void handleException (TransportException exp ) {
249251 pendingOutgoingJoins .remove (dedupKey );
250252 FailedJoinAttempt attempt = new FailedJoinAttempt (destination , joinRequest , exp );
251253 attempt .logNow ();
252- lastFailedJoinAttempt = attempt ;
254+ lastFailedJoinAttempt . set ( attempt ) ;
253255 }
254256
255257 @ Override
0 commit comments