diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/gateway/IndexShardGatewayService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/gateway/IndexShardGatewayService.java index 9d4052e9ebe..2b58ea4e371 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/gateway/IndexShardGatewayService.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/gateway/IndexShardGatewayService.java @@ -270,18 +270,21 @@ public class IndexShardGatewayService extends AbstractIndexShardComponent implem } } - public synchronized void close(boolean delete) { - if (snapshotScheduleFuture != null) { - snapshotScheduleFuture.cancel(true); - snapshotScheduleFuture = null; - } - if (!delete && snapshotOnClose) { + public void snapshotOnClose() { + if (snapshotOnClose) { try { snapshot("shutdown"); } catch (Exception e) { logger.warn("failed to snapshot on close", e); } } + } + + public synchronized void close(boolean delete) { + if (snapshotScheduleFuture != null) { + snapshotScheduleFuture.cancel(true); + snapshotScheduleFuture = null; + } // don't really delete the shard gateway if we are *not* primary, // the primary will close it if (!indexShard.routingEntry().primary()) { diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/service/InternalIndexService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/service/InternalIndexService.java index def23c61566..adaebf0bf82 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/service/InternalIndexService.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/service/InternalIndexService.java @@ -208,7 +208,7 @@ public class InternalIndexService extends AbstractIndexComponent implements Inde threadPool.cached().execute(new Runnable() { @Override public void run() { try { - deleteShard(shardId, delete, delete); + deleteShard(shardId, delete, !delete, delete); } catch (Exception e) { logger.warn("failed to close shard, delete [{}]", e, delete); } finally { @@ -276,10 +276,10 @@ public class InternalIndexService extends AbstractIndexComponent implements Inde } @Override public synchronized void cleanShard(int shardId) throws ElasticSearchException { - deleteShard(shardId, true, false); + deleteShard(shardId, true, false, false); } - private void deleteShard(int shardId, boolean delete, boolean deleteGateway) throws ElasticSearchException { + private void deleteShard(int shardId, boolean delete, boolean snapshotGateway, boolean deleteGateway) throws ElasticSearchException { Injector shardInjector; IndexShard indexShard; synchronized (this) { @@ -335,8 +335,16 @@ public class InternalIndexService extends AbstractIndexComponent implements Inde } catch (Exception e) { // ignore } + try { // now, we can snapshot to the gateway, it will be only the translog + if (snapshotGateway) { + shardInjector.getInstance(IndexShardGatewayService.class).snapshotOnClose(); + } + } catch (Exception e) { + // ignore + } + try { shardInjector.getInstance(IndexShardGatewayService.class).close(deleteGateway); } catch (Exception e) { // ignore