Skip to content

Commit a0d0866

Browse files
Shrink should not touch max_retries (#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 3da91d5 commit a0d0866

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -785,10 +785,7 @@ static void prepareResizeIndexSettings(
785785
if (type == ResizeType.SHRINK) {
786786
final List<String> nodesToAllocateOn = validateShrinkIndex(currentState, resizeSourceIndex.getName(),
787787
mappingKeys, resizeIntoName, indexSettingsBuilder.build());
788-
indexSettingsBuilder
789-
.put(initialRecoveryIdFilter, Strings.arrayToCommaDelimitedString(nodesToAllocateOn.toArray()))
790-
// we only try once and then give up with a shrink index
791-
.put("index.allocation.max_retries", 1);
788+
indexSettingsBuilder.put(initialRecoveryIdFilter, Strings.arrayToCommaDelimitedString(nodesToAllocateOn.toArray()));
792789
} else if (type == ResizeType.SPLIT) {
793790
validateSplitIndex(currentState, resizeSourceIndex.getName(), mappingKeys, resizeIntoName, indexSettingsBuilder.build());
794791
indexSettingsBuilder.putNull(initialRecoveryIdFilter);

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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
import static org.hamcrest.Matchers.endsWith;
7070
import static org.hamcrest.Matchers.equalTo;
7171
import static org.hamcrest.Matchers.hasToString;
72+
import static org.hamcrest.Matchers.nullValue;
7273

7374
public class MetaDataCreateIndexServiceTests extends ESTestCase {
7475

@@ -263,16 +264,18 @@ public void testPrepareResizeIndexSettings() {
263264
versions.sort(Comparator.comparingLong(l -> l.id));
264265
final Version version = versions.get(0);
265266
final Version upgraded = versions.get(1);
266-
final Settings indexSettings =
267+
final Settings.Builder indexSettingsBuilder =
267268
Settings.builder()
268269
.put("index.version.created", version)
269270
.put("index.version.upgraded", upgraded)
270271
.put("index.similarity.default.type", "BM25")
271272
.put("index.analysis.analyzer.default.tokenizer", "keyword")
272-
.put("index.soft_deletes.enabled", "true")
273-
.build();
273+
.put("index.soft_deletes.enabled", "true");
274+
if (randomBoolean()) {
275+
indexSettingsBuilder.put("index.allocation.max_retries", randomIntBetween(1, 1000));
276+
}
274277
runPrepareResizeIndexSettingsTest(
275-
indexSettings,
278+
indexSettingsBuilder.build(),
276279
Settings.EMPTY,
277280
Collections.emptyList(),
278281
randomBoolean(),
@@ -283,7 +286,7 @@ public void testPrepareResizeIndexSettings() {
283286
settings.get("index.analysis.analyzer.default.tokenizer"),
284287
equalTo("keyword"));
285288
assertThat(settings.get("index.routing.allocation.initial_recovery._id"), equalTo("node1"));
286-
assertThat(settings.get("index.allocation.max_retries"), equalTo("1"));
289+
assertThat(settings.get("index.allocation.max_retries"), nullValue());
287290
assertThat(settings.getAsVersion("index.version.created", null), equalTo(version));
288291
assertThat(settings.getAsVersion("index.version.upgraded", null), equalTo(upgraded));
289292
assertThat(settings.get("index.soft_deletes.enabled"), equalTo("true"));

0 commit comments

Comments
 (0)