From 3e264f6b95c6356c43adc2ec2053a612ffbfce80 Mon Sep 17 00:00:00 2001 From: Shay Banon Date: Mon, 4 Mar 2013 20:41:19 -0800 Subject: [PATCH] cleanup deletion of content in shards we are very conservative on when we delete data, remove the actual options of deleting data that are not used --- .../metadata/MetaDataCreateIndexService.java | 2 +- .../metadata/MetaDataIndexAliasesService.java | 2 +- .../metadata/MetaDataMappingService.java | 6 +- .../index/CloseableIndexComponent.java | 5 +- .../gateway/IndexShardGatewayService.java | 10 +--- .../blobstore/BlobStoreIndexGateway.java | 5 +- .../blobstore/BlobStoreIndexShardGateway.java | 5 +- .../gateway/local/LocalIndexGateway.java | 2 +- .../gateway/local/LocalIndexShardGateway.java | 11 ++-- .../index/gateway/none/NoneIndexGateway.java | 2 +- .../gateway/none/NoneIndexShardGateway.java | 3 +- .../LogByteSizeMergePolicyProvider.java | 2 +- .../policy/LogDocMergePolicyProvider.java | 2 +- .../policy/TieredMergePolicyProvider.java | 2 +- .../index/service/IndexService.java | 5 -- .../index/service/InternalIndexService.java | 60 +++++-------------- .../org/elasticsearch/index/store/Store.java | 21 +++---- .../store/support/AbstractIndexStore.java | 2 +- .../index/translog/Translog.java | 12 ++-- .../index/translog/fs/FsTranslog.java | 12 +++- .../indices/IndicesLifecycle.java | 14 ++--- .../elasticsearch/indices/IndicesService.java | 7 +-- .../indices/InternalIndicesLifecycle.java | 16 ++--- .../indices/InternalIndicesService.java | 40 ++++--------- .../cluster/IndicesClusterStateService.java | 6 +- .../memory/IndexingMemoryController.java | 2 +- .../indices/recovery/RecoveryTarget.java | 2 +- .../elasticsearch/search/SearchService.java | 4 +- .../translog/AbstractSimpleTranslogTests.java | 2 +- 29 files changed, 100 insertions(+), 164 deletions(-) diff --git a/src/main/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexService.java b/src/main/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexService.java index d82f8df7447..24823258352 100644 --- a/src/main/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexService.java +++ b/src/main/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexService.java @@ -365,7 +365,7 @@ public class MetaDataCreateIndexService extends AbstractComponent { logger.warn("[{}] failed to create", e, request.index); if (indexCreated) { // Index was already partially created - need to clean up - indicesService.deleteIndex(request.index, failureReason != null ? failureReason : "failed to create index"); + indicesService.removeIndex(request.index, failureReason != null ? failureReason : "failed to create index"); } listener.onFailure(e); return currentState; diff --git a/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexAliasesService.java b/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexAliasesService.java index 7f39522770f..fe92351d77b 100644 --- a/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexAliasesService.java +++ b/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexAliasesService.java @@ -180,7 +180,7 @@ public class MetaDataIndexAliasesService extends AbstractComponent { } } finally { for (String index : indicesToClose) { - indicesService.cleanIndex(index, "created for alias processing"); + indicesService.removeIndex(index, "created for alias processing"); } } } diff --git a/src/main/java/org/elasticsearch/cluster/metadata/MetaDataMappingService.java b/src/main/java/org/elasticsearch/cluster/metadata/MetaDataMappingService.java index 15461305504..9d76533bdda 100644 --- a/src/main/java/org/elasticsearch/cluster/metadata/MetaDataMappingService.java +++ b/src/main/java/org/elasticsearch/cluster/metadata/MetaDataMappingService.java @@ -148,7 +148,7 @@ public class MetaDataMappingService extends AbstractComponent { return currentState; } finally { if (createdIndex) { - indicesService.cleanIndex(index, "created for mapping processing"); + indicesService.removeIndex(index, "created for mapping processing"); } } } @@ -209,7 +209,7 @@ public class MetaDataMappingService extends AbstractComponent { return currentState; } finally { if (createdIndex) { - indicesService.cleanIndex(index, "created for mapping processing"); + indicesService.removeIndex(index, "created for mapping processing"); } } } @@ -409,7 +409,7 @@ public class MetaDataMappingService extends AbstractComponent { return currentState; } finally { for (String index : indicesToClose) { - indicesService.cleanIndex(index, "created for mapping processing"); + indicesService.removeIndex(index, "created for mapping processing"); } } } diff --git a/src/main/java/org/elasticsearch/index/CloseableIndexComponent.java b/src/main/java/org/elasticsearch/index/CloseableIndexComponent.java index 07daa651248..bae9a0b89b2 100644 --- a/src/main/java/org/elasticsearch/index/CloseableIndexComponent.java +++ b/src/main/java/org/elasticsearch/index/CloseableIndexComponent.java @@ -29,9 +29,6 @@ public interface CloseableIndexComponent { /** * Closes the index component. A boolean indicating if its part of an actual index * deletion or not is passed. - * - * @param delete true if the index is being deleted. - * @throws ElasticSearchException */ - void close(boolean delete) throws ElasticSearchException; + void close() throws ElasticSearchException; } \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/index/gateway/IndexShardGatewayService.java b/src/main/java/org/elasticsearch/index/gateway/IndexShardGatewayService.java index cccb28c1536..89f72dbcc4e 100644 --- a/src/main/java/org/elasticsearch/index/gateway/IndexShardGatewayService.java +++ b/src/main/java/org/elasticsearch/index/gateway/IndexShardGatewayService.java @@ -311,18 +311,14 @@ public class IndexShardGatewayService extends AbstractIndexShardComponent implem } } - public synchronized void close(boolean delete) { + @Override + public synchronized void close() { indexSettingsService.removeListener(applySettings); 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()) { - delete = false; - } - shardGateway.close(delete); + shardGateway.close(); if (snapshotLock != null) { snapshotLock.release(); } diff --git a/src/main/java/org/elasticsearch/index/gateway/blobstore/BlobStoreIndexGateway.java b/src/main/java/org/elasticsearch/index/gateway/blobstore/BlobStoreIndexGateway.java index ef5615884a8..11445c8888e 100644 --- a/src/main/java/org/elasticsearch/index/gateway/blobstore/BlobStoreIndexGateway.java +++ b/src/main/java/org/elasticsearch/index/gateway/blobstore/BlobStoreIndexGateway.java @@ -82,9 +82,6 @@ public abstract class BlobStoreIndexGateway extends AbstractIndexComponent imple } @Override - public void close(boolean delete) throws ElasticSearchException { - if (delete) { - blobStore.delete(indexPath); - } + public void close() throws ElasticSearchException { } } diff --git a/src/main/java/org/elasticsearch/index/gateway/blobstore/BlobStoreIndexShardGateway.java b/src/main/java/org/elasticsearch/index/gateway/blobstore/BlobStoreIndexShardGateway.java index e518c622fe7..67eb06ff70c 100644 --- a/src/main/java/org/elasticsearch/index/gateway/blobstore/BlobStoreIndexShardGateway.java +++ b/src/main/java/org/elasticsearch/index/gateway/blobstore/BlobStoreIndexShardGateway.java @@ -130,10 +130,7 @@ public abstract class BlobStoreIndexShardGateway extends AbstractIndexShardCompo } @Override - public void close(boolean delete) throws ElasticSearchException { - if (delete) { - blobStore.delete(shardPath); - } + public void close() throws ElasticSearchException { } @Override diff --git a/src/main/java/org/elasticsearch/index/gateway/local/LocalIndexGateway.java b/src/main/java/org/elasticsearch/index/gateway/local/LocalIndexGateway.java index f911c331683..be30de35a69 100644 --- a/src/main/java/org/elasticsearch/index/gateway/local/LocalIndexGateway.java +++ b/src/main/java/org/elasticsearch/index/gateway/local/LocalIndexGateway.java @@ -53,6 +53,6 @@ public class LocalIndexGateway extends AbstractIndexComponent implements IndexGa } @Override - public void close(boolean delete) { + public void close() { } } diff --git a/src/main/java/org/elasticsearch/index/gateway/local/LocalIndexShardGateway.java b/src/main/java/org/elasticsearch/index/gateway/local/LocalIndexShardGateway.java index 0313e009c1c..2f50646fe54 100644 --- a/src/main/java/org/elasticsearch/index/gateway/local/LocalIndexShardGateway.java +++ b/src/main/java/org/elasticsearch/index/gateway/local/LocalIndexShardGateway.java @@ -19,7 +19,6 @@ package org.elasticsearch.index.gateway.local; -import com.google.common.io.Closeables; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.index.SegmentInfos; @@ -234,10 +233,14 @@ public class LocalIndexShardGateway extends AbstractIndexShardComponent implemen } } catch (Throwable e) { // we failed to recovery, make sure to delete the translog file (and keep the recovering one) - indexShard.translog().close(true); + indexShard.translog().closeWithDelete(); throw new IndexShardGatewayRecoveryException(shardId, "failed to recover shard", e); } finally { - Closeables.closeQuietly(fs); + try { + fs.close(); + } catch (IOException e) { + // ignore + } } indexShard.performRecoveryFinalization(true); @@ -277,7 +280,7 @@ public class LocalIndexShardGateway extends AbstractIndexShardComponent implemen } @Override - public void close(boolean delete) { + public void close() { if (flushScheduler != null) { flushScheduler.cancel(false); } diff --git a/src/main/java/org/elasticsearch/index/gateway/none/NoneIndexGateway.java b/src/main/java/org/elasticsearch/index/gateway/none/NoneIndexGateway.java index 2aea4d54f2b..e8b1b9eb1b5 100644 --- a/src/main/java/org/elasticsearch/index/gateway/none/NoneIndexGateway.java +++ b/src/main/java/org/elasticsearch/index/gateway/none/NoneIndexGateway.java @@ -53,6 +53,6 @@ public class NoneIndexGateway extends AbstractIndexComponent implements IndexGat } @Override - public void close(boolean delete) { + public void close() { } } diff --git a/src/main/java/org/elasticsearch/index/gateway/none/NoneIndexShardGateway.java b/src/main/java/org/elasticsearch/index/gateway/none/NoneIndexShardGateway.java index 8af45314751..12879b35162 100644 --- a/src/main/java/org/elasticsearch/index/gateway/none/NoneIndexShardGateway.java +++ b/src/main/java/org/elasticsearch/index/gateway/none/NoneIndexShardGateway.java @@ -65,6 +65,7 @@ public class NoneIndexShardGateway extends AbstractIndexShardComponent implement // in the none case, we simply start the shard // clean the store, there should be nothing there... try { + logger.info("deleting shard content"); indexShard.store().deleteContent(); } catch (IOException e) { logger.warn("failed to clean store before starting shard", e); @@ -106,7 +107,7 @@ public class NoneIndexShardGateway extends AbstractIndexShardComponent implement } @Override - public void close(boolean delete) { + public void close() { } @Override diff --git a/src/main/java/org/elasticsearch/index/merge/policy/LogByteSizeMergePolicyProvider.java b/src/main/java/org/elasticsearch/index/merge/policy/LogByteSizeMergePolicyProvider.java index 9d99a09fd24..ed3246a963e 100644 --- a/src/main/java/org/elasticsearch/index/merge/policy/LogByteSizeMergePolicyProvider.java +++ b/src/main/java/org/elasticsearch/index/merge/policy/LogByteSizeMergePolicyProvider.java @@ -93,7 +93,7 @@ public class LogByteSizeMergePolicyProvider extends AbstractIndexShardComponent } @Override - public void close(boolean delete) throws ElasticSearchException { + public void close() throws ElasticSearchException { indexSettingsService.removeListener(applySettings); } diff --git a/src/main/java/org/elasticsearch/index/merge/policy/LogDocMergePolicyProvider.java b/src/main/java/org/elasticsearch/index/merge/policy/LogDocMergePolicyProvider.java index 5415f818cfa..c3877314188 100644 --- a/src/main/java/org/elasticsearch/index/merge/policy/LogDocMergePolicyProvider.java +++ b/src/main/java/org/elasticsearch/index/merge/policy/LogDocMergePolicyProvider.java @@ -70,7 +70,7 @@ public class LogDocMergePolicyProvider extends AbstractIndexShardComponent imple } @Override - public void close(boolean delete) throws ElasticSearchException { + public void close() throws ElasticSearchException { indexSettingsService.removeListener(applySettings); } diff --git a/src/main/java/org/elasticsearch/index/merge/policy/TieredMergePolicyProvider.java b/src/main/java/org/elasticsearch/index/merge/policy/TieredMergePolicyProvider.java index ec2c711f957..a5d22339bea 100644 --- a/src/main/java/org/elasticsearch/index/merge/policy/TieredMergePolicyProvider.java +++ b/src/main/java/org/elasticsearch/index/merge/policy/TieredMergePolicyProvider.java @@ -111,7 +111,7 @@ public class TieredMergePolicyProvider extends AbstractIndexShardComponent imple } @Override - public void close(boolean delete) throws ElasticSearchException { + public void close() throws ElasticSearchException { indexSettingsService.removeListener(applySettings); } diff --git a/src/main/java/org/elasticsearch/index/service/IndexService.java b/src/main/java/org/elasticsearch/index/service/IndexService.java index de71977ba6c..bcd87881aae 100644 --- a/src/main/java/org/elasticsearch/index/service/IndexService.java +++ b/src/main/java/org/elasticsearch/index/service/IndexService.java @@ -71,11 +71,6 @@ public interface IndexService extends IndexComponent, Iterable { IndexShard createShard(int sShardId) throws ElasticSearchException; - /** - * Cleans the shard locally, does not touch the gateway!. - */ - void cleanShard(int shardId, String reason) throws ElasticSearchException; - /** * Removes the shard, does not delete local data or the gateway. */ diff --git a/src/main/java/org/elasticsearch/index/service/InternalIndexService.java b/src/main/java/org/elasticsearch/index/service/InternalIndexService.java index 8e5913ea5da..22e0f3678a3 100644 --- a/src/main/java/org/elasticsearch/index/service/InternalIndexService.java +++ b/src/main/java/org/elasticsearch/index/service/InternalIndexService.java @@ -27,10 +27,8 @@ import org.elasticsearch.ElasticSearchIllegalStateException; import org.elasticsearch.ElasticSearchInterruptedException; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.inject.*; -import org.elasticsearch.common.io.FileSystemUtils; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.NodeEnvironment; -import org.elasticsearch.gateway.none.NoneGateway; import org.elasticsearch.index.*; import org.elasticsearch.index.aliases.IndexAliasesService; import org.elasticsearch.index.analysis.AnalysisService; @@ -72,7 +70,6 @@ import org.elasticsearch.plugins.PluginsService; import org.elasticsearch.plugins.ShardsPluginsModule; import org.elasticsearch.threadpool.ThreadPool; -import java.io.IOException; import java.util.Map; import java.util.Set; import java.util.concurrent.CountDownLatch; @@ -255,7 +252,7 @@ public class InternalIndexService extends AbstractIndexComponent implements Inde return indexEngine; } - public void close(final boolean delete, final String reason, @Nullable Executor executor) { + public void close(final String reason, @Nullable Executor executor) { synchronized (this) { closed = true; } @@ -267,9 +264,9 @@ public class InternalIndexService extends AbstractIndexComponent implements Inde @Override public void run() { try { - deleteShard(shardId, delete, !delete, delete, reason); + removeShard(shardId, reason); } catch (Exception e) { - logger.warn("failed to close shard, delete [{}]", e, delete); + logger.warn("failed to close shard", e); } finally { latch.countDown(); } @@ -345,32 +342,17 @@ public class InternalIndexService extends AbstractIndexComponent implements Inde return indexShard; } - @Override - public synchronized void cleanShard(int shardId, String reason) throws ElasticSearchException { - deleteShard(shardId, true, false, false, reason); - } - @Override public synchronized void removeShard(int shardId, String reason) throws ElasticSearchException { - deleteShard(shardId, false, false, false, reason); - } - - private void deleteShard(int shardId, boolean delete, boolean snapshotGateway, boolean deleteGateway, String reason) throws ElasticSearchException { Injector shardInjector; IndexShard indexShard; synchronized (this) { Map tmpShardInjectors = newHashMap(shardsInjectors); shardInjector = tmpShardInjectors.remove(shardId); if (shardInjector == null) { - if (!delete) { - return; - } - throw new IndexShardMissingException(new ShardId(index, shardId)); + return; } shardsInjectors = ImmutableMap.copyOf(tmpShardInjectors); - if (delete) { - logger.debug("deleting shard_id [{}]", shardId); - } Map tmpShardsMap = newHashMap(shards); indexShard = tmpShardsMap.remove(shardId); @@ -379,11 +361,11 @@ public class InternalIndexService extends AbstractIndexComponent implements Inde ShardId sId = new ShardId(index, shardId); - indicesLifecycle.beforeIndexShardClosed(sId, indexShard, delete); + indicesLifecycle.beforeIndexShardClosed(sId, indexShard); for (Class closeable : pluginsService.shardServices()) { try { - shardInjector.getInstance(closeable).close(delete); + shardInjector.getInstance(closeable).close(); } catch (Exception e) { logger.debug("failed to clean plugin shard service [{}]", e, closeable); } @@ -415,59 +397,45 @@ public class InternalIndexService extends AbstractIndexComponent implements Inde } try { - shardInjector.getInstance(MergePolicyProvider.class).close(delete); + shardInjector.getInstance(MergePolicyProvider.class).close(); } catch (Exception e) { logger.debug("failed to close merge policy provider", e); // ignore } try { - // now, we can snapshot to the gateway, it will be only the translog - if (snapshotGateway) { - shardInjector.getInstance(IndexShardGatewayService.class).snapshotOnClose(); - } + shardInjector.getInstance(IndexShardGatewayService.class).snapshotOnClose(); } catch (Exception e) { - logger.debug("failed to snapshot gateway on close", e); + logger.debug("failed to snapshot index shard gateway on close", e); // ignore } + try { - shardInjector.getInstance(IndexShardGatewayService.class).close(deleteGateway); + shardInjector.getInstance(IndexShardGatewayService.class).close(); } catch (Exception e) { logger.debug("failed to close index shard gateway", e); // ignore } try { // now we can close the translog - shardInjector.getInstance(Translog.class).close(delete); + shardInjector.getInstance(Translog.class).close(); } catch (Exception e) { logger.debug("failed to close translog", e); // ignore } // call this before we close the store, so we can release resources for it - indicesLifecycle.afterIndexShardClosed(sId, delete); + indicesLifecycle.afterIndexShardClosed(sId); // if we delete or have no gateway or the store is not persistent, clean the store... Store store = shardInjector.getInstance(Store.class); - if (delete || indexGateway.type().equals(NoneGateway.TYPE) || !indexStore.persistent()) { - try { - store.fullDelete(); - } catch (IOException e) { - logger.warn("failed to clean store on shard deletion", e); - } - } // and close it try { store.close(); - } catch (IOException e) { + } catch (Exception e) { logger.warn("failed to close store on shard deletion", e); } Injectors.close(injector); - - // delete the shard location if needed - if (delete || indexGateway.type().equals(NoneGateway.TYPE)) { - FileSystemUtils.deleteRecursively(nodeEnv.shardLocations(sId)); - } } } \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/index/store/Store.java b/src/main/java/org/elasticsearch/index/store/Store.java index 0450b024983..8bd6a3f5693 100644 --- a/src/main/java/org/elasticsearch/index/store/Store.java +++ b/src/main/java/org/elasticsearch/index/store/Store.java @@ -33,6 +33,7 @@ import org.elasticsearch.common.lucene.store.BufferedChecksumIndexOutput; import org.elasticsearch.common.lucene.store.ChecksumIndexOutput; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.ByteSizeValue; +import org.elasticsearch.index.CloseableIndexComponent; import org.elasticsearch.index.settings.IndexSettings; import org.elasticsearch.index.shard.AbstractIndexShardComponent; import org.elasticsearch.index.shard.ShardId; @@ -50,7 +51,7 @@ import java.util.zip.Adler32; /** */ -public class Store extends AbstractIndexShardComponent { +public class Store extends AbstractIndexShardComponent implements CloseableIndexComponent { static final String CHECKSUMS_PREFIX = "_checksums-"; @@ -112,6 +113,9 @@ public class Store extends AbstractIndexShardComponent { return md; } + /** + * Deletes the content of a shard store. Be careful calling this!. + */ public void deleteContent() throws IOException { String[] files = directory.listAll(); IOException lastException = null; @@ -137,13 +141,6 @@ public class Store extends AbstractIndexShardComponent { } } - public void fullDelete() throws IOException { - deleteContent(); - for (Directory delegate : directory.delegates()) { - directoryService.fullDelete(delegate); - } - } - public StoreStats stats() throws IOException { return new StoreStats(Directories.estimateSize(directory), directoryService.throttleTimeInNanos()); } @@ -248,8 +245,12 @@ public class Store extends AbstractIndexShardComponent { return false; } - public void close() throws IOException { - directory.close(); + public void close() { + try { + directory.close(); + } catch (IOException e) { + logger.debug("failed to close directory", e); + } } /** diff --git a/src/main/java/org/elasticsearch/index/store/support/AbstractIndexStore.java b/src/main/java/org/elasticsearch/index/store/support/AbstractIndexStore.java index 929cb91a631..4adaa5a21c3 100644 --- a/src/main/java/org/elasticsearch/index/store/support/AbstractIndexStore.java +++ b/src/main/java/org/elasticsearch/index/store/support/AbstractIndexStore.java @@ -102,7 +102,7 @@ public abstract class AbstractIndexStore extends AbstractIndexComponent implemen } @Override - public void close(boolean delete) throws ElasticSearchException { + public void close() throws ElasticSearchException { indexService.settingsService().removeListener(applySettings); } diff --git a/src/main/java/org/elasticsearch/index/translog/Translog.java b/src/main/java/org/elasticsearch/index/translog/Translog.java index 56cf45091e9..81631a453ea 100644 --- a/src/main/java/org/elasticsearch/index/translog/Translog.java +++ b/src/main/java/org/elasticsearch/index/translog/Translog.java @@ -29,6 +29,7 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.lease.Releasable; +import org.elasticsearch.index.CloseableIndexComponent; import org.elasticsearch.index.engine.Engine; import org.elasticsearch.index.shard.IndexShardComponent; @@ -38,10 +39,12 @@ import java.io.InputStream; /** * */ -public interface Translog extends IndexShardComponent { +public interface Translog extends IndexShardComponent, CloseableIndexComponent { public static final String TRANSLOG_ID_KEY = "translog_id"; + void closeWithDelete(); + /** * Returns the id of the current transaction log. */ @@ -122,13 +125,6 @@ public interface Translog extends IndexShardComponent { void syncOnEachOperation(boolean syncOnEachOperation); - /** - * Closes the transaction log. - *

- *

Can only be called by one thread. - */ - void close(boolean delete); - static class Location { public final long translogId; public final long translogLocation; diff --git a/src/main/java/org/elasticsearch/index/translog/fs/FsTranslog.java b/src/main/java/org/elasticsearch/index/translog/fs/FsTranslog.java index e82b2bffe45..8e80e1d9d69 100644 --- a/src/main/java/org/elasticsearch/index/translog/fs/FsTranslog.java +++ b/src/main/java/org/elasticsearch/index/translog/fs/FsTranslog.java @@ -20,6 +20,7 @@ package org.elasticsearch.index.translog.fs; import jsr166y.ThreadLocalRandom; +import org.elasticsearch.ElasticSearchException; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.io.FileSystemUtils; import org.elasticsearch.common.io.stream.BytesStreamOutput; @@ -118,7 +119,16 @@ public class FsTranslog extends AbstractIndexShardComponent implements Translog } @Override - public void close(boolean delete) { + public void closeWithDelete() { + close(true); + } + + @Override + public void close() throws ElasticSearchException { + close(false); + } + + private void close(boolean delete) { if (indexSettingsService != null) { indexSettingsService.removeListener(applySettings); } diff --git a/src/main/java/org/elasticsearch/indices/IndicesLifecycle.java b/src/main/java/org/elasticsearch/indices/IndicesLifecycle.java index c237ccfc188..4a870f42a07 100644 --- a/src/main/java/org/elasticsearch/indices/IndicesLifecycle.java +++ b/src/main/java/org/elasticsearch/indices/IndicesLifecycle.java @@ -97,19 +97,17 @@ public interface IndicesLifecycle { * Called before the index get closed. * * @param indexService The index service - * @param delete Does the index gets closed because of a delete command, or because the node is shutting down */ - public void beforeIndexClosed(IndexService indexService, boolean delete) { + public void beforeIndexClosed(IndexService indexService) { } /** * Called after the index has been closed. * - * @param index The index - * @param delete Does the index gets closed because of a delete command, or because the node is shutting down + * @param index The index */ - public void afterIndexClosed(Index index, boolean delete) { + public void afterIndexClosed(Index index) { } @@ -117,9 +115,8 @@ public interface IndicesLifecycle { * Called before the index shard gets closed. * * @param indexShard The index shard - * @param delete Does the index shard gets closed because of a delete command, or because the node is shutting down */ - public void beforeIndexShardClosed(ShardId shardId, @Nullable IndexShard indexShard, boolean delete) { + public void beforeIndexShardClosed(ShardId shardId, @Nullable IndexShard indexShard) { } @@ -127,9 +124,8 @@ public interface IndicesLifecycle { * Called after the index shard has been closed. * * @param shardId The shard id - * @param delete Does the index shard gets closed because of a delete command, or because the node is shutting down */ - public void afterIndexShardClosed(ShardId shardId, boolean delete) { + public void afterIndexShardClosed(ShardId shardId) { } } diff --git a/src/main/java/org/elasticsearch/indices/IndicesService.java b/src/main/java/org/elasticsearch/indices/IndicesService.java index aa911684e98..61169da1b5a 100644 --- a/src/main/java/org/elasticsearch/indices/IndicesService.java +++ b/src/main/java/org/elasticsearch/indices/IndicesService.java @@ -55,10 +55,5 @@ public interface IndicesService extends Iterable, LifecycleCompone IndexService createIndex(String index, Settings settings, String localNodeId) throws ElasticSearchException; - void deleteIndex(String index, String reason) throws ElasticSearchException; - - /** - * Cleans the index without actually deleting any content for it. - */ - void cleanIndex(String index, String reason) throws ElasticSearchException; + void removeIndex(String index, String reason) throws ElasticSearchException; } diff --git a/src/main/java/org/elasticsearch/indices/InternalIndicesLifecycle.java b/src/main/java/org/elasticsearch/indices/InternalIndicesLifecycle.java index dbd5f45dc09..090efbbc4ef 100644 --- a/src/main/java/org/elasticsearch/indices/InternalIndicesLifecycle.java +++ b/src/main/java/org/elasticsearch/indices/InternalIndicesLifecycle.java @@ -87,27 +87,27 @@ public class InternalIndicesLifecycle extends AbstractComponent implements Indic } } - public void beforeIndexClosed(IndexService indexService, boolean delete) { + public void beforeIndexClosed(IndexService indexService) { for (Listener listener : listeners) { - listener.beforeIndexClosed(indexService, delete); + listener.beforeIndexClosed(indexService); } } - public void afterIndexClosed(Index index, boolean delete) { + public void afterIndexClosed(Index index) { for (Listener listener : listeners) { - listener.afterIndexClosed(index, delete); + listener.afterIndexClosed(index); } } - public void beforeIndexShardClosed(ShardId shardId, @Nullable IndexShard indexShard, boolean delete) { + public void beforeIndexShardClosed(ShardId shardId, @Nullable IndexShard indexShard) { for (Listener listener : listeners) { - listener.beforeIndexShardClosed(shardId, indexShard, delete); + listener.beforeIndexShardClosed(shardId, indexShard); } } - public void afterIndexShardClosed(ShardId shardId, boolean delete) { + public void afterIndexShardClosed(ShardId shardId) { for (Listener listener : listeners) { - listener.afterIndexShardClosed(shardId, delete); + listener.afterIndexShardClosed(shardId); } } } diff --git a/src/main/java/org/elasticsearch/indices/InternalIndicesService.java b/src/main/java/org/elasticsearch/indices/InternalIndicesService.java index fa6df2e9856..3c2abe4ea99 100644 --- a/src/main/java/org/elasticsearch/indices/InternalIndicesService.java +++ b/src/main/java/org/elasticsearch/indices/InternalIndicesService.java @@ -27,7 +27,6 @@ import org.elasticsearch.ElasticSearchIllegalStateException; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.component.AbstractLifecycleComponent; import org.elasticsearch.common.inject.*; -import org.elasticsearch.common.io.FileSystemUtils; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.concurrent.EsExecutors; import org.elasticsearch.env.NodeEnvironment; @@ -148,7 +147,7 @@ public class InternalIndicesService extends AbstractLifecycleComponent tmpMap = newHashMap(indices); @@ -340,13 +328,13 @@ public class InternalIndicesService extends AbstractLifecycleComponent closeable : pluginsService.indexServices()) { - indexInjector.getInstance(closeable).close(delete); + indexInjector.getInstance(closeable).close(); } - ((InternalIndexService) indexService).close(delete, reason, executor); + ((InternalIndexService) indexService).close(reason, executor); indexInjector.getInstance(PercolatorService.class).close(); indexInjector.getInstance(IndexCache.class).close(); @@ -354,19 +342,15 @@ public class InternalIndicesService extends AbstractLifecycleComponent { class CleanContextOnIndicesLifecycleListener extends IndicesLifecycle.Listener { @Override - public void beforeIndexClosed(IndexService indexService, boolean delete) { + public void beforeIndexClosed(IndexService indexService) { releaseContextsForIndex(indexService.index()); } @Override - public void beforeIndexShardClosed(ShardId shardId, @Nullable IndexShard indexShard, boolean delete) { + public void beforeIndexShardClosed(ShardId shardId, @Nullable IndexShard indexShard) { releaseContextsForShard(shardId); } } diff --git a/src/test/java/org/elasticsearch/test/unit/index/translog/AbstractSimpleTranslogTests.java b/src/test/java/org/elasticsearch/test/unit/index/translog/AbstractSimpleTranslogTests.java index 5e097c06b17..4e2dcde8b10 100644 --- a/src/test/java/org/elasticsearch/test/unit/index/translog/AbstractSimpleTranslogTests.java +++ b/src/test/java/org/elasticsearch/test/unit/index/translog/AbstractSimpleTranslogTests.java @@ -53,7 +53,7 @@ public abstract class AbstractSimpleTranslogTests { @AfterMethod public void tearDown() { - translog.close(true); + translog.closeWithDelete(); } protected abstract Translog create();