-
Notifications
You must be signed in to change notification settings - Fork 24.8k
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
Limit retries of failed allocations per index #18467
Merged
s1monw
merged 12 commits into
elastic:master
from
s1monw:limit_failed_allocation_retries
May 20, 2016
Merged
Changes from 5 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
394b280
Limit retries of failed allocations per index
s1monw 21887c1
apply feedback from @dakrone
s1monw b8d56c7
fix test
s1monw cb25e79
* Rename max_retry to max_retries
s1monw 0aef3d1
simplify assertion
s1monw 4a4436b
apply feedback
s1monw 6e88223
fix line length in test
s1monw 2544fec
add retry_failed=true|false flag to reroute API and add documentation
s1monw 68ad1e0
fix check condition
s1monw 36aeb55
feedback from @ywelsch
s1monw fd18eeb
fix docs
s1monw 6ff6822
add unittests for ClusterReroute
s1monw 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 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
71 changes: 71 additions & 0 deletions
71
.../java/org/elasticsearch/cluster/routing/allocation/decider/MaxRetryAllocationDecider.java
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 |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* 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.decider; | ||
|
||
import org.elasticsearch.cluster.metadata.IndexMetaData; | ||
import org.elasticsearch.cluster.routing.RoutingNode; | ||
import org.elasticsearch.cluster.routing.ShardRouting; | ||
import org.elasticsearch.cluster.routing.UnassignedInfo; | ||
import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; | ||
import org.elasticsearch.common.inject.Inject; | ||
import org.elasticsearch.common.settings.Setting; | ||
import org.elasticsearch.common.settings.Settings; | ||
|
||
/** | ||
* An allocation decider that prevents shards from being allocated on any node if the shards allocation has been retried N times without | ||
* success. This means if a shard has been INITIALIZING N times in a row without being moved to STARTED the shard will be ignored until | ||
* the setting for <tt>index.allocation.max_retry</tt> is raised. The default value is <tt>5</tt>. | ||
*/ | ||
public class MaxRetryAllocationDecider extends AllocationDecider { | ||
|
||
public static final Setting<Integer> SETTING_ALLOCATION_MAX_RETRY = Setting.intSetting("index.allocation.max_retries", 5, 0, | ||
Setting.Property.Dynamic, Setting.Property.IndexScope); | ||
|
||
public static final String NAME = "max_retry"; | ||
|
||
/** | ||
* Initializes a new {@link MaxRetryAllocationDecider} | ||
* | ||
* @param settings {@link Settings} used by this {@link AllocationDecider} | ||
*/ | ||
@Inject | ||
public MaxRetryAllocationDecider(Settings settings) { | ||
super(settings); | ||
} | ||
|
||
@Override | ||
public Decision canAllocate(ShardRouting shardRouting, RoutingAllocation allocation) { | ||
UnassignedInfo unassignedInfo = shardRouting.unassignedInfo(); | ||
if (unassignedInfo != null && unassignedInfo.getNumFailedAllocations() > 0) { | ||
IndexMetaData indexSafe = allocation.metaData().getIndexSafe(shardRouting.index()); | ||
int maxRetry = SETTING_ALLOCATION_MAX_RETRY.get(indexSafe.getSettings()); | ||
if (unassignedInfo.getNumFailedAllocations() >= maxRetry) { | ||
return allocation.decision(Decision.NO, NAME, "shard has already failed allocating [" | ||
+ unassignedInfo.getNumFailedAllocations() + "] times " + unassignedInfo.toString()); | ||
} | ||
} | ||
return allocation.decision(Decision.YES, NAME, "shard has no previous failures"); | ||
} | ||
|
||
@Override | ||
public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) { | ||
return canAllocate(shardRouting, allocation); | ||
} | ||
} |
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
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.
just call this variable
indexMetaData
?