From 3a33388872da9ca8273dbf5f98e0948eeaf4cf5e Mon Sep 17 00:00:00 2001 From: Michael McCandless Date: Thu, 17 Sep 2015 16:19:03 -0400 Subject: [PATCH] Catch IndexWriter 'files do not exist' assertion and throw EngineCreationFailureExc --- .../elasticsearch/index/engine/InternalEngine.java | 12 ++++++++++-- .../index/engine/InternalEngineTests.java | 5 ----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/index/engine/InternalEngine.java b/core/src/main/java/org/elasticsearch/index/engine/InternalEngine.java index f4a77cfc610..773979dba5a 100644 --- a/core/src/main/java/org/elasticsearch/index/engine/InternalEngine.java +++ b/core/src/main/java/org/elasticsearch/index/engine/InternalEngine.java @@ -21,8 +21,8 @@ package org.elasticsearch.index.engine; import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.IndexReader; -import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriter.IndexReaderWarmer; +import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.index.LeafReader; import org.apache.lucene.index.LeafReaderContext; @@ -45,7 +45,7 @@ import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.IOUtils; import org.apache.lucene.util.InfoStream; import org.elasticsearch.ElasticsearchException; -import org.elasticsearch.action.support.TransportActions; +import org.elasticsearch.ExceptionsHelper; import org.elasticsearch.cluster.routing.DjbHashFunction; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.lease.Releasable; @@ -153,6 +153,14 @@ public class InternalEngine extends Engine { assert translogGeneration != null; } catch (IOException | TranslogCorruptedException e) { throw new EngineCreationFailureException(shardId, "failed to create engine", e); + } catch (AssertionError e) { + // IndexWriter throws AssertionError on init, if asserts are enabled, if any files don't exist, but tests that + // randomly throw FNFE/NSFE can also hit this: + if (ExceptionsHelper.stackTrace(e).contains("org.apache.lucene.index.IndexWriter.filesExist")) { + throw new EngineCreationFailureException(shardId, "failed to create engine", e); + } else { + throw e; + } } this.translog = translog; manager = createSearcherManager(); diff --git a/core/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java b/core/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java index 818e2b08122..3381102a419 100644 --- a/core/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java +++ b/core/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java @@ -41,7 +41,6 @@ import org.apache.lucene.store.MockDirectoryWrapper; import org.apache.lucene.util.IOUtils; import org.apache.lucene.util.TestUtil; import org.elasticsearch.ElasticsearchException; -import org.elasticsearch.ExceptionsHelper; import org.elasticsearch.Version; import org.elasticsearch.action.support.TransportActions; import org.elasticsearch.cluster.metadata.IndexMetaData; @@ -1730,10 +1729,6 @@ public class InternalEngineTests extends ESTestCase { started = true; break; } catch (EngineCreationFailureException ex) { - } catch (AssertionError ex) { - // IndexWriter can throw AssertionError on init (if asserts are enabled) if our directory randomly throws FNFE/NSFE when - // it asserts that all referenced files in the current commit point do exist - assertTrue(ExceptionsHelper.stackTrace(ex).contains("org.apache.lucene.index.IndexWriter.filesExist")); } }