Skip to content

Commit 50fdbf0

Browse files
ILM Freeze step retry when not acknowledged (#53287)
A freeze operation can partially fail in multiple places, including the close verification step. This left the index in an unfrozen but partially closed state. Now throw an exception to retry the freeze step instead.
1 parent 21d428b commit 50fdbf0

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/FreezeStep.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
package org.elasticsearch.xpack.core.ilm;
77

8+
import org.elasticsearch.ElasticsearchException;
89
import org.elasticsearch.action.ActionListener;
910
import org.elasticsearch.client.Client;
1011
import org.elasticsearch.cluster.ClusterState;
@@ -26,6 +27,11 @@ public FreezeStep(StepKey key, StepKey nextStepKey, Client client) {
2627
public void performDuringNoSnapshot(IndexMetaData indexMetaData, ClusterState currentState, Listener listener) {
2728
getClient().admin().indices().execute(FreezeIndexAction.INSTANCE,
2829
new FreezeRequest(indexMetaData.getIndex().getName()),
29-
ActionListener.wrap(response -> listener.onResponse(true), listener::onFailure));
30+
ActionListener.wrap(response -> {
31+
if (response.isAcknowledged() == false) {
32+
throw new ElasticsearchException("freeze index request failed to be acknowledged");
33+
}
34+
listener.onResponse(true);
35+
}, listener::onFailure));
3036
}
3137
}

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/FreezeStepTests.java

+36-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.elasticsearch.client.IndicesAdminClient;
1616
import org.elasticsearch.cluster.metadata.IndexMetaData;
1717
import org.elasticsearch.protocol.xpack.frozen.FreezeRequest;
18+
import org.elasticsearch.protocol.xpack.frozen.FreezeResponse;
1819
import org.elasticsearch.xpack.core.frozen.action.FreezeIndexAction;
1920
import org.elasticsearch.xpack.core.ilm.Step.StepKey;
2021
import org.junit.Before;
@@ -86,7 +87,7 @@ public void testFreeze() {
8687
assertNotNull(request);
8788
assertEquals(1, request.indices().length);
8889
assertEquals(indexMetaData.getIndex().getName(), request.indices()[0]);
89-
listener.onResponse(null);
90+
listener.onResponse(new FreezeResponse(true, true));
9091
return null;
9192
}).when(indicesClient).execute(Mockito.any(), Mockito.any(), Mockito.any());
9293

@@ -151,4 +152,38 @@ public void onFailure(Exception e) {
151152

152153
assertThat(exceptionThrown.get(), equalTo(true));
153154
}
155+
156+
public void testNotAcknowledged() {
157+
IndexMetaData indexMetaData = IndexMetaData.builder(randomAlphaOfLength(10)).settings(settings(Version.CURRENT))
158+
.numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)).build();
159+
160+
AdminClient adminClient = Mockito.mock(AdminClient.class);
161+
IndicesAdminClient indicesClient = Mockito.mock(IndicesAdminClient.class);
162+
163+
Mockito.when(client.admin()).thenReturn(adminClient);
164+
Mockito.when(adminClient.indices()).thenReturn(indicesClient);
165+
Mockito.doAnswer(invocation -> {
166+
@SuppressWarnings("unchecked")
167+
ActionListener<AcknowledgedResponse> listener = (ActionListener<AcknowledgedResponse>) invocation.getArguments()[2];
168+
listener.onResponse(new FreezeResponse(false, false));
169+
return null;
170+
}).when(indicesClient).execute(Mockito.any(), Mockito.any(), Mockito.any());
171+
172+
SetOnce<Boolean> exceptionThrown = new SetOnce<>();
173+
FreezeStep step = createRandomInstance();
174+
step.performAction(indexMetaData, null, null, new AsyncActionStep.Listener() {
175+
@Override
176+
public void onResponse(boolean complete) {
177+
throw new AssertionError("Unexpected method call");
178+
}
179+
180+
@Override
181+
public void onFailure(Exception e) {
182+
assertEquals("freeze index request failed to be acknowledged", e.getMessage());
183+
exceptionThrown.set(true);
184+
}
185+
});
186+
187+
assertThat(exceptionThrown.get(), equalTo(true));
188+
}
154189
}

0 commit comments

Comments
 (0)