From d96faa4a3a57b1dcd40d5658bf491e63f8ba4764 Mon Sep 17 00:00:00 2001 From: Yonik Seeley Date: Mon, 1 Jul 2013 16:33:55 +0000 Subject: [PATCH] SOLR-4926: SolrDeletionPolicy.getLatestCommit can be null before IW is used git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1498554 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/solr/handler/SnapPuller.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/solr/core/src/java/org/apache/solr/handler/SnapPuller.java b/solr/core/src/java/org/apache/solr/handler/SnapPuller.java index be83de94eab..2a31d2b9000 100644 --- a/solr/core/src/java/org/apache/solr/handler/SnapPuller.java +++ b/solr/core/src/java/org/apache/solr/handler/SnapPuller.java @@ -318,8 +318,25 @@ public class SnapPuller { long latestVersion = (Long) response.get(CMD_INDEX_VERSION); long latestGeneration = (Long) response.get(GENERATION); + // TODO: make sure that getLatestCommit only returns commit points for the main index (i.e. no side-car indexes) IndexCommit commit = core.getDeletionPolicy().getLatestCommit(); - + if (commit == null) { + // Presumably the IndexWriter hasn't been opened yet, and hence the deletion policy hasn't been updated with commit points + RefCounted searcherRefCounted = null; + try { + searcherRefCounted = core.getNewestSearcher(false); + if (searcherRefCounted == null) { + LOG.warn("No open searcher found - fetch aborted"); + return false; + } + commit = searcherRefCounted.get().getIndexReader().getIndexCommit(); + } finally { + if (searcherRefCounted != null) + searcherRefCounted.decref(); + } + } + + if (latestVersion == 0L) { if (forceReplication && commit.getGeneration() != 0) { // since we won't get the files for an empty index,