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 b5a62eca901..de13eb10977 100644 --- a/core/src/main/java/org/elasticsearch/index/engine/InternalEngine.java +++ b/core/src/main/java/org/elasticsearch/index/engine/InternalEngine.java @@ -781,9 +781,9 @@ public class InternalEngine extends Engine { // we need to fail the engine. it might have already been failed before // but we are double-checking it's failed and closed if (indexWriter.isOpen() == false && indexWriter.getTragicException() != null) { - failEngine("already closed by tragic event", indexWriter.getTragicException()); + failEngine("already closed by tragic event on the index writer", indexWriter.getTragicException()); } else if (translog.isOpen() == false && translog.getTragicException() != null) { - failEngine("already closed by tragic event", translog.getTragicException()); + failEngine("already closed by tragic event on the translog", translog.getTragicException()); } return true; } else if (t != null && diff --git a/core/src/main/java/org/elasticsearch/index/translog/BufferingTranslogWriter.java b/core/src/main/java/org/elasticsearch/index/translog/BufferingTranslogWriter.java index 97c00ce0a02..a2eb0bff646 100644 --- a/core/src/main/java/org/elasticsearch/index/translog/BufferingTranslogWriter.java +++ b/core/src/main/java/org/elasticsearch/index/translog/BufferingTranslogWriter.java @@ -128,10 +128,10 @@ public final class BufferingTranslogWriter extends TranslogWriter { } // we can do this outside of the write lock but we have to protect from // concurrent syncs + ensureOpen(); // just for kicks - the checkpoint happens or not either way try { - ensureOpen(); // just for kicks - the checkpoint happens or not either way checkpoint(offsetToSync, opsCounter, channelReference); - } catch (IOException ex) { + } catch (Throwable ex) { closeWithTragicEvent(ex); throw ex; } diff --git a/core/src/main/java/org/elasticsearch/index/translog/TranslogWriter.java b/core/src/main/java/org/elasticsearch/index/translog/TranslogWriter.java index d6f21ebb412..9ebe6041581 100644 --- a/core/src/main/java/org/elasticsearch/index/translog/TranslogWriter.java +++ b/core/src/main/java/org/elasticsearch/index/translog/TranslogWriter.java @@ -130,12 +130,10 @@ public class TranslogWriter extends TranslogReader { protected final void closeWithTragicEvent(Throwable throwable) throws IOException { try (ReleasableLock lock = writeLock.acquire()) { - if (throwable != null) { - if (tragedy == null) { - tragedy = throwable; - } else { - tragedy.addSuppressed(throwable); - } + if (tragedy == null) { + tragedy = throwable; + } else { + tragedy.addSuppressed(throwable); } close(); } diff --git a/core/src/test/java/org/elasticsearch/index/translog/TranslogTests.java b/core/src/test/java/org/elasticsearch/index/translog/TranslogTests.java index ad4ac07f6d6..e35c04dcd6b 100644 --- a/core/src/test/java/org/elasticsearch/index/translog/TranslogTests.java +++ b/core/src/test/java/org/elasticsearch/index/translog/TranslogTests.java @@ -1310,7 +1310,7 @@ public class TranslogTests extends ESTestCase { super.write(src); src.position(pos); src.limit(limit); - throw new IOException("no space left on device"); + throw new IOException("__FAKE__ no space left on device"); } } return super.write(src); @@ -1334,7 +1334,7 @@ public class TranslogTests extends ESTestCase { } catch (IOException ex) { failed = true; assertFalse(translog.isOpen()); - assertEquals("no space left on device", ex.getMessage()); + assertEquals("__FAKE__ no space left on device", ex.getMessage()); } simulateDiskFull.set(randomBoolean()); } @@ -1345,7 +1345,7 @@ public class TranslogTests extends ESTestCase { fail("we are already closed"); } catch (AlreadyClosedException ex) { assertNotNull(ex.getCause()); - assertEquals(ex.getCause().getMessage(), "no space left on device"); + assertEquals(ex.getCause().getMessage(), "__FAKE__ no space left on device"); } }