You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ab...@apache.org on 2021/01/14 12:11:27 UTC
[lucene-solr] branch jira/solr-15055-2 updated: SOLR-15055: Fix the
replica count verification.
This is an automated email from the ASF dual-hosted git repository.
ab pushed a commit to branch jira/solr-15055-2
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git
The following commit(s) were added to refs/heads/jira/solr-15055-2 by this push:
new e296eb0 SOLR-15055: Fix the replica count verification.
e296eb0 is described below
commit e296eb020d48f3e1cc84d75d72d420bb15e61057
Author: Andrzej Bialecki <ab...@apache.org>
AuthorDate: Thu Jan 14 13:10:50 2021 +0100
SOLR-15055: Fix the replica count verification.
---
.../plugins/AffinityPlacementFactory.java | 29 +++++++++++++---------
1 file changed, 17 insertions(+), 12 deletions(-)
diff --git a/solr/core/src/java/org/apache/solr/cluster/placement/plugins/AffinityPlacementFactory.java b/solr/core/src/java/org/apache/solr/cluster/placement/plugins/AffinityPlacementFactory.java
index 799562e..ad75053 100644
--- a/solr/core/src/java/org/apache/solr/cluster/placement/plugins/AffinityPlacementFactory.java
+++ b/solr/core/src/java/org/apache/solr/cluster/placement/plugins/AffinityPlacementFactory.java
@@ -30,6 +30,7 @@ import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.util.*;
+import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
@@ -265,6 +266,14 @@ public class AffinityPlacementFactory implements PlacementPluginFactory<Affinity
if (!withCollections.values().contains(secondaryCollection.getName())) {
return;
}
+ Map<Node, Map<String, AtomicInteger>> secondaryNodeShardReplicas = new HashMap<>();
+ secondaryCollection.shards().forEach(shard ->
+ shard.replicas().forEach(replica -> {
+ secondaryNodeShardReplicas.computeIfAbsent(replica.getNode(), n -> new HashMap<>())
+ .computeIfAbsent(replica.getShard().getShardName(), s -> new AtomicInteger())
+ .incrementAndGet();
+ }));
+
// find the colocated-with collections
Cluster cluster = placementContext.getCluster();
Set<SolrCollection> colocatedCollections = new HashSet<>();
@@ -301,18 +310,14 @@ public class AffinityPlacementFactory implements PlacementPluginFactory<Affinity
if (!colocatingNodes.containsKey(replica.getNode())) {
continue;
}
- // check that this is the only replica of this shard on this node
- Shard shard = replica.getShard();
- boolean hasOtherReplicas = false;
- for (Replica otherReplica : shard.replicas()) {
- if (otherReplica.getNode().equals(replica.getNode())) {
- hasOtherReplicas = true;
- break;
- }
- }
- // ok to delete when at least one remains on this node
- if (hasOtherReplicas) {
- return;
+ // check that there will be at least one replica remaining
+ AtomicInteger secondaryCount = secondaryNodeShardReplicas
+ .getOrDefault(replica.getNode(), Map.of())
+ .getOrDefault(replica.getShard().getShardName(), new AtomicInteger());
+ if (secondaryCount.get() > 1) {
+ // we can delete it - record the deletion
+ secondaryCount.decrementAndGet();
+ continue;
}
// fail - this replica cannot be removed
if (exception == null) {