This is an automated email from the ASF dual-hosted git repository. jsweeney pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/solr.git
The following commit(s) were added to refs/heads/main by this push: new 44c750a29ec SOLR-16689: Improving efficiency of replication process (#1442) 44c750a29ec is described below commit 44c750a29ecc4ac81562e1e6df501bcbc5ffe39f Author: Justin Sweeney <justinswee...@fullstory.com> AuthorDate: Mon Mar 13 09:17:34 2023 -0600 SOLR-16689: Improving efficiency of replication process (#1442) Improving efficiency of replication process by avoiding repeated attempts to replicate empty index and avoiding commit call to leader when replicating to a non-leader replica --- solr/CHANGES.txt | 2 ++ solr/core/src/java/org/apache/solr/cloud/RecoveryStrategy.java | 6 ++++-- solr/core/src/java/org/apache/solr/handler/IndexFetcher.java | 2 +- solr/solrj/src/java/org/apache/solr/common/cloud/Replica.java | 10 ++++++++++ 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 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.java index 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 async SolrRequestHandler 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.java index 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 commit log.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.java index 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