diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2021-05-17 21:14:39 +0200 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2021-05-17 21:14:39 +0200 |
commit | 38d447ad818c8e0183325db5751635fece76989b (patch) | |
tree | 20b813c4addf7c13ac71b232724468fcdf7d253d | |
parent | c2f70e36eeff84cc85d06b1d0e8c8acbd29410cc (diff) |
Remove by index is not thread safe, even if the list is a CopyOnWriteArrayList.
iOne thing is that it might throw if index is invalid. The other thing is that the
index might point to something completely different. But remove by value should be fine.
-rw-r--r-- | documentapi/src/main/java/com/yahoo/documentapi/messagebus/protocol/ContentPolicy.java | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/documentapi/src/main/java/com/yahoo/documentapi/messagebus/protocol/ContentPolicy.java b/documentapi/src/main/java/com/yahoo/documentapi/messagebus/protocol/ContentPolicy.java index f8e6989bbfa..792d3628ba0 100644 --- a/documentapi/src/main/java/com/yahoo/documentapi/messagebus/protocol/ContentPolicy.java +++ b/documentapi/src/main/java/com/yahoo/documentapi/messagebus/protocol/ContentPolicy.java @@ -108,13 +108,13 @@ public class ContentPolicy extends SlobrokPolicy { while ((targets.total != 0) && (100 * targets.list.size() / targets.total >= requiredUpPercentageToSendToKnownGoodNodes)) { - int randIndex = randomizer.nextInt(targets.list.size()); - String targetSpec = getTargetSpec(targets.list.get(randIndex), context); + Integer distributor = targets.list.get(randomizer.nextInt(targets.list.size())); + String targetSpec = getTargetSpec(distributor, context); if (targetSpec != null) { context.trace(3, "Sending to random node seen up in cluster state"); return targetSpec; } - targets.list.remove(randIndex); + targets.list.remove(distributor); } context.trace(3, "Too few nodes seen up in state. Sending totally random."); return getTargetSpec(null, context); |