Browse Source

Catch AlreadClosedException in RobinSearcher#release()

When we relocate a shard we might still have pending SearchContext
instances hanging around that will be used in "in-flight" searches
on the already relocated shard. This is a valid operation but if
we have already closed the underlying directory which happens during
cleanup concurrently the close call on the IndexReader can trigger
an AlreadyClosedException when the NRT reader tries to cleanup files
via the IndexWriter.

Closes #4273
Simon Willnauer 12 years ago
parent
commit
71eb4532f8

+ 5 - 0
src/main/java/org/elasticsearch/index/engine/robin/RobinEngine.java

@@ -1499,6 +1499,11 @@ public class RobinEngine extends AbstractIndexShardComponent implements Engine {
                 return true;
             } catch (IOException e) {
                 return false;
+            } catch (AlreadyClosedException e) {
+                /* this one can happen if we already closed the
+                 * underlying store / directory and we call into the
+                 * IndexWriter to free up pending files. */
+                return false;
             }
         }
     }

+ 1 - 5
src/main/java/org/elasticsearch/search/SearchService.java

@@ -433,11 +433,7 @@ public class SearchService extends AbstractLifecycleComponent<SearchService> {
         } catch (Throwable e) {
             context.indexShard().searchService().onFailedFetchPhase(context);
             logger.trace("Fetch phase failed", e);
-            try {
-                freeContext(context); // we just try to make sure this is freed - rethrow orig exception.
-            } catch(Throwable t) {
-                logger.trace("Could not free context", t);
-            }
+            freeContext(context); // we just try to make sure this is freed - rethrow orig exception.
             throw ExceptionsHelper.convertToRuntime(e);
         } finally {
             cleanContext(context);

+ 1 - 2
src/test/java/org/elasticsearch/search/basic/SearchWhileRelocatingTests.java

@@ -57,8 +57,7 @@ public class SearchWhileRelocatingTests extends ElasticsearchIntegrationTest {
     private void testSearchAndRelocateConcurrently(int numberOfReplicas) throws Exception {
         final int numShards = between(10, 20);
         client().admin().indices().prepareCreate("test")
-                .setSettings(settingsBuilder().put("index.number_of_shards", numShards).put("index.number_of_replicas", numberOfReplicas)
-                .put("index.store.type", "niofs"))
+                .setSettings(settingsBuilder().put("index.number_of_shards", numShards).put("index.number_of_replicas", numberOfReplicas))
                 .addMapping("type1", "loc", "type=geo_point", "test", "type=string").execute().actionGet();
         ensureGreen();
         List<IndexRequestBuilder> indexBuilders = new ArrayList<IndexRequestBuilder>();