From ed8d6bbcd39e4198e19210258dd78177d022bd83 Mon Sep 17 00:00:00 2001 From: kimchy Date: Thu, 19 May 2011 00:36:07 +0300 Subject: [PATCH] fix refresh logic after the change to not do it under write lock --- .../elasticsearch/index/engine/robin/RobinEngine.java | 9 ++++++--- .../index/shard/service/InternalIndexShard.java | 7 +++---- 2 files changed, 9 insertions(+), 7 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 2d873bbc83a..598062eb320 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 @@ -581,7 +581,7 @@ public class RobinEngine extends AbstractIndexShardComponent implements Engine { @Override public Searcher searcher() throws EngineException { AcquirableResource holder; - for (; ;) { + for (; ; ) { holder = this.nrtResource; if (holder.acquire()) { break; @@ -709,8 +709,8 @@ public class RobinEngine extends AbstractIndexShardComponent implements Engine { // we need to refresh in order to clear older version values long time = threadPool.estimatedTimeInMillis(); // mark time here, before we refresh, and then delete all older values refresh(new Refresh(true).force(true)); - if (indexingSearcher.get() != null) { - indexingSearcher.get().release(); + Searcher searcher = indexingSearcher.get(); + if (searcher != null) { indexingSearcher.set(null); } for (Map.Entry entry : versionMap.entrySet()) { @@ -732,6 +732,9 @@ public class RobinEngine extends AbstractIndexShardComponent implements Engine { } } } + if (searcher != null) { + searcher.release(); + } } finally { flushing.set(false); } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/shard/service/InternalIndexShard.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/shard/service/InternalIndexShard.java index d22eee58361..0dad9ed4837 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/shard/service/InternalIndexShard.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/shard/service/InternalIndexShard.java @@ -496,15 +496,14 @@ public class InternalIndexShard extends AbstractIndexShardComponent implements I if (withFlush) { engine.flush(new Engine.Flush()); } + // clear unreferenced files + translog.clearUnreferenced(); + engine.refresh(new Engine.Refresh(true)); synchronized (mutex) { logger.debug("state: [{}]->[{}], reason [post recovery]", state, IndexShardState.STARTED); state = IndexShardState.STARTED; } startScheduledTasksIfNeeded(); - engine.refresh(new Engine.Refresh(true)); - - // clear unreferenced files - translog.clearUnreferenced(); indicesLifecycle.afterIndexShardStarted(this); }