From 721f315210ba6538dc468f516961f1ff4afd1b0e Mon Sep 17 00:00:00 2001 From: Shay Banon Date: Fri, 21 Oct 2011 20:18:57 +0200 Subject: [PATCH] handle also illegal state case to see if OOM happened within the index writer --- .../index/engine/robin/RobinEngine.java | 64 +++++++++++++++---- 1 file changed, 52 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 1e6c6e71716..c0fa2217cb3 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 @@ -359,6 +359,11 @@ public class RobinEngine extends AbstractIndexShardComponent implements Engine { } catch (OutOfMemoryError e) { failEngine(e); throw new CreateFailedEngineException(shardId, create, e); + } catch (IllegalStateException e) { + if (e.getMessage().contains("OutOfMemoryError")) { + failEngine(e); + } + throw new CreateFailedEngineException(shardId, create, e); } finally { rwl.readLock().unlock(); } @@ -478,6 +483,11 @@ public class RobinEngine extends AbstractIndexShardComponent implements Engine { } catch (OutOfMemoryError e) { failEngine(e); throw new IndexFailedEngineException(shardId, index, e); + } catch (IllegalStateException e) { + if (e.getMessage().contains("OutOfMemoryError")) { + failEngine(e); + } + throw new IndexFailedEngineException(shardId, index, e); } finally { rwl.readLock().unlock(); } @@ -593,6 +603,11 @@ public class RobinEngine extends AbstractIndexShardComponent implements Engine { } catch (OutOfMemoryError e) { failEngine(e); throw new DeleteFailedEngineException(shardId, delete, e); + } catch (IllegalStateException e) { + if (e.getMessage().contains("OutOfMemoryError")) { + failEngine(e); + } + throw new DeleteFailedEngineException(shardId, delete, e); } finally { rwl.readLock().unlock(); } @@ -757,6 +772,14 @@ public class RobinEngine extends AbstractIndexShardComponent implements Engine { } } catch (AlreadyClosedException e) { // an index writer got replaced on us, ignore + } catch (OutOfMemoryError e) { + failEngine(e); + throw new RefreshFailedEngineException(shardId, e); + } catch (IllegalStateException e) { + if (e.getMessage().contains("OutOfMemoryError")) { + failEngine(e); + } + throw new RefreshFailedEngineException(shardId, e); } catch (Exception e) { if (indexWriter == null) { throw new EngineClosedException(shardId, failedEngine); @@ -765,9 +788,6 @@ public class RobinEngine extends AbstractIndexShardComponent implements Engine { } else { throw new RefreshFailedEngineException(shardId, e); } - } catch (OutOfMemoryError e) { - failEngine(e); - throw new RefreshFailedEngineException(shardId, e); } } finally { rwl.readLock().unlock(); @@ -821,11 +841,16 @@ public class RobinEngine extends AbstractIndexShardComponent implements Engine { current.markForClose(); refreshVersioningTable(threadPool.estimatedTimeInMillis()); - } catch (Exception e) { - throw new FlushFailedEngineException(shardId, e); } catch (OutOfMemoryError e) { failEngine(e); throw new FlushFailedEngineException(shardId, e); + } catch (IllegalStateException e) { + if (e.getMessage().contains("OutOfMemoryError")) { + failEngine(e); + } + throw new FlushFailedEngineException(shardId, e); + } catch (Exception e) { + throw new FlushFailedEngineException(shardId, e); } } finally { rwl.writeLock().unlock(); @@ -866,13 +891,18 @@ public class RobinEngine extends AbstractIndexShardComponent implements Engine { // when tans overrides it translog.makeTransientCurrent(); } - } catch (Exception e) { - translog.revertTransient(); - throw new FlushFailedEngineException(shardId, e); } catch (OutOfMemoryError e) { translog.revertTransient(); failEngine(e); throw new FlushFailedEngineException(shardId, e); + } catch (IllegalStateException e) { + if (e.getMessage().contains("OutOfMemoryError")) { + failEngine(e); + } + throw new FlushFailedEngineException(shardId, e); + } catch (Exception e) { + translog.revertTransient(); + throw new FlushFailedEngineException(shardId, e); } } } finally { @@ -931,11 +961,16 @@ public class RobinEngine extends AbstractIndexShardComponent implements Engine { ((EnableMergePolicy) indexWriter.getConfig().getMergePolicy()).enableMerge(); } indexWriter.maybeMerge(); - } catch (Exception e) { - throw new OptimizeFailedEngineException(shardId, e); } catch (OutOfMemoryError e) { failEngine(e); throw new OptimizeFailedEngineException(shardId, e); + } catch (IllegalStateException e) { + if (e.getMessage().contains("OutOfMemoryError")) { + failEngine(e); + } + throw new OptimizeFailedEngineException(shardId, e); + } catch (Exception e) { + throw new OptimizeFailedEngineException(shardId, e); } finally { rwl.readLock().unlock(); if (indexWriter != null && indexWriter.getConfig().getMergePolicy() instanceof EnableMergePolicy) { @@ -965,11 +1000,16 @@ public class RobinEngine extends AbstractIndexShardComponent implements Engine { } else { indexWriter.optimize(optimize.maxNumSegments(), false); } - } catch (Exception e) { - throw new OptimizeFailedEngineException(shardId, e); } catch (OutOfMemoryError e) { failEngine(e); throw new OptimizeFailedEngineException(shardId, e); + } catch (IllegalStateException e) { + if (e.getMessage().contains("OutOfMemoryError")) { + failEngine(e); + } + throw new OptimizeFailedEngineException(shardId, e); + } catch (Exception e) { + throw new OptimizeFailedEngineException(shardId, e); } finally { rwl.readLock().unlock(); if (indexWriter != null && indexWriter.getConfig().getMergePolicy() instanceof EnableMergePolicy) {