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/20 12:59:59 UTC
[lucene-solr] branch jira/solr-15055-2 updated: SOLR-15055: Minor
refactoring for clarity.
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 bb0c600 SOLR-15055: Minor refactoring for clarity.
bb0c600 is described below
commit bb0c6008a7e6054e40e49941765116f8584c77d0
Author: Andrzej Bialecki <ab...@apache.org>
AuthorDate: Wed Jan 20 13:59:34 2021 +0100
SOLR-15055: Minor refactoring for clarity.
---
.../plugins/AffinityPlacementFactory.java | 71 +++++++++++-----------
1 file changed, 34 insertions(+), 37 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 0ad62ac..75096a50 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
@@ -31,7 +31,6 @@ 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;
/**
@@ -268,28 +267,35 @@ public class AffinityPlacementFactory implements PlacementPluginFactory<Affinity
@Override
public void verifyAllowedModification(ModificationRequest modificationRequest, PlacementContext placementContext) throws PlacementModificationException, InterruptedException {
- Cluster cluster = placementContext.getCluster();
if (modificationRequest instanceof DeleteShardsRequest) {
throw new UnsupportedOperationException("not implemented yet");
} else if (modificationRequest instanceof DeleteCollectionRequest) {
- DeleteCollectionRequest deleteCollectionRequest = (DeleteCollectionRequest) modificationRequest;
- Set<String> colocatedCollections = colocatedWith.getOrDefault(deleteCollectionRequest.getCollection().getName(), Set.of());
- for (String primaryName : colocatedCollections) {
- try {
- if (cluster.getCollection(primaryName) != null) {
- // still exists
- throw new PlacementModificationException("colocated collection " + primaryName + " still present");
- }
- } catch (IOException e) {
- throw new PlacementModificationException("failed to retrieve colocated collection information", e);
+ verifyDeleteCollection((DeleteCollectionRequest) modificationRequest, placementContext);
+ } else if (modificationRequest instanceof DeleteReplicasRequest) {
+ verifyDeleteReplicas((DeleteReplicasRequest) modificationRequest, placementContext);
+ } else {
+ throw new UnsupportedOperationException("unsupported request type " + modificationRequest.getClass().getName());
+ }
+ }
+
+ private void verifyDeleteCollection(DeleteCollectionRequest deleteCollectionRequest, PlacementContext placementContext) throws PlacementModificationException, InterruptedException {
+ Cluster cluster = placementContext.getCluster();
+ Set<String> colocatedCollections = colocatedWith.getOrDefault(deleteCollectionRequest.getCollection().getName(), Set.of());
+ for (String primaryName : colocatedCollections) {
+ try {
+ if (cluster.getCollection(primaryName) != null) {
+ // still exists
+ throw new PlacementModificationException("colocated collection " + primaryName + " still present");
}
+ } catch (IOException e) {
+ throw new PlacementModificationException("failed to retrieve colocated collection information", e);
}
- return;
- } else if (!(modificationRequest instanceof DeleteReplicasRequest)) {
- throw new UnsupportedOperationException("unsupported request type " + modificationRequest.getClass().getName());
}
- DeleteReplicasRequest request = (DeleteReplicasRequest) modificationRequest;
- SolrCollection secondaryCollection = request.getCollection();
+ }
+
+ private void verifyDeleteReplicas(DeleteReplicasRequest deleteReplicasRequest, PlacementContext placementContext) throws PlacementModificationException, InterruptedException {
+ Cluster cluster = placementContext.getCluster();
+ SolrCollection secondaryCollection = deleteReplicasRequest.getCollection();
Set<String> colocatedCollections = colocatedWith.get(secondaryCollection.getName());
if (colocatedCollections == null) {
return;
@@ -304,29 +310,20 @@ public class AffinityPlacementFactory implements PlacementPluginFactory<Affinity
// find the colocated-with collections
Map<Node, Set<String>> colocatingNodes = new HashMap<>();
- AtomicReference<Exception> exc = new AtomicReference<>();
- colocatedCollections.forEach(collName -> {
- if (exc.get() != null) {
- return;
- }
- SolrCollection coll;
- try {
- coll = cluster.getCollection(collName);
- } catch (Exception e) {
- exc.set(e);
- return;
+ try {
+ for (String colocatedCollection : colocatedCollections) {
+ SolrCollection coll = cluster.getCollection(colocatedCollection);
+ coll.shards().forEach(shard ->
+ shard.replicas().forEach(replica -> {
+ colocatingNodes.computeIfAbsent(replica.getNode(), n -> new HashSet<>())
+ .add(coll.getName());
+ }));
}
- coll.shards().forEach(shard ->
- shard.replicas().forEach(replica -> {
- colocatingNodes.computeIfAbsent(replica.getNode(), n -> new HashSet<>())
- .add(coll.getName());
- }));
- });
- if (exc.get() != null) {
- throw new PlacementModificationException("failed to retrieve colocated collection information", exc.get());
+ } catch (IOException ioe) {
+ throw new PlacementModificationException("failed to retrieve colocated collection information", ioe);
}
PlacementModificationException exception = null;
- for (Replica replica : request.getReplicas()) {
+ for (Replica replica : deleteReplicasRequest.getReplicas()) {
if (!colocatingNodes.containsKey(replica.getNode())) {
continue;
}