Browse Source

Remove all corruption markers if finalization fails

Simon Willnauer 10 years ago
parent
commit
eaa8576bba

+ 26 - 0
src/main/java/org/elasticsearch/index/store/Store.java

@@ -500,6 +500,32 @@ public class Store extends AbstractIndexShardComponent implements Closeable, Ref
         return false;
     }
 
+    /**
+     * Deletes all corruption markers from this store.
+     */
+    public void removeCorruptionMarker() throws IOException {
+        ensureOpen();
+        final Directory directory = directory();
+        IOException firstException = null;
+        final String[] files = directory.listAll();
+        for (String file : files) {
+            if (file.startsWith(CORRUPTED)) {
+                try {
+                    directory.deleteFile(file);
+                } catch (IOException ex) {
+                    if (firstException == null) {
+                        firstException = ex;
+                    } else {
+                        firstException.addSuppressed(ex);
+                    }
+                }
+            }
+        }
+        if (firstException != null) {
+            throw firstException;
+        }
+    }
+
     public void failIfCorrupted() throws IOException {
         ensureOpen();
         failIfCorrupted(directory, shardId);

+ 5 - 1
src/main/java/org/elasticsearch/indices/recovery/RecoveryTarget.java

@@ -356,7 +356,11 @@ public class RecoveryTarget extends AbstractComponent {
                     // source shard since this index might be broken there as well? The Source can handle this and checks
                     // its content on disk if possible.
                     try {
-                        Lucene.cleanLuceneIndex(store.directory()); // clean up and delete all files
+                        try {
+                            store.removeCorruptionMarker();
+                        } finally {
+                            Lucene.cleanLuceneIndex(store.directory()); // clean up and delete all files
+                        }
                     } catch (Throwable e) {
                         logger.debug("Failed to clean lucene index", e);
                         ex.addSuppressed(e);