From 47b075017145dffdd875d2007127b37e868497ee Mon Sep 17 00:00:00 2001 From: Shay Banon Date: Tue, 26 Jul 2011 16:39:36 +0300 Subject: [PATCH] improve lock logic when recovering to reduce chance of throwable slipping and causing no release of lock --- .../index/engine/robin/RobinEngine.java | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/engine/robin/RobinEngine.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/engine/robin/RobinEngine.java index 20a137421d2..2631eb02a9d 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/engine/robin/RobinEngine.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/engine/robin/RobinEngine.java @@ -945,10 +945,10 @@ public class RobinEngine extends AbstractIndexShardComponent implements Engine { failEngine(e); throw new OptimizeFailedEngineException(shardId, e); } finally { + rwl.readLock().unlock(); if (indexWriter != null && indexWriter.getConfig().getMergePolicy() instanceof EnableMergePolicy) { ((EnableMergePolicy) indexWriter.getConfig().getMergePolicy()).disableMerge(); } - rwl.readLock().unlock(); optimizeMutex.set(false); } } @@ -1031,18 +1031,9 @@ public class RobinEngine extends AbstractIndexShardComponent implements Engine { } rwl.writeLock().lock(); - Translog.Snapshot phase3Snapshot; + Translog.Snapshot phase3Snapshot = null; try { phase3Snapshot = translog.snapshot(phase2Snapshot); - } catch (Exception e) { - --disableFlushCounter; - rwl.writeLock().unlock(); - phase1Snapshot.release(); - phase2Snapshot.release(); - throw new RecoveryEngineException(shardId, 3, "Snapshot failed", e); - } - - try { recoveryHandler.phase3(phase3Snapshot); } catch (Exception e) { throw new RecoveryEngineException(shardId, 3, "Execution failed", e); @@ -1051,7 +1042,9 @@ public class RobinEngine extends AbstractIndexShardComponent implements Engine { rwl.writeLock().unlock(); phase1Snapshot.release(); phase2Snapshot.release(); - phase3Snapshot.release(); + if (phase3Snapshot != null) { + phase3Snapshot.release(); + } } }