From d7fcca704a5fd27bdc52de8c2c4539f65f8b1e5d Mon Sep 17 00:00:00 2001 From: jimczi Date: Mon, 27 Apr 2020 14:14:49 +0200 Subject: [PATCH] Ignore closed exception on refresh pending location listener This newly added listener should catch closed exceptions when accessing the internal engine. Closes #55792 --- .../java/org/elasticsearch/index/shard/IndexShard.java | 9 +++++++-- .../elasticsearch/xpack/search/AsyncSearchActionIT.java | 2 -- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/index/shard/IndexShard.java b/server/src/main/java/org/elasticsearch/index/shard/IndexShard.java index ce82e146ef5d4..cd9faa8761623 100644 --- a/server/src/main/java/org/elasticsearch/index/shard/IndexShard.java +++ b/server/src/main/java/org/elasticsearch/index/shard/IndexShard.java @@ -3222,12 +3222,17 @@ private class RefreshPendingLocationListener implements ReferenceManager.Refresh @Override public void beforeRefresh() { - lastWriteLocation = getEngine().getTranslogLastWriteLocation(); + try { + lastWriteLocation = getEngine().getTranslogLastWriteLocation(); + } catch (AlreadyClosedException exc) { + // shard is closed - no location is fine + lastWriteLocation = null; + } } @Override public void afterRefresh(boolean didRefresh) { - if (didRefresh) { + if (didRefresh && lastWriteLocation != null) { pendingRefreshLocation.updateAndGet(pendingLocation -> { if (pendingLocation == null || pendingLocation.compareTo(lastWriteLocation) <= 0) { return null; diff --git a/x-pack/plugin/async-search/src/test/java/org/elasticsearch/xpack/search/AsyncSearchActionIT.java b/x-pack/plugin/async-search/src/test/java/org/elasticsearch/xpack/search/AsyncSearchActionIT.java index f4592fd5593d2..2f8a2ad120aa4 100644 --- a/x-pack/plugin/async-search/src/test/java/org/elasticsearch/xpack/search/AsyncSearchActionIT.java +++ b/x-pack/plugin/async-search/src/test/java/org/elasticsearch/xpack/search/AsyncSearchActionIT.java @@ -170,7 +170,6 @@ public void testTermsAggregation() throws Exception { } } - @AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/55792") public void testRestartAfterCompletion() throws Exception { final AsyncSearchResponse initial; try (SearchResponseIterator it = @@ -208,7 +207,6 @@ public void testDeleteCleanupIndex() throws Exception { ensureTaskRemoval(response.getId()); } - @AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/55792") public void testCleanupOnFailure() throws Exception { final AsyncSearchResponse initial; try (SearchResponseIterator it =