From 7b6c2a0deb280e354d4a93b72ef2eff317995050 Mon Sep 17 00:00:00 2001 From: David Turner Date: Thu, 14 Feb 2019 16:14:18 +0000 Subject: [PATCH] Deal with exceptions when obtaining both retention locks --- .../index/engine/InternalEngine.java | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/index/engine/InternalEngine.java b/server/src/main/java/org/elasticsearch/index/engine/InternalEngine.java index 7df1f03ae2b43..5a75ea5fd2590 100644 --- a/server/src/main/java/org/elasticsearch/index/engine/InternalEngine.java +++ b/server/src/main/java/org/elasticsearch/index/engine/InternalEngine.java @@ -2567,10 +2567,23 @@ public final long getMinRetainedSeqNo() { public Closeable acquireRetentionLock() { if (softDeleteEnabled) { final Closeable softDeletesRetentionLock = softDeletesPolicy.acquireRetentionLock(); - final Closeable translogRetentionLock = translog.acquireRetentionLock(); + final Closeable translogRetentionLock; + try { + translogRetentionLock = translog.acquireRetentionLock(); + } catch (Exception e) { + try { + softDeletesRetentionLock.close(); + } catch (IOException ioexception) { + e.addSuppressed(ioexception); + } + throw e; + } return () -> { - softDeletesRetentionLock.close(); - translogRetentionLock.close(); + try { + translogRetentionLock.close(); + } finally { + softDeletesRetentionLock.close(); + } }; } else { return translog.acquireRetentionLock();