From f7d633a56e99736d9cc51d807c6e745ec63380ab Mon Sep 17 00:00:00 2001 From: Varun Thacker Date: Sun, 5 Apr 2015 14:59:02 +0000 Subject: [PATCH] SOLR-6637: Better error handling when retrieving checksums (Fixes Policeman Jenkins Failure #2134) git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1671400 13f79535-47bb-0310-9956-ffa450edef68 --- .../src/java/org/apache/solr/handler/RestoreCore.java | 10 ++++++++-- .../src/java/org/apache/solr/handler/SnapShooter.java | 5 +++-- .../test/org/apache/solr/handler/TestRestoreCore.java | 6 ++++-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/solr/core/src/java/org/apache/solr/handler/RestoreCore.java b/solr/core/src/java/org/apache/solr/handler/RestoreCore.java index 0d86ca57f89..25ff24ee5d1 100644 --- a/solr/core/src/java/org/apache/solr/handler/RestoreCore.java +++ b/solr/core/src/java/org/apache/solr/handler/RestoreCore.java @@ -17,6 +17,7 @@ package org.apache.solr.handler; * limitations under the License. */ +import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; import java.util.concurrent.Callable; @@ -72,9 +73,14 @@ public class RestoreCore implements Callable { //Move all files from backupDir to restoreIndexDir for (String filename : backupDir.listAll()) { checkInterrupted(); - log.info("Copying over file to restore directory " + filename); + log.info("Copying file {} to restore directory ", filename); try (IndexInput indexInput = backupDir.openInput(filename, IOContext.READONCE)) { - long checksum = CodecUtil.retrieveChecksum(indexInput); + Long checksum = null; + try { + checksum = CodecUtil.retrieveChecksum(indexInput); + } catch (Exception e) { + log.warn("Could not read checksum from index file: " + filename, e); + } long length = indexInput.length(); IndexFetcher.CompareResult compareResult = IndexFetcher.compareFile(indexDir, filename, length, checksum); if (!compareResult.equal || (!compareResult.checkSummed && (filename.endsWith(".si") diff --git a/solr/core/src/java/org/apache/solr/handler/SnapShooter.java b/solr/core/src/java/org/apache/solr/handler/SnapShooter.java index e6cb1ac1703..ffdafa5b310 100644 --- a/solr/core/src/java/org/apache/solr/handler/SnapShooter.java +++ b/solr/core/src/java/org/apache/solr/handler/SnapShooter.java @@ -127,7 +127,7 @@ public class SnapShooter { } void createSnapshot(final IndexCommit indexCommit, ReplicationHandler replicationHandler) { - LOG.info("Creating backup snapshot " + (snapshotName == null ? "" : snapshotName)); + LOG.info("Creating backup snapshot " + (snapshotName == null ? "" : snapshotName) + " at " + snapDir); NamedList details = new NamedList<>(); details.add("startTime", new Date().toString()); try { @@ -144,7 +144,8 @@ public class SnapShooter { details.add("status", "success"); details.add("snapshotCompletedAt", new Date().toString()); details.add("snapshotName", snapshotName); - LOG.info("Done creating backup snapshot: " + (snapshotName == null ? "" : snapshotName)); + LOG.info("Done creating backup snapshot: " + (snapshotName == null ? "" : snapshotName) + + " at " + snapDir); } catch (Exception e) { IndexFetcher.delTree(snapShotDir); LOG.error("Exception while creating snapshot", e); diff --git a/solr/core/src/test/org/apache/solr/handler/TestRestoreCore.java b/solr/core/src/test/org/apache/solr/handler/TestRestoreCore.java index bdedc7c6331..e5d7adaa236 100644 --- a/solr/core/src/test/org/apache/solr/handler/TestRestoreCore.java +++ b/solr/core/src/test/org/apache/solr/handler/TestRestoreCore.java @@ -26,6 +26,7 @@ import java.net.URLEncoder; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.regex.Matcher; import java.util.regex.Pattern; import org.apache.commons.io.IOUtils; @@ -226,8 +227,9 @@ public class TestRestoreCore extends SolrJettyTestBase { URL url = new URL(masterUrl); stream = url.openStream(); String response = IOUtils.toString(stream, "UTF-8"); - if(pException.matcher(response).find()) { - fail("Failed to complete restore action"); + Matcher matcher = pException.matcher(response); + if(matcher.find()) { + fail("Failed to complete restore action with exception " + matcher.group(1)); } if(response.contains("success")) { return true;