New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor RecoveryTarget state management #8092
Closed
Closed
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
4005aa2
Recovery: clean up temporary files when canceling recovery
bleskes 99e67a2
temp file names registry - not there yet.
bleskes 046967e
wip
bleskes aaafcf2
Some more cleanup and java docs
bleskes 676957d
Beter encapsulate temporary files
bleskes 32a9225
Fix compilation after rebasing to 1.x
bleskes af561c4
testCancellationCleansTempFiles: use assertBusy to verify all files w…
bleskes 1facdbf
Feedback round
bleskes 4ca2507
moved package line
bleskes 1f10339
one more private final
bleskes 8997284
Fail recovery on every error while listing local files.
bleskes File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,9 +61,10 @@ | |
import org.elasticsearch.index.shard.ShardId; | ||
import org.elasticsearch.index.shard.service.IndexShard; | ||
import org.elasticsearch.index.shard.service.InternalIndexShard; | ||
import org.elasticsearch.index.store.Store; | ||
import org.elasticsearch.indices.IndicesService; | ||
import org.elasticsearch.indices.recovery.*; | ||
import org.elasticsearch.indices.recovery.RecoveryFailedException; | ||
import org.elasticsearch.indices.recovery.RecoveryState; | ||
import org.elasticsearch.indices.recovery.RecoveryTarget; | ||
import org.elasticsearch.threadpool.ThreadPool; | ||
|
||
import java.util.HashMap; | ||
|
@@ -559,19 +560,18 @@ private void applyNewOrUpdatedShards(final ClusterChangedEvent event) throws Ela | |
boolean shardHasBeenRemoved = false; | ||
if (currentRoutingEntry.initializing() && shardRouting.initializing() && !currentRoutingEntry.equals(shardRouting)) { | ||
logger.debug("[{}][{}] removing shard (different instance of it allocated on this node, current [{}], global [{}])", shardRouting.index(), shardRouting.id(), currentRoutingEntry, shardRouting); | ||
// cancel recovery just in case we are in recovery (its fine if we are not in recovery, it will be a noop). | ||
recoveryTarget.cancelRecovery(indexShard); | ||
// closing the shard will also cancel any ongoing recovery. | ||
indexService.removeShard(shardRouting.id(), "removing shard (different instance of it allocated on this node)"); | ||
shardHasBeenRemoved = true; | ||
} else if (isPeerRecovery(shardRouting)) { | ||
// check if there is an existing recovery going, and if so, and the source node is not the same, cancel the recovery to restart it | ||
RecoveryStatus recoveryStatus = recoveryTarget.recoveryStatus(indexShard); | ||
if (recoveryStatus != null && recoveryStatus.stage() != RecoveryState.Stage.DONE) { | ||
RecoveryState recoveryState = recoveryTarget.recoveryState(indexShard); | ||
if (recoveryState != null && recoveryState.getStage() != RecoveryState.Stage.DONE) { | ||
// we have an ongoing recovery, find the source based on current routing and compare them | ||
DiscoveryNode sourceNode = findSourceNodeForPeerRecovery(routingTable, nodes, shardRouting); | ||
if (!recoveryStatus.sourceNode().equals(sourceNode)) { | ||
if (!recoveryState.getSourceNode().equals(sourceNode)) { | ||
logger.debug("[{}][{}] removing shard (recovery source changed), current [{}], global [{}])", shardRouting.index(), shardRouting.id(), currentRoutingEntry, shardRouting); | ||
recoveryTarget.cancelRecovery(indexShard); | ||
// closing the shard will also cancel any ongoing recovery. | ||
indexService.removeShard(shardRouting.id(), "removing shard (recovery source node changed)"); | ||
shardHasBeenRemoved = true; | ||
} | ||
|
@@ -728,17 +728,7 @@ private void applyInitializingShard(final RoutingTable routingTable, final Disco | |
// the edge case where its mark as relocated, and we might need to roll it back... | ||
// For replicas: we are recovering a backup from a primary | ||
RecoveryState.Type type = shardRouting.primary() ? RecoveryState.Type.RELOCATION : RecoveryState.Type.REPLICA; | ||
final Store store = indexShard.store(); | ||
final StartRecoveryRequest request; | ||
store.incRef(); | ||
try { | ||
store.failIfCorrupted(); | ||
request = new StartRecoveryRequest(indexShard.shardId(), sourceNode, nodes.localNode(), | ||
false, store.getMetadata().asMap(), type, recoveryIdGenerator.incrementAndGet()); | ||
} finally { | ||
store.decRef(); | ||
} | ||
recoveryTarget.startRecovery(request, indexShard, new PeerRecoveryListener(request, shardRouting, indexService, indexMetaData)); | ||
recoveryTarget.startRecovery(indexShard, type, sourceNode, new PeerRecoveryListener(shardRouting, indexService, indexMetaData)); | ||
|
||
} catch (Throwable e) { | ||
indexShard.engine().failEngine("corrupted preexisting index", e); | ||
|
@@ -808,68 +798,41 @@ private boolean isPeerRecovery(ShardRouting shardRouting) { | |
|
||
private class PeerRecoveryListener implements RecoveryTarget.RecoveryListener { | ||
|
||
private final StartRecoveryRequest request; | ||
private final ShardRouting shardRouting; | ||
private final IndexService indexService; | ||
private final IndexMetaData indexMetaData; | ||
|
||
private PeerRecoveryListener(StartRecoveryRequest request, ShardRouting shardRouting, IndexService indexService, IndexMetaData indexMetaData) { | ||
this.request = request; | ||
private PeerRecoveryListener(ShardRouting shardRouting, IndexService indexService, IndexMetaData indexMetaData) { | ||
this.shardRouting = shardRouting; | ||
this.indexService = indexService; | ||
this.indexMetaData = indexMetaData; | ||
} | ||
|
||
@Override | ||
public void onRecoveryDone() { | ||
shardStateAction.shardStarted(shardRouting, indexMetaData.getUUID(), "after recovery (replica) from node [" + request.sourceNode() + "]"); | ||
} | ||
|
||
@Override | ||
public void onRetryRecovery(TimeValue retryAfter, RecoveryStatus recoveryStatus) { | ||
recoveryTarget.retryRecovery(request, retryAfter, recoveryStatus, PeerRecoveryListener.this); | ||
} | ||
|
||
@Override | ||
public void onIgnoreRecovery(boolean removeShard, String reason) { | ||
if (!removeShard) { | ||
return; | ||
} | ||
synchronized (mutex) { | ||
if (indexService.hasShard(shardRouting.shardId().id())) { | ||
if (logger.isDebugEnabled()) { | ||
logger.debug("[{}][{}] removing shard on ignored recovery, reason [{}]", shardRouting.index(), shardRouting.shardId().id(), reason); | ||
} | ||
try { | ||
indexService.removeShard(shardRouting.shardId().id(), "ignore recovery: " + reason); | ||
} catch (IndexShardMissingException e) { | ||
// the node got closed on us, ignore it | ||
} catch (Throwable e1) { | ||
logger.warn("[{}][{}] failed to delete shard after ignore recovery", e1, indexService.index().name(), shardRouting.shardId().id()); | ||
} | ||
} | ||
} | ||
public void onRecoveryDone(RecoveryState state) { | ||
shardStateAction.shardStarted(shardRouting, indexMetaData.getUUID(), "after recovery (replica) from node [" + state.getSourceNode() + "]"); | ||
} | ||
|
||
@Override | ||
public void onRecoveryFailure(RecoveryFailedException e, boolean sendShardFailure) { | ||
public void onRecoveryFailure(RecoveryState state, RecoveryFailedException e, boolean sendShardFailure) { | ||
handleRecoveryFailure(indexService, indexMetaData, shardRouting, sendShardFailure, e); | ||
} | ||
} | ||
|
||
private void handleRecoveryFailure(IndexService indexService, IndexMetaData indexMetaData, ShardRouting shardRouting, boolean sendShardFailure, Throwable failure) { | ||
logger.warn("[{}][{}] failed to start shard", failure, indexService.index().name(), shardRouting.shardId().id()); | ||
synchronized (mutex) { | ||
if (indexService.hasShard(shardRouting.shardId().id())) { | ||
try { | ||
logger.debug("[{}][{}] removing shard on failed recovery [{}]", shardRouting.index(), shardRouting.shardId().id(), failure.getMessage()); | ||
indexService.removeShard(shardRouting.shardId().id(), "recovery failure [" + ExceptionsHelper.detailedMessage(failure) + "]"); | ||
} catch (IndexShardMissingException e) { | ||
// the node got closed on us, ignore it | ||
} catch (Throwable e1) { | ||
logger.warn("[{}][{}] failed to delete shard after failed startup", e1, indexService.index().name(), shardRouting.shardId().id()); | ||
logger.warn("[{}][{}] failed to delete shard after recovery failure", e1, indexService.index().name(), shardRouting.shardId().id()); | ||
} | ||
} | ||
if (sendShardFailure) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. it is now removed from the listener interface. |
||
logger.warn("[{}][{}] sending failed shard after recovery failure", failure, indexService.index().name(), shardRouting.shardId().id()); | ||
try { | ||
failedShards.put(shardRouting.shardId(), new FailedShard(shardRouting.version())); | ||
shardStateAction.shardFailed(shardRouting, indexMetaData.getUUID(), "Failed to start shard, message [" + detailedMessage(failure) + "]"); | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this go into the ctor?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nevermind it gets updated