Only use IndexShard instance to lookup recovery status

make sure we use the instance itself to look it up, and not the shard id, as we might get another instance
leftover from #6825
This commit is contained in:
Shay Banon 2014-07-11 11:38:25 +02:00
parent f480969503
commit 43a5cbe9be
3 changed files with 9 additions and 20 deletions

View File

@ -157,7 +157,7 @@ public class TransportRecoveryAction extends
RecoveryStatus recoveryStatus = indexShard.recoveryStatus();
if (recoveryStatus == null) {
recoveryStatus = recoveryTarget.recoveryStatus(indexShard.shardId());
recoveryStatus = recoveryTarget.recoveryStatus(indexShard);
}
if (recoveryStatus != null) {

View File

@ -544,7 +544,7 @@ public class IndicesClusterStateService extends AbstractLifecycleComponent<Indic
indexService.removeShard(shardRouting.id(), "removing shard (different instance of it allocated on this node)");
} 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.shardId());
RecoveryStatus recoveryStatus = recoveryTarget.recoveryStatus(indexShard);
if (recoveryStatus != null && recoveryStatus.stage() != RecoveryState.Stage.DONE) {
// we have an ongoing recovery, find the source based on current routing and compare them
DiscoveryNode sourceNode = findSourceNodeForPeerRecovery(routingTable, nodes, shardRouting);

View File

@ -109,16 +109,15 @@ public class RecoveryTarget extends AbstractComponent {
});
}
public RecoveryStatus recoveryStatus(ShardId shardId) {
RecoveryStatus peerRecoveryStatus = findRecoveryByShardId(shardId);
if (peerRecoveryStatus == null) {
public RecoveryStatus recoveryStatus(IndexShard indexShard) {
RecoveryStatus recoveryStatus = findRecoveryByShard(indexShard);
if (recoveryStatus == null) {
return null;
}
// update how long it takes if we are still recovering...
if (peerRecoveryStatus.recoveryState().getTimer().startTime() > 0 && peerRecoveryStatus.stage() != RecoveryState.Stage.DONE) {
peerRecoveryStatus.recoveryState().getTimer().time(System.currentTimeMillis() - peerRecoveryStatus.recoveryState().getTimer().startTime());
if (recoveryStatus.recoveryState().getTimer().startTime() > 0 && recoveryStatus.stage() != RecoveryState.Stage.DONE) {
recoveryStatus.recoveryState().getTimer().time(System.currentTimeMillis() - recoveryStatus.recoveryState().getTimer().startTime());
}
return peerRecoveryStatus;
return recoveryStatus;
}
public void cancelRecovery(IndexShard indexShard) {
@ -319,16 +318,6 @@ public class RecoveryTarget extends AbstractComponent {
void onRecoveryFailure(RecoveryFailedException e, boolean sendShardFailure);
}
@Nullable
private RecoveryStatus findRecoveryByShardId(ShardId shardId) {
for (RecoveryStatus recoveryStatus : onGoingRecoveries.values()) {
if (recoveryStatus.shardId.equals(shardId)) {
return recoveryStatus;
}
}
return null;
}
@Nullable
private RecoveryStatus findRecoveryByShard(IndexShard indexShard) {
for (RecoveryStatus recoveryStatus : onGoingRecoveries.values()) {