Apache Solr open-source search software
SOLR-16689: Improving efficiency of replication process (#1442)
Justin Sweeney44c750a29ecc
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 8d0bfaeb853..d885dc3c337 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -185,6 +185,8 @@ Optimizations* SOLR-16487: Replication pooling is optimized based on hard and soft commit settings for a given collection (Justin Sweeney)+* SOLR-16689: Avoiding commits on leader when recovering a non-leader replica and avoiding incorrectly replicating an empty core (Justin Sweeney)+Bug Fixes---------------------diff --git a/solr/core/src/java/org/apache/solr/cloud/RecoveryStrategy.java b/solr/core/src/java/org/apache/solr/cloud/RecoveryStrategy.javaindex 565ce004b99..e24b132cf34 100644--- a/solr/core/src/java/org/apache/solr/cloud/RecoveryStrategy.java+++ b/solr/core/src/java/org/apache/solr/cloud/RecoveryStrategy.java@@ -223,8 +223,10 @@ public class RecoveryStrategy implements Runnable, Closeable {log.info("Attempting to replicate from [{}].", leaderUrl);- // send commit- commitOnLeader(leaderUrl);+ // send commit if replica could be a leader+ if (Replica.Type.isLeaderType(replicaType)) {+ commitOnLeader(leaderUrl);+ }// use rep handler directly, so we can do this sync rather than asyncSolrRequestHandler handler = core.getRequestHandler(ReplicationHandler.PATH);diff --git a/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java b/solr/core/src/java/org/apache/solr/handler/IndexFetcher.javaindex 9d61974e859..099bac7ec35 100644--- a/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java+++ b/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java@@ -546,7 +546,7 @@ public class IndexFetcher {}if (latestVersion == 0L) {- if (commit.getGeneration() != 0) {+ if (IndexDeletionPolicyWrapper.getCommitTimestamp(commit) != 0L) {// since we won't get the files for an empty index,// we just clear ours and commitlog.info("New index in Leader. Deleting mine...");diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/Replica.java b/solr/solrj/src/java/org/apache/solr/common/cloud/Replica.javaindex 83155fa48d1..583c4a4e494 100644--- a/solr/solrj/src/java/org/apache/solr/common/cloud/Replica.java+++ b/solr/solrj/src/java/org/apache/solr/common/cloud/Replica.java@@ -129,6 +129,16 @@ public class Replica extends ZkNodeProps implements MapWriter {public static Type get(String name) {return name == null ? Type.NRT : Type.valueOf(name.toUpperCase(Locale.ROOT));}++ /**+ * Only certain replica types can become leaders+ *+ * @param type the type of a replica+ * @return true if that type is able to be leader, false otherwise+ */+ public static boolean isLeaderType(Type type) {+ return type == null || type == NRT || type == TLOG;+ }}// immutable