You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by dw...@apache.org on 2021/03/10 09:56:14 UTC
[lucene] 03/04: SOLR-15130: Support node_type per-collection node
sets.
This is an automated email from the ASF dual-hosted git repository.
dweiss pushed a commit to branch jira/solr-15130
in repository https://gitbox.apache.org/repos/asf/lucene.git
commit 9bd4c424323e7421de2ab091e12d7160eaa8947f
Author: Andrzej Bialecki <ab...@apache.org>
AuthorDate: Mon Feb 15 18:05:53 2021 +0100
SOLR-15130: Support node_type per-collection node sets.
---
.../cluster/placement/PlacementPluginConfig.java | 2 +
.../placement/plugins/AffinityPlacementConfig.java | 39 +++++++-
.../plugins/AffinityPlacementFactory.java | 46 ++-------
.../apache/solr/cluster/placement/Builders.java | 1 +
.../plugins/AffinityPlacementFactoryTest.java | 111 +++++++++++++++++++--
5 files changed, 154 insertions(+), 45 deletions(-)
diff --git a/solr/core/src/java/org/apache/solr/cluster/placement/PlacementPluginConfig.java b/solr/core/src/java/org/apache/solr/cluster/placement/PlacementPluginConfig.java
index fd5566d..758e5fe 100644
--- a/solr/core/src/java/org/apache/solr/cluster/placement/PlacementPluginConfig.java
+++ b/solr/core/src/java/org/apache/solr/cluster/placement/PlacementPluginConfig.java
@@ -25,4 +25,6 @@ import org.apache.solr.common.util.ReflectMapWriter;
* annotated with {@link org.apache.solr.common.annotation.JsonProperty} if needed.
*/
public interface PlacementPluginConfig extends ReflectMapWriter {
+
+ public static final String COLLECTION_PROPERTY_PREFIX = "placement.";
}
diff --git a/solr/core/src/java/org/apache/solr/cluster/placement/plugins/AffinityPlacementConfig.java b/solr/core/src/java/org/apache/solr/cluster/placement/plugins/AffinityPlacementConfig.java
index eefd3f2..10eecd4 100644
--- a/solr/core/src/java/org/apache/solr/cluster/placement/plugins/AffinityPlacementConfig.java
+++ b/solr/core/src/java/org/apache/solr/cluster/placement/plugins/AffinityPlacementConfig.java
@@ -25,8 +25,43 @@ import org.apache.solr.common.annotation.JsonProperty;
*/
public class AffinityPlacementConfig implements PlacementPluginConfig {
- public static final String COLLECTION_NODE_TYPE_PROPERTY = "placement.affinity.node_type";
- public static final String WITH_COLLECTION_PROPERTY = "placement.affinity.withCollection";
+ /**
+ * Collection property that defines a comma-separate list of required node types.
+ */
+ public static final String COLLECTION_NODE_TYPE_PROPERTY = COLLECTION_PROPERTY_PREFIX + "affinity.node_type";
+ /**
+ * Collection property that defines the secondary collection name to be co-located with
+ * this collection.
+ */
+ public static final String WITH_COLLECTION_PROPERTY = COLLECTION_PROPERTY_PREFIX + "affinity.withCollection";
+ /**
+ * <p>Name of the system property on a node indicating which (public cloud) Availability Zone that node is in. The value
+ * is any string, different strings denote different availability zones.
+ *
+ * <p>Nodes on which this system property is not defined are considered being in the same Availability Zone
+ * {@link #UNDEFINED_AVAILABILITY_ZONE} (hopefully the value of this constant is not the name of a real Availability Zone :).
+ */
+ public static final String AVAILABILITY_ZONE_SYSPROP = "availability_zone";
+ /**
+ * <p>Name of the system property on a node indicating the type of replicas allowed on that node.
+ * The value of that system property is a comma-separated list or a single string of value names of
+ * {@link org.apache.solr.cluster.Replica.ReplicaType} (case insensitive). If that property is not defined, that node is
+ * considered accepting all replica types (i.e. undefined is equivalent to {@code "NRT,Pull,tlog"}).
+ */
+ public static final String REPLICA_TYPE_SYSPROP = "replica_type";
+ /**
+ * Name of the system property on a node indicating the arbitrary "node type" (for example, a node
+ * more suitable for the indexing work load could be labeled as <code>node_type: indexing</code>).
+ * The value of this system property is a comma-separated list or a single label (labels must not
+ * contain commas), which represent a logical OR for the purpose of placement. Collections may
+ * indicate the required node types using the {@link AffinityPlacementConfig#COLLECTION_NODE_TYPE_PROPERTY},
+ * and replicas will be placed only on the nodes that match one of the types.
+ */
+ public static final String NODE_TYPE_SYSPROP = "node_type";
+ /**
+ * This is the "AZ" name for nodes that do not define an AZ. Should not match a real AZ name (I think we're safe)
+ */
+ public static final String UNDEFINED_AVAILABILITY_ZONE = "uNd3f1NeD";
public static final long DEFAULT_MINIMAL_FREE_DISK_GB = 20L;
public static final long DEFAULT_PRIORITIZED_FREE_DISK_GB = 100L;
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 96ef754..fbcf70e 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
@@ -115,30 +115,6 @@ import java.util.stream.Collectors;
public class AffinityPlacementFactory implements PlacementPluginFactory<AffinityPlacementConfig> {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
- /**
- * <p>Name of the system property on a node indicating which (public cloud) Availability Zone that node is in. The value
- * is any string, different strings denote different availability zones.
- *
- * <p>Nodes on which this system property is not defined are considered being in the same Availability Zone
- * {@link #UNDEFINED_AVAILABILITY_ZONE} (hopefully the value of this constant is not the name of a real Availability Zone :).
- */
- public static final String AVAILABILITY_ZONE_SYSPROP = "availability_zone";
-
- /**
- * <p>Name of the system property on a node indicating the type of replicas allowed on that node.
- * The value of that system property is a comma separated list or a single string of value names of
- * {@link org.apache.solr.cluster.Replica.ReplicaType} (case insensitive). If that property is not defined, that node is
- * considered accepting all replica types (i.e. undefined is equivalent to {@code "NRT,Pull,tlog"}).
- */
- public static final String REPLICA_TYPE_SYSPROP = "replica_type";
-
- public static final String NODE_TYPE_SYSPROP = "node_type";
-
- /**
- * This is the "AZ" name for nodes that do not define an AZ. Should not match a real AZ name (I think we're safe)
- */
- public static final String UNDEFINED_AVAILABILITY_ZONE = "uNd3f1NeD";
-
private AffinityPlacementConfig config = AffinityPlacementConfig.DEFAULT;
/**
@@ -201,9 +177,9 @@ public class AffinityPlacementFactory implements PlacementPluginFactory<Affinity
// Request all needed attributes
AttributeFetcher attributeFetcher = placementContext.getAttributeFetcher();
attributeFetcher
- .requestNodeSystemProperty(AVAILABILITY_ZONE_SYSPROP)
- .requestNodeSystemProperty(NODE_TYPE_SYSPROP)
- .requestNodeSystemProperty(REPLICA_TYPE_SYSPROP);
+ .requestNodeSystemProperty(AffinityPlacementConfig.AVAILABILITY_ZONE_SYSPROP)
+ .requestNodeSystemProperty(AffinityPlacementConfig.NODE_TYPE_SYSPROP)
+ .requestNodeSystemProperty(AffinityPlacementConfig.REPLICA_TYPE_SYSPROP);
attributeFetcher
.requestNodeMetric(NodeMetricImpl.NUM_CORES)
.requestNodeMetric(NodeMetricImpl.FREE_DISK_GB);
@@ -359,13 +335,13 @@ public class AffinityPlacementFactory implements PlacementPluginFactory<Affinity
}
/**
- * Resolves the AZ of a node and takes care of nodes that have no defined AZ in system property {@link #AVAILABILITY_ZONE_SYSPROP}
- * to then return {@link #UNDEFINED_AVAILABILITY_ZONE} as the AZ name.
+ * Resolves the AZ of a node and takes care of nodes that have no defined AZ in system property {@link AffinityPlacementConfig#AVAILABILITY_ZONE_SYSPROP}
+ * to then return {@link AffinityPlacementConfig#UNDEFINED_AVAILABILITY_ZONE} as the AZ name.
*/
private String getNodeAZ(Node n, final AttributeValues attrValues) {
- Optional<String> nodeAz = attrValues.getSystemProperty(n, AVAILABILITY_ZONE_SYSPROP);
+ Optional<String> nodeAz = attrValues.getSystemProperty(n, AffinityPlacementConfig.AVAILABILITY_ZONE_SYSPROP);
// All nodes with undefined AZ will be considered part of the same AZ. This also works for deployments that do not care about AZ's
- return nodeAz.orElse(UNDEFINED_AVAILABILITY_ZONE);
+ return nodeAz.orElse(AffinityPlacementConfig.UNDEFINED_AVAILABILITY_ZONE);
}
/**
@@ -399,7 +375,7 @@ public class AffinityPlacementFactory implements PlacementPluginFactory<Affinity
* as it would not be possible to make any meaningful placement decisions.
*
* @param nodes all nodes on which this plugin should compute placement
- * @param attrValues attributes fetched for the nodes. This method uses system property {@link #REPLICA_TYPE_SYSPROP} as
+ * @param attrValues attributes fetched for the nodes. This method uses system property {@link AffinityPlacementConfig#REPLICA_TYPE_SYSPROP} as
* well as the number of cores on each node.
*/
private Pair<EnumMap<Replica.ReplicaType, Set<Node>>, Map<Node, Integer>> getNodesPerReplicaType(Set<Node> nodes, final AttributeValues attrValues) {
@@ -437,7 +413,7 @@ public class AffinityPlacementFactory implements PlacementPluginFactory<Affinity
Integer coresCount = attrValues.getNodeMetric(node, NodeMetricImpl.NUM_CORES).get();
coresOnNodes.put(node, coresCount);
- String supportedReplicaTypes = attrValues.getSystemProperty(node, REPLICA_TYPE_SYSPROP).isPresent() ? attrValues.getSystemProperty(node, REPLICA_TYPE_SYSPROP).get() : null;
+ String supportedReplicaTypes = attrValues.getSystemProperty(node, AffinityPlacementConfig.REPLICA_TYPE_SYSPROP).isPresent() ? attrValues.getSystemProperty(node, AffinityPlacementConfig.REPLICA_TYPE_SYSPROP).get() : null;
// If property not defined or is only whitespace on a node, assuming node can take any replica type
if (supportedReplicaTypes == null || supportedReplicaTypes.isBlank()) {
for (Replica.ReplicaType rt : Replica.ReplicaType.values()) {
@@ -667,11 +643,11 @@ public class AffinityPlacementFactory implements PlacementPluginFactory<Affinity
Set<String> collNodeTypes = Set.copyOf(StrUtils.splitSmart(collProperty, ','));
Set<Node> filteredNodes = initialNodes.stream()
.filter(n -> {
- Optional<String> nodePropOpt = attributeValues.getSystemProperty(n, AffinityPlacementConfig.COLLECTION_NODE_TYPE_PROPERTY);
+ Optional<String> nodePropOpt = attributeValues.getSystemProperty(n, AffinityPlacementConfig.NODE_TYPE_SYSPROP);
if (!nodePropOpt.isPresent()) {
return false;
}
- Set<String> nodeTypes = Set.copyOf(StrUtils.splitSmart(nodePropOpt.get(), ','));
+ Set<String> nodeTypes = new HashSet<>(StrUtils.splitSmart(nodePropOpt.get(), ','));
nodeTypes.retainAll(collNodeTypes);
return !nodeTypes.isEmpty();
}).collect(Collectors.toSet());
diff --git a/solr/core/src/test/org/apache/solr/cluster/placement/Builders.java b/solr/core/src/test/org/apache/solr/cluster/placement/Builders.java
index 43de56e..d31ba45 100644
--- a/solr/core/src/test/org/apache/solr/cluster/placement/Builders.java
+++ b/solr/core/src/test/org/apache/solr/cluster/placement/Builders.java
@@ -55,6 +55,7 @@ public class Builders {
NodeBuilder nodeBuilder = new NodeBuilder().setNodeName("node_" + n); // Default name, can be changed
nodeBuilder.setTotalDiskGB(10000.0);
nodeBuilder.setFreeDiskGB(5000.0);
+ nodeBuilder.setCoreCount(0);
nodeBuilders.add(nodeBuilder);
}
return this;
diff --git a/solr/core/src/test/org/apache/solr/cluster/placement/plugins/AffinityPlacementFactoryTest.java b/solr/core/src/test/org/apache/solr/cluster/placement/plugins/AffinityPlacementFactoryTest.java
index 877f0d5..b421ea3 100644
--- a/solr/core/src/test/org/apache/solr/cluster/placement/plugins/AffinityPlacementFactoryTest.java
+++ b/solr/core/src/test/org/apache/solr/cluster/placement/plugins/AffinityPlacementFactoryTest.java
@@ -28,6 +28,7 @@ import org.apache.solr.cluster.placement.Builders;
import org.apache.solr.cluster.placement.impl.ModificationRequestImpl;
import org.apache.solr.cluster.placement.impl.PlacementRequestImpl;
import org.apache.solr.common.util.Pair;
+import org.apache.solr.common.util.StrUtils;
import org.junit.BeforeClass;
import org.junit.Test;
import org.slf4j.Logger;
@@ -296,8 +297,8 @@ public class AffinityPlacementFactoryTest extends SolrTestCaseJ4 {
acceptedReplicaType = NRT_REPLICA_TYPE;
}
- nodeBuilders.get(i).setSysprop(AffinityPlacementFactory.AVAILABILITY_ZONE_SYSPROP, az)
- .setSysprop(AffinityPlacementFactory.REPLICA_TYPE_SYSPROP, acceptedReplicaType)
+ nodeBuilders.get(i).setSysprop(AffinityPlacementConfig.AVAILABILITY_ZONE_SYSPROP, az)
+ .setSysprop(AffinityPlacementConfig.REPLICA_TYPE_SYSPROP, acceptedReplicaType)
.setCoreCount(numcores)
.setFreeDiskGB(freedisk);
}
@@ -348,7 +349,7 @@ public class AffinityPlacementFactoryTest extends SolrTestCaseJ4 {
Builders.ClusterBuilder clusterBuilder = Builders.newClusterBuilder().initializeLiveNodes(9);
LinkedList<Builders.NodeBuilder> nodeBuilders = clusterBuilder.getLiveNodeBuilders();
for (int i = 0; i < 9; i++) {
- nodeBuilders.get(i).setSysprop(AffinityPlacementFactory.AVAILABILITY_ZONE_SYSPROP, "AZ" + (i / 3))
+ nodeBuilders.get(i).setSysprop(AffinityPlacementConfig.AVAILABILITY_ZONE_SYSPROP, "AZ" + (i / 3))
.setCoreCount(i)
.setFreeDiskGB((double)(PRIORITIZED_FREE_DISK_GB + 10));
}
@@ -498,9 +499,9 @@ public class AffinityPlacementFactoryTest extends SolrTestCaseJ4 {
nodeBuilder.setCoreCount(0);
nodeBuilder.setFreeDiskGB(100.0);
if (i < NUM_NODES / 2) {
- nodeBuilder.setSysprop(AffinityPlacementFactory.AVAILABILITY_ZONE_SYSPROP, "az1");
+ nodeBuilder.setSysprop(AffinityPlacementConfig.AVAILABILITY_ZONE_SYSPROP, "az1");
} else {
- nodeBuilder.setSysprop(AffinityPlacementFactory.AVAILABILITY_ZONE_SYSPROP, "az2");
+ nodeBuilder.setSysprop(AffinityPlacementConfig.AVAILABILITY_ZONE_SYSPROP, "az2");
}
}
@@ -525,7 +526,7 @@ public class AffinityPlacementFactoryTest extends SolrTestCaseJ4 {
Map<Replica.ReplicaType, Map<String, Map<String, AtomicInteger>>> replicas = new HashMap<>();
AttributeValues attributeValues = placementContext.getAttributeFetcher().fetchAttributes();
for (ReplicaPlacement rp : pp.getReplicaPlacements()) {
- Optional<String> azOptional = attributeValues.getSystemProperty(rp.getNode(), AffinityPlacementFactory.AVAILABILITY_ZONE_SYSPROP);
+ Optional<String> azOptional = attributeValues.getSystemProperty(rp.getNode(), AffinityPlacementConfig.AVAILABILITY_ZONE_SYSPROP);
if (!azOptional.isPresent()) {
fail("missing AZ sysprop for node " + rp.getNode());
}
@@ -555,10 +556,10 @@ public class AffinityPlacementFactoryTest extends SolrTestCaseJ4 {
nodeBuilder.setCoreCount(0);
nodeBuilder.setFreeDiskGB(100.0);
if (i < NUM_NODES / 3 * 2) {
- nodeBuilder.setSysprop(AffinityPlacementFactory.REPLICA_TYPE_SYSPROP, "Nrt, TlOg");
+ nodeBuilder.setSysprop(AffinityPlacementConfig.REPLICA_TYPE_SYSPROP, "Nrt, TlOg");
nodeBuilder.setSysprop("group", "one");
} else {
- nodeBuilder.setSysprop(AffinityPlacementFactory.REPLICA_TYPE_SYSPROP, "Pull,foobar");
+ nodeBuilder.setSysprop(AffinityPlacementConfig.REPLICA_TYPE_SYSPROP, "Pull,foobar");
nodeBuilder.setSysprop("group", "two");
}
}
@@ -743,6 +744,100 @@ public class AffinityPlacementFactoryTest extends SolrTestCaseJ4 {
}
}
+ @Test
+ public void testNodeType() throws Exception {
+ Builders.ClusterBuilder clusterBuilder = Builders.newClusterBuilder().initializeLiveNodes(9);
+ LinkedList<Builders.NodeBuilder> nodeBuilders = clusterBuilder.getLiveNodeBuilders();
+ for (int i = 0; i < 9; i++) {
+ nodeBuilders.get(i).setSysprop(AffinityPlacementConfig.NODE_TYPE_SYSPROP, "type_" + (i % 3));
+ }
+
+ String collectionName = "nodeTypeCollection";
+ Builders.CollectionBuilder collectionBuilder = Builders.newCollectionBuilder(collectionName);
+ collectionBuilder.initializeShardsReplicas(1, 0, 0, 0, clusterBuilder.getLiveNodeBuilders());
+
+ // test single node type in collection
+ collectionBuilder.addCustomProperty(AffinityPlacementConfig.COLLECTION_NODE_TYPE_PROPERTY, "type_0");
+ clusterBuilder.addCollection(collectionBuilder);
+
+ PlacementContext placementContext = clusterBuilder.buildPlacementContext();
+ Map<String, Set<String>> nodeNamesByType = new HashMap<>();
+ Cluster cluster = placementContext.getCluster();
+ AttributeValues attributeValues = placementContext.getAttributeFetcher()
+ .requestNodeSystemProperty(AffinityPlacementConfig.NODE_TYPE_SYSPROP)
+ .fetchAttributes();
+ placementContext.getCluster().getLiveNodes().forEach(n ->
+ nodeNamesByType
+ .computeIfAbsent(attributeValues.getSystemProperty(n, AffinityPlacementConfig.NODE_TYPE_SYSPROP).get(), type -> new HashSet<>())
+ .add(n.getName())
+ );
+ SolrCollection collection = placementContext.getCluster().getCollection(collectionName);
+ PlacementRequestImpl placementRequest = new PlacementRequestImpl(collection,
+ Set.of("shard1"), placementContext.getCluster().getLiveNodes(), 3, 0, 0);
+
+ PlacementPlan pp = plugin.computePlacement(placementRequest, placementContext);
+ assertEquals("expected 3 placements: " + pp, 3, pp.getReplicaPlacements().size());
+ Set<String> type0nodes = nodeNamesByType.get("type_0");
+ Set<String> type1nodes = nodeNamesByType.get("type_1");
+ Set<String> type2nodes = nodeNamesByType.get("type_2");
+
+ for (ReplicaPlacement p : pp.getReplicaPlacements()) {
+ assertTrue(type0nodes.contains(p.getNode().getName()));
+ }
+
+ // test 2 node types in collection
+ collectionBuilder.addCustomProperty(AffinityPlacementConfig.COLLECTION_NODE_TYPE_PROPERTY, "type_0,type_1");
+ placementContext = clusterBuilder.buildPlacementContext();
+ collection = placementContext.getCluster().getCollection(collectionName);
+ placementRequest = new PlacementRequestImpl(collection,
+ Set.of("shard1"), placementContext.getCluster().getLiveNodes(), 6, 0, 0);
+
+ pp = plugin.computePlacement(placementRequest, placementContext);
+ assertEquals("expected 6 placements: " + pp, 6, pp.getReplicaPlacements().size());
+ for (ReplicaPlacement p : pp.getReplicaPlacements()) {
+ assertTrue(type0nodes.contains(p.getNode().getName()) ||
+ type1nodes.contains(p.getNode().getName()));
+ }
+
+ // test 2 node types in nodes
+ for (int i = 0; i < 9; i++) {
+ if (i < 3) {
+ nodeBuilders.get(i).setSysprop(AffinityPlacementConfig.NODE_TYPE_SYSPROP, "type_0,type_1");
+ } else if (i < 6) {
+ nodeBuilders.get(i).setSysprop(AffinityPlacementConfig.NODE_TYPE_SYSPROP, "type_1,type_2");
+ } else {
+ nodeBuilders.get(i).setSysprop(AffinityPlacementConfig.NODE_TYPE_SYSPROP, "type_2");
+ }
+ }
+ collectionBuilder.addCustomProperty(AffinityPlacementConfig.COLLECTION_NODE_TYPE_PROPERTY, "type_0,type_1");
+ placementContext = clusterBuilder.buildPlacementContext();
+ collection = placementContext.getCluster().getCollection(collectionName);
+ placementRequest = new PlacementRequestImpl(collection,
+ Set.of("shard1"), placementContext.getCluster().getLiveNodes(), 6, 0, 0);
+ pp = plugin.computePlacement(placementRequest, placementContext);
+ assertEquals("expected 6 placements: " + pp, 6, pp.getReplicaPlacements().size());
+ nodeNamesByType.clear();
+ AttributeValues attributeValues2 = placementContext.getAttributeFetcher()
+ .requestNodeSystemProperty(AffinityPlacementConfig.NODE_TYPE_SYSPROP)
+ .fetchAttributes();
+ placementContext.getCluster().getLiveNodes().forEach(n -> {
+ String nodeTypesStr = attributeValues2.getSystemProperty(n, AffinityPlacementConfig.NODE_TYPE_SYSPROP).get();
+ for (String nodeType : StrUtils.splitSmart(nodeTypesStr, ',')) {
+ nodeNamesByType
+ .computeIfAbsent(nodeType, type -> new HashSet<>())
+ .add(n.getName());
+ }
+ });
+ type0nodes = nodeNamesByType.get("type_0");
+ type1nodes = nodeNamesByType.get("type_1");
+
+ for (ReplicaPlacement p : pp.getReplicaPlacements()) {
+ assertTrue(type0nodes.contains(p.getNode().getName()) ||
+ type1nodes.contains(p.getNode().getName()));
+ }
+
+ }
+
@Test @Slow
public void testScalability() throws Exception {
log.info("==== numNodes ====");