Skip to content

Commit 22463a1

Browse files
committed
JVMCBC-1592 Shuffle node list instead of rotating
Motivation ---------- Avoid a pathological condition where the number of open buckets is equal to the number of nodes, and the config refresh request for one of the buckets always goes to a degraded node. By randomizing the node selection, we ensure the request eventually goes to one of the other nodes. Change-Id: I013328fab5286775d796b1cc57ca0ba7933bb460 Reviewed-on: https://review.couchbase.org/c/couchbase-jvm-clients/+/221189 Tested-by: Build Bot <[email protected]> Reviewed-by: Michael Reiche <[email protected]>
1 parent 4f5880f commit 22463a1

File tree

1 file changed

+1
-18
lines changed

1 file changed

+1
-18
lines changed

core-io/src/main/java/com/couchbase/client/core/config/refresher/KeyValueBucketRefresher.java

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
import java.util.Set;
4747
import java.util.concurrent.ConcurrentHashMap;
4848
import java.util.concurrent.atomic.AtomicInteger;
49-
import java.util.concurrent.atomic.AtomicLong;
5049
import java.util.stream.Collectors;
5150

5251
import static com.couchbase.client.core.config.ConfigurationProvider.TRIGGERED_BY_CONFIG_CHANGE_NOTIFICATION;
@@ -97,12 +96,6 @@ public class KeyValueBucketRefresher implements BucketRefresher {
9796
*/
9897
private final ConfigurationProvider provider;
9998

100-
/**
101-
* The global offset is used to make sure each KV node eventually gets used
102-
* by shifting on each invocation.
103-
*/
104-
private final AtomicLong nodeOffset = new AtomicLong(0);
105-
10699
/**
107100
* Holds all current registrations and their last timestamp when the bucket has been
108101
* updated.
@@ -242,7 +235,7 @@ private List<NodeInfo> filterEligibleNodes(final String name) {
242235
}
243236

244237
List<NodeInfo> nodes = new ArrayList<>(config.nodes());
245-
shiftNodeList(nodes);
238+
Collections.shuffle(nodes);
246239

247240
return nodes
248241
.stream()
@@ -313,16 +306,6 @@ private ConfigVersion currentVersion(String bucketName) {
313306
return config == null ? ConfigVersion.ZERO : config.version();
314307
}
315308

316-
/**
317-
* Helper method to transparently rearrange the node list based on the current global offset.
318-
*
319-
* @param nodeList the list to shift.
320-
*/
321-
private <T> void shiftNodeList(final List<T> nodeList) {
322-
int shiftBy = (int) (nodeOffset.getAndIncrement() % nodeList.size());
323-
Collections.rotate(nodeList, -shiftBy);
324-
}
325-
326309
@Override
327310
public Mono<Void> register(final String name) {
328311
return Mono.defer(() -> {

0 commit comments

Comments
 (0)