You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by tf...@apache.org on 2018/08/06 23:12:14 UTC

lucene-solr:branch_7x: SOLR-12626: TestInjection.waitForInSyncWithLeader retries in case of errors

Repository: lucene-solr
Updated Branches:
  refs/heads/branch_7x 7519e172c -> d82fc7c3b


SOLR-12626: TestInjection.waitForInSyncWithLeader retries in case of errors

When waiting for follower replicas to be in sync with the leader, TestInjection.waitForInSyncWithLeader
now keeps waiting even if it gets an exception while trying to get leader's replication details. The
method will only exit when it exhausts the number of retries or succeeds.


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/d82fc7c3
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/d82fc7c3
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/d82fc7c3

Branch: refs/heads/branch_7x
Commit: d82fc7c3b5f038f11fac6e00a8eba828d17a4cf1
Parents: 7519e17
Author: Tomas Fernandez Lobbe <tf...@apache.org>
Authored: Mon Aug 6 13:33:53 2018 -0700
Committer: Tomas Fernandez Lobbe <tf...@apache.org>
Committed: Mon Aug 6 16:12:05 2018 -0700

----------------------------------------------------------------------
 .../org/apache/solr/util/TestInjection.java     | 22 ++++++++++++--------
 1 file changed, 13 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d82fc7c3/solr/core/src/java/org/apache/solr/util/TestInjection.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/util/TestInjection.java b/solr/core/src/java/org/apache/solr/util/TestInjection.java
index 34915fb..4642eac 100644
--- a/solr/core/src/java/org/apache/solr/util/TestInjection.java
+++ b/solr/core/src/java/org/apache/solr/util/TestInjection.java
@@ -414,7 +414,7 @@ public class TestInjection {
   }
 
   @SuppressForbidden(reason = "Need currentTimeMillis, because COMMIT_TIME_MSEC_KEY use currentTimeMillis as value")
-  public static boolean waitForInSyncWithLeader(SolrCore core, ZkController zkController, String collection, String shardId) throws InterruptedException {
+  public static boolean waitForInSyncWithLeader(SolrCore core, ZkController zkController, String collection, String shardId) {
     if (waitForReplicasInSync == null) return true;
     log.info("Start waiting for replica in sync with leader");
     long currentTime = System.currentTimeMillis();
@@ -422,8 +422,8 @@ public class TestInjection {
     boolean enabled = pair.first();
     if (!enabled) return true;
     long t = System.currentTimeMillis() - 200;
-    try {
-      for (int i = 0; i < pair.second(); i++) {
+    for (int i = 0; i < pair.second(); i++) {
+      try {
         if (core.isClosed()) return true;
         Replica leaderReplica = zkController.getZkStateReader().getLeaderRetry(
             collection, shardId);
@@ -431,7 +431,7 @@ public class TestInjection {
           ModifiableSolrParams params = new ModifiableSolrParams();
           params.set(CommonParams.QT, ReplicationHandler.PATH);
           params.set(COMMAND, CMD_DETAILS);
-
+  
           NamedList<Object> response = leaderClient.request(new QueryRequest(params));
           long leaderVersion = (long) ((NamedList)response.get("details")).get("indexVersion");
           String localVersion = core.withSearcher(searcher ->
@@ -445,14 +445,18 @@ public class TestInjection {
             log.debug("Tlog replica not in sync with leader yet. Attempt: {}. Local Version={}, leader Version={}", i, localVersion, leaderVersion);
             Thread.sleep(500);
           }
-
+  
         }
+      } catch (InterruptedException e) {
+        Thread.currentThread().interrupt();
+        if (core.isClosed()) return true;
+        log.error("Thread interrupted while waiting for core {} to be in sync with leader", core.getName());
+        return false;
+      } catch (Exception e) {
+        if (core.isClosed()) return true;
+        log.error("Exception when wait for replicas in sync with master. Will retry until timeout.", e);
       }
-
-    } catch (Exception e) {
-      log.error("Exception when wait for replicas in sync with master");
     }
-
     return false;
   }