From 953119d5105331fa04b1c58d15ff957eeb81b7b8 Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Fri, 26 Apr 2019 09:48:25 +0200 Subject: Also protect oldClusterVersionGottenCount --- .../com/yahoo/documentapi/messagebus/protocol/StoragePolicy.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'documentapi') diff --git a/documentapi/src/main/java/com/yahoo/documentapi/messagebus/protocol/StoragePolicy.java b/documentapi/src/main/java/com/yahoo/documentapi/messagebus/protocol/StoragePolicy.java index 75de698cc5e..2d6d47cf8ab 100644 --- a/documentapi/src/main/java/com/yahoo/documentapi/messagebus/protocol/StoragePolicy.java +++ b/documentapi/src/main/java/com/yahoo/documentapi/messagebus/protocol/StoragePolicy.java @@ -30,6 +30,7 @@ import java.util.Map; import java.util.Optional; import java.util.Random; import java.util.concurrent.CopyOnWriteArrayList; +import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; import java.util.logging.Logger; @@ -317,7 +318,7 @@ public class StoragePolicy extends ExternalSlobrokPolicy { private final Distribution distribution; private final InstabilityChecker persistentFailureChecker; private AtomicReference safeCachedClusterState = new AtomicReference<>(null); - private int oldClusterVersionGottenCount = 0; + private final AtomicInteger oldClusterVersionGottenCount = new AtomicInteger(0); private final int maxOldClusterVersionBeforeSendingRandom; // Reset cluster version protection DistributorSelectionLogic(Parameters params, ExternalSlobrokPolicy policy) { @@ -456,8 +457,8 @@ public class StoragePolicy extends ExternalSlobrokPolicy { private void resetCachedStateIfClusterStateVersionLikelyRolledBack(ClusterState newState) { ClusterState cachedClusterState = safeCachedClusterState.get(); if (cachedClusterState != null && cachedClusterState.getVersion() > newState.getVersion()) { - if (++oldClusterVersionGottenCount >= maxOldClusterVersionBeforeSendingRandom) { - oldClusterVersionGottenCount = 0; + if (oldClusterVersionGottenCount.incrementAndGet() >= maxOldClusterVersionBeforeSendingRandom) { + oldClusterVersionGottenCount.set(0); safeCachedClusterState.set(null); } } -- cgit v1.2.3