Skip to content

Commit b69f698

Browse files
liangkaiwenkliang78HoustonPutman
authored
SOLR-17837: Omit PULL replicas from preferredLeader prop distribution (#3451)
Co-authored-by: kliang78 <kliang78@bloomberg.net> Co-authored-by: Houston Putman <houston@apache.org>
1 parent a9178f5 commit b69f698

4 files changed

Lines changed: 34 additions & 11 deletions

File tree

solr/CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,8 @@ Bug Fixes
265265

266266
* SOLR-17863: Fix race condition in SolrCore's fingerprint cache which caused leader election to hang. (Luke Kot-Zaniewski, Matthew Biscocho)
267267

268+
* SOLR-17837: PULL replica nodes could be marked as "preferredLeader" by BALANCESHARDUNIQUE despite never being able to be elected leader (Kevin Liang via Houston Putman)
269+
268270
Dependency Upgrades
269271
---------------------
270272
(No changes)

solr/core/src/java/org/apache/solr/cloud/ExclusiveSliceProperty.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,12 @@ private boolean collectCurrentPropStats() {
151151
}
152152
continue;
153153
}
154+
// omit replicas that cannot potentially be leader from preferredLeader
155+
// candidates
156+
if (SliceMutator.PREFERRED_LEADER_PROP.equals(property)
157+
&& !replica.getType().leaderEligible) {
158+
continue;
159+
}
154160
allHosts.add(replica.getNodeName());
155161
String nodeName = replica.getNodeName();
156162
if (StrUtils.isNotBlank(replica.getStr(property))) {

solr/core/src/test/org/apache/solr/cloud/api/collections/TestReplicaProperties.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import org.junit.Test;
3737

3838
public class TestReplicaProperties extends ReplicaPropertiesBase {
39-
4039
public static final String COLLECTION_NAME = "testcollection";
4140

4241
public TestReplicaProperties() {
@@ -49,11 +48,11 @@ public TestReplicaProperties() {
4948
public void test() throws Exception {
5049

5150
try (CloudSolrClient client = createCloudClient(null)) {
52-
// Mix up a bunch of different combinations of shards and replicas in order to exercise
53-
// boundary cases. shards, replicationFactor
54-
int shards = random().nextInt(5) + 2;
55-
int replicationFactor = random().nextInt(2) + 2;
56-
createCollection(null, COLLECTION_NAME, shards, replicationFactor, client, null, "conf1");
51+
int shards = 5;
52+
int tlogNodes = 4;
53+
int pullNodes = 4;
54+
Map<String, Object> replicaProps = createReplicaProps(0, tlogNodes, pullNodes, shards);
55+
createCollection(null, COLLECTION_NAME, replicaProps, client, "conf1");
5756
}
5857

5958
waitForCollection(ZkStateReader.from(cloudClient), COLLECTION_NAME, 2);
@@ -249,6 +248,14 @@ private void verifyLeaderAssignment(CloudSolrClient client, String collectionNam
249248
for (Replica replica : slice.getReplicas()) {
250249
boolean isLeader = replica.getBool("leader", false);
251250
boolean isPreferred = replica.getBool("property.preferredleader", false);
251+
if (!replica.getType().leaderEligible && isPreferred) {
252+
lastFailMsg =
253+
"Replica "
254+
+ replica.getName()
255+
+ " of type "
256+
+ replica.getType()
257+
+ ", that cannot be elected leader, should NOT be marked as a preferred leader";
258+
}
252259
if (isLeader != isPreferred) {
253260
lastFailMsg =
254261
"Replica should NOT have preferredLeader != leader. Preferred: "

solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2359,17 +2359,25 @@ public static void waitForNon403or404or503(SolrClient collectionClient, String b
23592359
fail("Could not find the new collection - " + exp.code() + " : " + baseUrl);
23602360
}
23612361

2362+
// for bypassing getPullReplicaCount() - idk why setting pulla replica # should be determined at
2363+
// class level and
2364+
// can cause weird behavior
2365+
protected static Map<String, Object> createReplicaProps(
2366+
int numNrtReplicas, int numTlogReplicas, int numPullReplicas, int numShards) {
2367+
return Map.of(
2368+
ZkStateReader.NRT_REPLICAS, numNrtReplicas,
2369+
ZkStateReader.TLOG_REPLICAS, numTlogReplicas,
2370+
ZkStateReader.PULL_REPLICAS, numPullReplicas,
2371+
CollectionHandlingUtils.NUM_SLICES, numShards);
2372+
}
2373+
23622374
protected void createCollection(
23632375
String collName, CloudSolrClient client, int replicationFactor, int numShards)
23642376
throws Exception {
23652377
int numNrtReplicas = useTlogReplicas() ? 0 : replicationFactor;
23662378
int numTlogReplicas = useTlogReplicas() ? replicationFactor : 0;
23672379
Map<String, Object> props =
2368-
Map.of(
2369-
ZkStateReader.NRT_REPLICAS, numNrtReplicas,
2370-
ZkStateReader.TLOG_REPLICAS, numTlogReplicas,
2371-
ZkStateReader.PULL_REPLICAS, getPullReplicaCount(),
2372-
CollectionHandlingUtils.NUM_SLICES, numShards);
2380+
createReplicaProps(numNrtReplicas, numTlogReplicas, getPullReplicaCount(), numShards);
23732381
Map<String, List<Integer>> collectionInfos = new HashMap<>();
23742382
createCollection(collectionInfos, collName, props, client);
23752383
}

0 commit comments

Comments
 (0)