Skip to content

Commit 8c64932

Browse files
authored
Small code fixes to Placement Plugins (#4213)
1 parent 2cd2e4e commit 8c64932

5 files changed

Lines changed: 13 additions & 30 deletions

File tree

solr/core/src/java/org/apache/solr/cluster/placement/plugins/AffinityPlacementConfig.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ public class AffinityPlacementConfig implements PlacementPluginConfig {
4040
*
4141
* <p>Nodes on which this system property is not defined are considered being in the same
4242
* Availability Zone {@link #UNDEFINED_AVAILABILITY_ZONE} (hopefully the value of this constant is
43-
* not the name of a real Availability Zone :).
43+
* not the name of a real Availability Zone).
4444
*/
4545
public static final String AVAILABILITY_ZONE_SYSPROP = "availability_zone";
4646

4747
/**
4848
* Name of the system property on a node indicating the type of replicas allowed on that node. The
4949
* value of that system property is a comma separated list or a single string of value names of
50-
* {@link org.apache.solr.cluster.Replica.ReplicaType} (case insensitive). If that property is not
50+
* {@link org.apache.solr.cluster.Replica.ReplicaType} (case-insensitive). If that property is not
5151
* defined, that node is considered accepting all replica types (i.e. undefined is equivalent to
5252
* {@code "NRT,Pull,tlog"}).
5353
*/
@@ -136,8 +136,8 @@ public class AffinityPlacementConfig implements PlacementPluginConfig {
136136

137137
/**
138138
* Determines the maximum number of replicas of a particular type of a particular shard that can
139-
* be placed within a single domain (as defined by the @link #SPREAD_DOMAIN_SYSPROP} System
140-
* property.
139+
* be placed within a single domain (as defined by the {@link #SPREAD_DOMAIN_SYSPROP} System
140+
* property).
141141
*/
142142
@JsonProperty public Integer maxReplicasPerShardInDomain = -1;
143143

@@ -163,7 +163,7 @@ public AffinityPlacementConfig(long minimalFreeDiskGB, long prioritizedFreeDiskG
163163
* @param prioritizedFreeDiskGB prioritized free disk GB.
164164
* @param withCollection configuration of co-located collections: keys are primary collection
165165
* names and values are secondary collection names.
166-
* @param collectionNodeType configuration of reequired node types per collection. Keys are
166+
* @param collectionNodeType configuration of required node types per collection. Keys are
167167
* collection names and values are comma-separated lists of required node types.
168168
*/
169169
public AffinityPlacementConfig(

solr/core/src/java/org/apache/solr/cluster/placement/plugins/AffinityPlacementFactory.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@
7777
* }' http://localhost:8983/api/cluster/plugin
7878
* </pre>
7979
*
80-
* <p>In order to delete the placement-plugin section (and to fallback to either Legacy or rule
81-
* based placement if configured for a collection), execute:
80+
* <p>In order to delete the placement-plugin section (and fallback to either Legacy or rule based
81+
* placement if configured for a collection), execute:
8282
*
8383
* <pre>
8484
*
@@ -295,7 +295,7 @@ protected Map<Node, WeightedNode> getBaseWeightedNodes(
295295
}
296296
}
297297

298-
// If there are not multiple spreadDomains, then there is nothing to spread across
298+
// only spread across if there are multiple spreadDomains
299299
if (affinityPlacementContext.allSpreadDomains.size() < 2) {
300300
affinityPlacementContext.doSpreadAcrossDomains = false;
301301
}
@@ -307,8 +307,7 @@ AffinityNode newNodeFromMetrics(
307307
Node node,
308308
AttributeValues attrValues,
309309
AffinityPlacementContext affinityPlacementContext,
310-
boolean skipNodesWithErrors)
311-
throws PlacementException {
310+
boolean skipNodesWithErrors) {
312311
Set<Replica.ReplicaType> supportedReplicaTypes =
313312
attrValues.getSystemProperty(node, AffinityPlacementConfig.REPLICA_TYPE_SYSPROP).stream()
314313
.flatMap(s -> Arrays.stream(s.split(",")))

solr/core/src/java/org/apache/solr/cluster/placement/plugins/OrderedNodePlacementPlugin.java

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public List<PlacementPlan> computePlacements(
9393
}
9494

9595
List<WeightedNode> nodesForRequest =
96-
weightedNodes.stream().filter(request::isTargetingNode).collect(Collectors.toList());
96+
weightedNodes.stream().filter(request::isTargetingNode).toList();
9797

9898
SolrCollection solrCollection = request.getCollection();
9999
// Now place all replicas of all shards on available nodes
@@ -241,7 +241,7 @@ public BalancePlan computeBalancing(
241241
List<Replica> availableReplicasToMove =
242242
highestWeight.getAllReplicasOnNode().stream()
243243
.sorted(Comparator.comparing(Replica::getReplicaName))
244-
.collect(Collectors.toList());
244+
.toList();
245245
int combinedNodeWeights = highestWeight.calcWeight() + lowestWeight.calcWeight();
246246
for (Replica r : availableReplicasToMove) {
247247
// Only continue if the replica can be removed from the old node and moved to the new node
@@ -284,7 +284,7 @@ public BalancePlan computeBalancing(
284284
break;
285285
}
286286
}
287-
// For now we do not have any way to see if there are out-of-date notes in the middle of the
287+
// For now, we do not have any way to see if there are out-of-date nodes in the middle of the
288288
// TreeSet. Therefore, we need to re-sort this list after every selection. In the future, we
289289
// should find a way to re-sort the out-of-date nodes without having to sort all nodes.
290290
traversedHighNodes.addAll(orderedNodes);
@@ -442,12 +442,6 @@ public Set<String> getShardsOnNode(String collection) {
442442
return replicas.getOrDefault(collection, Collections.emptyMap()).keySet();
443443
}
444444

445-
public boolean hasShardOnNode(Shard shard) {
446-
return replicas
447-
.getOrDefault(shard.getCollection().getName(), Collections.emptyMap())
448-
.containsKey(shard.getShardName());
449-
}
450-
451445
public Set<Replica> getReplicasForShardOnNode(Shard shard) {
452446
return Optional.ofNullable(replicas.get(shard.getCollection().getName()))
453447
.map(m -> m.get(shard.getShardName()))
@@ -775,15 +769,6 @@ public void add(WeightedNode node) {
775769
}
776770
}
777771

778-
/**
779-
* Get the number of nodes in the heap.
780-
*
781-
* @return number of nodes
782-
*/
783-
public int size() {
784-
return size;
785-
}
786-
787772
/**
788773
* Check if the heap is empty.
789774
*

solr/core/src/java/org/apache/solr/cluster/placement/plugins/RandomPlacementFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
/**
3232
* Factory for creating {@link RandomPlacementPlugin}, a placement plugin implementing random
3333
* placement for new collection creation while preventing two replicas of same shard from being
34-
* placed on same node..
34+
* placed on same node.
3535
*
3636
* <p>See {@link RandomNode} for information on how this PlacementFactory weights nodes.
3737
*

solr/core/src/test/org/apache/solr/cluster/placement/plugins/AffinityPlacementFactoryTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,6 @@ public void testFreeDiskConstraintsWithNewReplicas() throws Exception {
748748
int NUM_NODES = 3;
749749
Builders.ClusterBuilder clusterBuilder =
750750
Builders.newClusterBuilder().initializeLiveNodes(NUM_NODES);
751-
Node smallNode = null;
752751
for (int i = 0; i < NUM_NODES; i++) {
753752
Builders.NodeBuilder nodeBuilder = clusterBuilder.getLiveNodeBuilders().get(i);
754753
// Act as if the two replicas were placed on nodes 1 and 2

0 commit comments

Comments
 (0)