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 extends CloseableIndexComponent> 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();