Skip to content

Commit d5da0e2

Browse files
henningandersenhowardhuanghua
authored andcommitted
Shrink should not touch max_retries (elastic#47719)
Shrink would set `max_retries=1` in order to avoid retrying. This however sticks to the shrunk index afterwards, causing issues when a shard copy later fails to allocate just once. Avoiding a retry of a shrink makes sense since there is no new node to allocate to and a retry will likely fail again. However, the downside of having max_retries=1 afterwards outweigh the benefit of not retrying the failed shrink a few times. This change ensures shrink no longer sets max_retries and also makes all resize operations (shrink, clone, split) leave the setting at default value rather than copy it from source.
1 parent c627046 commit d5da0e2

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

server/src/main/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexService.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -766,10 +766,7 @@ static void prepareResizeIndexSettings(
766766
if (type == ResizeType.SHRINK) {
767767
final List<String> nodesToAllocateOn = validateShrinkIndex(currentState, resizeSourceIndex.getName(),
768768
mappingKeys, resizeIntoName, indexSettingsBuilder.build());
769-
indexSettingsBuilder
770-
.put(initialRecoveryIdFilter, Strings.arrayToCommaDelimitedString(nodesToAllocateOn.toArray()))
771-
// we only try once and then give up with a shrink index
772-
.put("index.allocation.max_retries", 1);
769+
indexSettingsBuilder.put(initialRecoveryIdFilter, Strings.arrayToCommaDelimitedString(nodesToAllocateOn.toArray()));
773770
} else if (type == ResizeType.SPLIT) {
774771
validateSplitIndex(currentState, resizeSourceIndex.getName(), mappingKeys, resizeIntoName, indexSettingsBuilder.build());
775772
indexSettingsBuilder.putNull(initialRecoveryIdFilter);

server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/MaxRetryAllocationDecider.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
public class MaxRetryAllocationDecider extends AllocationDecider {
3838

3939
public static final Setting<Integer> SETTING_ALLOCATION_MAX_RETRY = Setting.intSetting("index.allocation.max_retries", 5, 0,
40-
Setting.Property.Dynamic, Setting.Property.IndexScope);
40+
Setting.Property.Dynamic, Setting.Property.IndexScope, Setting.Property.NotCopyableOnResize);
4141

4242
public static final String NAME = "max_retry";
4343

server/src/test/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexServiceTests.java

+8-5
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
import static org.hamcrest.Matchers.endsWith;
6969
import static org.hamcrest.Matchers.equalTo;
7070
import static org.hamcrest.Matchers.hasToString;
71+
import static org.hamcrest.Matchers.nullValue;
7172

7273
public class MetaDataCreateIndexServiceTests extends ESTestCase {
7374

@@ -247,16 +248,18 @@ public void testPrepareResizeIndexSettings() {
247248
versions.sort(Comparator.comparingLong(l -> l.id));
248249
final Version version = versions.get(0);
249250
final Version upgraded = versions.get(1);
250-
final Settings indexSettings =
251+
final Settings.Builder indexSettingsBuilder =
251252
Settings.builder()
252253
.put("index.version.created", version)
253254
.put("index.version.upgraded", upgraded)
254255
.put("index.similarity.default.type", "BM25")
255256
.put("index.analysis.analyzer.default.tokenizer", "keyword")
256-
.put("index.soft_deletes.enabled", "true")
257-
.build();
257+
.put("index.soft_deletes.enabled", "true");
258+
if (randomBoolean()) {
259+
indexSettingsBuilder.put("index.allocation.max_retries", randomIntBetween(1, 1000));
260+
}
258261
runPrepareResizeIndexSettingsTest(
259-
indexSettings,
262+
indexSettingsBuilder.build(),
260263
Settings.EMPTY,
261264
Collections.emptyList(),
262265
randomBoolean(),
@@ -267,7 +270,7 @@ public void testPrepareResizeIndexSettings() {
267270
settings.get("index.analysis.analyzer.default.tokenizer"),
268271
equalTo("keyword"));
269272
assertThat(settings.get("index.routing.allocation.initial_recovery._id"), equalTo("node1"));
270-
assertThat(settings.get("index.allocation.max_retries"), equalTo("1"));
273+
assertThat(settings.get("index.allocation.max_retries"), nullValue());
271274
assertThat(settings.getAsVersion("index.version.created", null), equalTo(version));
272275
assertThat(settings.getAsVersion("index.version.upgraded", null), equalTo(upgraded));
273276
assertThat(settings.get("index.soft_deletes.enabled"), equalTo("true"));

0 commit comments

Comments
 (0)