From d156aafd1d5cfda2d7b56e4c73c6ddee43d48e91 Mon Sep 17 00:00:00 2001 From: Cao Manh Dat Date: Mon, 27 Mar 2017 16:44:22 +0700 Subject: [PATCH] SOLR-9835: TestInjection.waitForInSyncWithLeader() should rely on commit point of searcher --- .../org/apache/solr/util/TestInjection.java | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) 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 97291a1f6a7..15f5b3d8665 100644 --- a/solr/core/src/java/org/apache/solr/util/TestInjection.java +++ b/solr/core/src/java/org/apache/solr/util/TestInjection.java @@ -28,6 +28,7 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.apache.lucene.search.IndexSearcher; import org.apache.solr.client.solrj.impl.HttpSolrClient; import org.apache.solr.client.solrj.request.QueryRequest; import org.apache.solr.cloud.ZkController; @@ -43,6 +44,7 @@ import org.apache.solr.common.util.SuppressForbidden; import org.apache.solr.core.CoreContainer; import org.apache.solr.core.SolrCore; import org.apache.solr.handler.ReplicationHandler; +import org.apache.solr.search.SolrIndexSearcher; import org.apache.solr.update.SolrIndexWriter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -363,7 +365,8 @@ 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 { if (waitForReplicasInSync == null) return true; - + log.info("Start waiting for replica in sync with leader"); + long currentTime = System.currentTimeMillis(); Pair pair = parseValue(waitForReplicasInSync); boolean enabled = pair.first(); if (!enabled) return true; @@ -380,14 +383,20 @@ public class TestInjection { NamedList response = leaderClient.request(new QueryRequest(params)); long leaderVersion = (long) ((NamedList)response.get("details")).get("indexVersion"); - - String localVersion = core.getDeletionPolicy().getLatestCommit().getUserData().get(SolrIndexWriter.COMMIT_TIME_MSEC_KEY); - if (localVersion == null && leaderVersion == 0 && !core.getUpdateHandler().getUpdateLog().hasUncommittedChanges()) return true; - if (localVersion != null && Long.parseLong(localVersion) == leaderVersion && (leaderVersion >= t || i >= 6)) { - return true; - } else { - Thread.sleep(500); + RefCounted searcher = core.getSearcher(); + try { + String localVersion = searcher.get().getIndexReader().getIndexCommit().getUserData().get(SolrIndexWriter.COMMIT_TIME_MSEC_KEY); + if (localVersion == null && leaderVersion == 0 && !core.getUpdateHandler().getUpdateLog().hasUncommittedChanges()) return true; + if (localVersion != null && Long.parseLong(localVersion) == leaderVersion && (leaderVersion >= t || i >= 6)) { + log.info("Waiting time for replica in sync with leader: {}", System.currentTimeMillis()-currentTime); + return true; + } else { + Thread.sleep(500); + } + } finally { + searcher.decref(); } + } }