Don't get IndexShard instance in the executor but use already availale instance

We try to get the index shard instance again from the index service on a different
threads while that shard might have already been closed or removed which can cause a NPE
instead of another expected expecption.
This commit is contained in:
Simon Willnauer 2015-09-30 20:41:35 +02:00
parent 3c18393e48
commit 4886562d78
1 changed files with 6 additions and 6 deletions

View File

@ -672,28 +672,28 @@ public class IndicesClusterStateService extends AbstractLifecycleComponent<Indic
handleRecoveryFailure(indexService, shardRouting, true, e);
}
} else {
final DiscoveryNode localNode = clusterService.localNode();
threadPool.generic().execute(() -> {
final RestoreSource restoreSource = shardRouting.restoreSource();
final ShardId sId = indexShard.shardId();
try {
final boolean success;
final IndexShard shard = indexService.shard(shardId);
final DiscoveryNode localNode = clusterService.localNode();
if (restoreSource == null) {
// recover from filesystem store
success = shard.recoverFromStore(shardRouting, localNode);
success = indexShard.recoverFromStore(shardRouting, localNode);
} else {
// restore
final IndexShardRepository indexShardRepository = repositoriesService.indexShardRepository(restoreSource.snapshotId().getRepository());
try {
success = shard.restoreFromRepository(shardRouting, indexShardRepository, localNode);
success = indexShard.restoreFromRepository(shardRouting, indexShardRepository, localNode);
} catch (Throwable t) {
if (Lucene.isCorruptionException(t)) {
restoreService.failRestore(restoreSource.snapshotId(), shard.shardId());
restoreService.failRestore(restoreSource.snapshotId(), sId);
}
throw t;
}
if (success) {
restoreService.indexShardRestoreCompleted(restoreSource.snapshotId(), shard.shardId());
restoreService.indexShardRestoreCompleted(restoreSource.snapshotId(), sId);
}
}
if (success) {