-
Notifications
You must be signed in to change notification settings - Fork 25.5k
Reset failed allocation counter before executing routing commands #42658
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
Merged
DaveCTurner
merged 12 commits into
elastic:master
from
vigyasharma:reset-max-retry-counter
Jun 10, 2019
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
4e57fa7
Reset max_retries counter before executing routing commands
vigyasharma a07ebb0
Add license header
vigyasharma 9c30d54
Avoid creating RoutingAllocation on each counter reset
vigyasharma 3edd457
Reformat
DaveCTurner c45ab04
Apply suggestions from code review
vigyasharma c936a2a
Minor CR suggestions
vigyasharma e641401
Modify test as per review suggestions
vigyasharma 37fcdb4
Merge branch 'master' into reset-max-retry-counter
elasticmachine 8660044
Merge branch 'master' into reset-max-retry-counter
DaveCTurner e4cf0c8
Merge branch 'master' into reset-max-retry-counter
DaveCTurner a6a2aee
Merge branch 'master' into reset-max-retry-counter
DaveCTurner 3b2bc8a
Merge branch 'master' into reset-max-retry-counter
DaveCTurner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
97 changes: 97 additions & 0 deletions
97
...rc/test/java/org/elasticsearch/cluster/routing/allocation/RetryFailedAllocationTests.java
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.cluster.routing.allocation; | ||
|
||
import org.elasticsearch.ElasticsearchException; | ||
import org.elasticsearch.Version; | ||
import org.elasticsearch.cluster.ClusterName; | ||
import org.elasticsearch.cluster.ClusterState; | ||
import org.elasticsearch.cluster.ESAllocationTestCase; | ||
import org.elasticsearch.cluster.metadata.IndexMetaData; | ||
import org.elasticsearch.cluster.metadata.MetaData; | ||
import org.elasticsearch.cluster.node.DiscoveryNodes; | ||
import org.elasticsearch.cluster.routing.RoutingTable; | ||
import org.elasticsearch.cluster.routing.ShardRouting; | ||
import org.elasticsearch.cluster.routing.ShardRoutingState; | ||
import org.elasticsearch.cluster.routing.allocation.command.AllocateReplicaAllocationCommand; | ||
import org.elasticsearch.cluster.routing.allocation.command.AllocationCommands; | ||
import org.elasticsearch.cluster.routing.allocation.decider.MaxRetryAllocationDecider; | ||
import org.elasticsearch.common.settings.Settings; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.sameInstance; | ||
|
||
public class RetryFailedAllocationTests extends ESAllocationTestCase { | ||
|
||
private MockAllocationService strategy; | ||
private ClusterState clusterState; | ||
private final String INDEX_NAME = "index"; | ||
|
||
@Override | ||
public void setUp() throws Exception { | ||
super.setUp(); | ||
MetaData metaData = MetaData.builder().put(IndexMetaData.builder(INDEX_NAME) | ||
.settings(settings(Version.CURRENT)).numberOfShards(1).numberOfReplicas(1)).build(); | ||
RoutingTable routingTable = RoutingTable.builder().addAsNew(metaData.index(INDEX_NAME)).build(); | ||
clusterState = ClusterState.builder(ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable) | ||
.nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2"))).build(); | ||
strategy = createAllocationService(Settings.EMPTY); | ||
} | ||
|
||
private ShardRouting getPrimary() { | ||
return clusterState.getRoutingTable().index(INDEX_NAME).shard(0).primaryShard(); | ||
} | ||
|
||
private ShardRouting getReplica() { | ||
return clusterState.getRoutingTable().index(INDEX_NAME).shard(0).replicaShards().get(0); | ||
} | ||
|
||
public void testRetryFailedResetForAllocationCommands() { | ||
final int retries = MaxRetryAllocationDecider.SETTING_ALLOCATION_MAX_RETRY.get(Settings.EMPTY); | ||
clusterState = strategy.reroute(clusterState, "initial allocation"); | ||
clusterState = strategy.applyStartedShards(clusterState, Collections.singletonList(getPrimary())); | ||
|
||
// Exhaust all replica allocation attempts with shard failures | ||
for (int i = 0; i < retries; i++) { | ||
List<FailedShard> failedShards = Collections.singletonList( | ||
new FailedShard(getReplica(), "failing-shard::attempt-" + i, | ||
new ElasticsearchException("simulated"), randomBoolean())); | ||
clusterState = strategy.applyFailedShards(clusterState, failedShards); | ||
clusterState = strategy.reroute(clusterState, "allocation retry attempt-" + i); | ||
} | ||
assertThat("replica should not be assigned", getReplica().state(), equalTo(ShardRoutingState.UNASSIGNED)); | ||
assertThat("reroute should be a no-op", strategy.reroute(clusterState, "test"), sameInstance(clusterState)); | ||
|
||
// Now allocate replica with retry_failed flag set | ||
AllocationService.CommandsResult result = strategy.reroute(clusterState, | ||
new AllocationCommands(new AllocateReplicaAllocationCommand(INDEX_NAME, 0, | ||
getPrimary().currentNodeId().equals("node1") ? "node2" : "node1")), | ||
false, true); | ||
clusterState = result.getClusterState(); | ||
|
||
assertEquals(ShardRoutingState.INITIALIZING, getReplica().state()); | ||
clusterState = strategy.applyStartedShards(clusterState, Collections.singletonList(getReplica())); | ||
assertEquals(ShardRoutingState.STARTED, getReplica().state()); | ||
assertFalse(clusterState.getRoutingNodes().hasUnassignedShards()); | ||
} | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.