From 2288d44eebc76c87f2aef4072b4b3cebf6a5bba8 Mon Sep 17 00:00:00 2001 From: Britta Weber Date: Tue, 8 Sep 2015 14:23:34 +0200 Subject: [PATCH] Engine: Let AlreadyClosedException and EngineClosedException bubble up Whe we call optimize we ignore Exceptions that indicate a closed shard. However, when a shard is closed while an optimize request is in flight it might also trigger an AlreadyClosedException from the IndexWriter when we get the config or ForceMergeFailedEngineException with the EngineClosedException wrapped inside. Because these are not identified as exceptions that indicate a closed shard (TransportActions.isShardNotAvailableException(..)) optimize would sometimes report failures when shards were relocating while optimize was called and sometimes not. This caused weird test failures, see #13266 . Instead, we should let EngineClosedException bubble up and also recognize AlreadyClosedException as an indicator for a closed shard. --- .../elasticsearch/ElasticsearchException.java | 1 - .../optimize/TransportOptimizeAction.java | 2 +- .../upgrade/post/TransportUpgradeAction.java | 2 +- .../action/support/TransportActions.java | 4 +- .../node/TransportBroadcastByNodeAction.java | 2 +- .../elasticsearch/index/engine/Engine.java | 4 +- .../ForceMergeFailedEngineException.java | 39 ----------------- .../index/engine/InternalEngine.java | 8 ++-- .../elasticsearch/index/shard/IndexShard.java | 4 +- .../index/engine/InternalEngineTests.java | 43 ++++++++++++++++++- 10 files changed, 55 insertions(+), 54 deletions(-) delete mode 100644 core/src/main/java/org/elasticsearch/index/engine/ForceMergeFailedEngineException.java diff --git a/core/src/main/java/org/elasticsearch/ElasticsearchException.java b/core/src/main/java/org/elasticsearch/ElasticsearchException.java index 4f478057fa0..a9b0ba58e09 100644 --- a/core/src/main/java/org/elasticsearch/ElasticsearchException.java +++ b/core/src/main/java/org/elasticsearch/ElasticsearchException.java @@ -583,7 +583,6 @@ public class ElasticsearchException extends RuntimeException implements ToXConte org.elasticsearch.index.query.QueryParsingException.class, org.elasticsearch.action.support.replication.TransportReplicationAction.RetryOnPrimaryException.class, org.elasticsearch.index.engine.DeleteByQueryFailedEngineException.class, - org.elasticsearch.index.engine.ForceMergeFailedEngineException.class, org.elasticsearch.discovery.MasterNotDiscoveredException.class, org.elasticsearch.action.support.broadcast.BroadcastShardOperationFailedException.class, org.elasticsearch.node.NodeClosedException.class, diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/optimize/TransportOptimizeAction.java b/core/src/main/java/org/elasticsearch/action/admin/indices/optimize/TransportOptimizeAction.java index 549ce8fd57b..846612dae47 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/optimize/TransportOptimizeAction.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/optimize/TransportOptimizeAction.java @@ -74,7 +74,7 @@ public class TransportOptimizeAction extends TransportBroadcastByNodeAction throwable = new AtomicReference<>(); + String operation = randomFrom("optimize", "refresh", "flush"); + Thread mergeThread = new Thread() { + @Override + public void run() { + boolean stop = false; + logger.info("try with {}", operation); + while (stop == false) { + try { + switch (operation) { + case "optimize": { + engine.forceMerge(true, 1, false, false, false); + break; + } + case "refresh": { + engine.refresh("test refresh"); + break; + } + case "flush": { + engine.flush(true, false); + break; + } + } + } catch (Throwable t) { + throwable.set(t); + stop = true; + } + } + } + }; + mergeThread.start(); + engine.close(); + mergeThread.join(); + logger.info("exception caught: ", throwable.get()); + assertTrue("expected an Exception that signals shard is not available", TransportActions.isShardNotAvailableException(throwable.get())); + } }