Skip to content
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

ILM Freeze step retry when not acknowledged #53287

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
package org.elasticsearch.xpack.core.ilm;

import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.client.Client;
import org.elasticsearch.cluster.ClusterState;
Expand All @@ -26,7 +27,12 @@ public FreezeStep(StepKey key, StepKey nextStepKey, Client client) {
public void performDuringNoSnapshot(IndexMetaData indexMetaData, ClusterState currentState, Listener listener) {
getClient().admin().indices().execute(FreezeIndexAction.INSTANCE,
new FreezeRequest(indexMetaData.getIndex().getName()).masterNodeTimeout(getMasterTimeout(currentState)),
ActionListener.wrap(response -> listener.onResponse(true), listener::onFailure));
ActionListener.wrap(response -> {
if (response.isAcknowledged() == false) {
throw new ElasticsearchException("freeze index request failed to be acknowledged");
}
listener.onResponse(true);
}, listener::onFailure));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.elasticsearch.action.support.master.AcknowledgedResponse;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.protocol.xpack.frozen.FreezeRequest;
import org.elasticsearch.protocol.xpack.frozen.FreezeResponse;
import org.elasticsearch.xpack.core.frozen.action.FreezeIndexAction;
import org.elasticsearch.xpack.core.ilm.Step.StepKey;
import org.mockito.Mockito;
Expand Down Expand Up @@ -73,7 +74,7 @@ public void testFreeze() {
assertNotNull(request);
assertEquals(1, request.indices().length);
assertEquals(indexMetaData.getIndex().getName(), request.indices()[0]);
listener.onResponse(null);
listener.onResponse(new FreezeResponse(true, true));
return null;
}).when(indicesClient).execute(Mockito.any(), Mockito.any(), Mockito.any());

Expand Down Expand Up @@ -127,4 +128,32 @@ public void onFailure(Exception e) {

assertThat(exceptionThrown.get(), equalTo(true));
}

public void testNotAcknowledged() {
IndexMetaData indexMetaData = getIndexMetaData();

Mockito.doAnswer(invocation -> {
@SuppressWarnings("unchecked")
ActionListener<AcknowledgedResponse> listener = (ActionListener<AcknowledgedResponse>) invocation.getArguments()[2];
listener.onResponse(new FreezeResponse(false, false));
return null;
}).when(indicesClient).execute(Mockito.any(), Mockito.any(), Mockito.any());

SetOnce<Boolean> exceptionThrown = new SetOnce<>();
FreezeStep step = createRandomInstance();
step.performAction(indexMetaData, emptyClusterState(), null, new AsyncActionStep.Listener() {
@Override
public void onResponse(boolean complete) {
throw new AssertionError("Unexpected method call");
}

@Override
public void onFailure(Exception e) {
assertEquals("freeze index request failed to be acknowledged", e.getMessage());
exceptionThrown.set(true);
}
});

assertThat(exceptionThrown.get(), equalTo(true));
}
}