SOLR-14471: Fix last-place replica after shards.preference rules (#1507)

Properly apply base replica ordering to last-place shards.preference matches
This commit is contained in:
Michael Gibney 2020-05-15 00:31:35 -04:00 committed by GitHub
parent 5eea9758c9
commit 54dca800a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 2 deletions

View File

@ -158,7 +158,7 @@ public class RequestReplicaListTransformerGenerator {
Object current;
int idx = 1;
int boundaryCount = 0;
int[] boundaries = new int[choices.size() - 1];
int[] boundaries = new int[choices.size()];
do {
current = iter.next();
if (replicaComp.compare(prev, current) != 0) {
@ -167,6 +167,7 @@ public class RequestReplicaListTransformerGenerator {
prev = current;
idx++;
} while (iter.hasNext());
boundaries[boundaryCount++] = idx;
// Finally inspect boundaries to apply base transformation, where necessary (separate phase to avoid ConcurrentModificationException)
int startIdx = 0;

View File

@ -88,6 +88,19 @@ public class RequestReplicaListTransformerGeneratorTest extends SolrTestCaseJ4 {
)
);
// Add a PULL replica so that there's a tie for "last place"
replicas.add(
new Replica(
"node5",
map(
ZkStateReader.BASE_URL_PROP, "http://host2_2:8983/solr",
ZkStateReader.NODE_NAME_PROP, "node5",
ZkStateReader.CORE_NAME_PROP, "collection1",
ZkStateReader.REPLICA_TYPE, "PULL"
), "c1","s1"
)
);
// replicaType and replicaBase combined rule param
String rulesParam = ShardParams.SHARDS_PREFERENCE_REPLICA_TYPE + ":NRT," +
ShardParams.SHARDS_PREFERENCE_REPLICA_TYPE + ":TLOG," +
@ -101,6 +114,7 @@ public class RequestReplicaListTransformerGeneratorTest extends SolrTestCaseJ4 {
assertEquals("node2", replicas.get(1).getNodeName());
assertEquals("node4", replicas.get(2).getNodeName());
assertEquals("node3", replicas.get(3).getNodeName());
assertEquals("node5", replicas.get(4).getNodeName());
params.set("routingPreference", "1");
rlt = generator.getReplicaListTransformer(params);
@ -108,7 +122,8 @@ public class RequestReplicaListTransformerGeneratorTest extends SolrTestCaseJ4 {
assertEquals("node1", replicas.get(0).getNodeName());
assertEquals("node4", replicas.get(1).getNodeName());
assertEquals("node2", replicas.get(2).getNodeName());
assertEquals("node3", replicas.get(3).getNodeName());
assertEquals("node5", replicas.get(3).getNodeName());
assertEquals("node3", replicas.get(4).getNodeName());
}
@SuppressWarnings("unchecked")