[CORE] close all resources even if #beforeIndexShardClosed throws an exception

Conflicts:
	src/main/java/org/elasticsearch/index/IndexService.java
This commit is contained in:
Simon Willnauer 2015-02-21 14:22:53 +01:00
parent 16f19bf7bd
commit 3e2f4b86e4

View File

@ -376,36 +376,40 @@ public class IndexService extends AbstractIndexComponent implements IndexCompone
private void closeShardInjector(String reason, ShardId sId, Injector shardInjector, IndexShard indexShard) { private void closeShardInjector(String reason, ShardId sId, Injector shardInjector, IndexShard indexShard) {
final int shardId = sId.id(); final int shardId = sId.id();
try { try {
indicesLifecycle.beforeIndexShardClosed(sId, indexShard, indexSettings); try {
for (Class<? extends Closeable> closeable : pluginsService.shardServices()) { indicesLifecycle.beforeIndexShardClosed(sId, indexShard, indexSettings);
try { } finally {
shardInjector.getInstance(closeable).close(); // close everything else even if the beforeIndexShardClosed threw an exception
} catch (Throwable e) { for (Class<? extends Closeable> closeable : pluginsService.shardServices()) {
logger.debug("[{}] failed to clean plugin shard service [{}]", e, shardId, closeable); try {
shardInjector.getInstance(closeable).close();
} catch (Throwable e) {
logger.debug("[{}] failed to clean plugin shard service [{}]", e, shardId, closeable);
}
} }
} // now we can close the translog service, we need to close it before the we close the shard
// now we can close the translog service, we need to close it before the we close the shard closeInjectorResource(sId, shardInjector, TranslogService.class);
closeInjectorResource(sId, shardInjector, TranslogService.class); // this logic is tricky, we want to close the engine so we rollback the changes done to it
// this logic is tricky, we want to close the engine so we rollback the changes done to it // and close the shard so no operations are allowed to it
// and close the shard so no operations are allowed to it if (indexShard != null) {
if (indexShard != null) { try {
try { final boolean flushEngine = deleted.get() == false && closed.get(); // only flush we are we closed (closed index or shutdown) and if we are not deleted
final boolean flushEngine = deleted.get() == false && closed.get(); // only flush we are we closed (closed index or shutdown) and if we are not deleted indexShard.close(reason, flushEngine);
indexShard.close(reason, flushEngine); } catch (Throwable e) {
} catch (Throwable e) { logger.debug("[{}] failed to close index shard", e, shardId);
logger.debug("[{}] failed to close index shard", e, shardId); // ignore
// ignore }
} }
} closeInjectorResource(sId, shardInjector,
closeInjectorResource(sId, shardInjector, MergeSchedulerProvider.class,
MergeSchedulerProvider.class, MergePolicyProvider.class,
MergePolicyProvider.class, IndexShardGatewayService.class,
IndexShardGatewayService.class, Translog.class,
Translog.class, PercolatorQueriesRegistry.class);
PercolatorQueriesRegistry.class);
// call this before we close the store, so we can release resources for it // call this before we close the store, so we can release resources for it
indicesLifecycle.afterIndexShardClosed(sId, indexShard, indexSettings); indicesLifecycle.afterIndexShardClosed(sId, indexShard, indexSettings);
}
} finally { } finally {
try { try {
shardInjector.getInstance(Store.class).close(); shardInjector.getInstance(Store.class).close();