Skip to content

Commit

Permalink
ILM open/close steps are noop if idx is open/close (elastic#48614)
Browse files Browse the repository at this point in the history
The open and close follower steps didn't check if the index is open,
closed respectively, before executing the open/close request.
This changes the steps to check the index state and only perform the
open/close operation if the index is not already open/closed.
  • Loading branch information
andreidan committed Oct 29, 2019
1 parent d0cbbf9 commit 1586002
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,17 @@ void performDuringNoSnapshot(IndexMetaData indexMetaData, ClusterState currentCl
return;
}

CloseIndexRequest closeIndexRequest = new CloseIndexRequest(followerIndex);
getClient().admin().indices().close(closeIndexRequest, ActionListener.wrap(
r -> {
assert r.isAcknowledged() : "close index response is not acknowledged";
listener.onResponse(true);
},
listener::onFailure)
);
if (indexMetaData.getState() == IndexMetaData.State.OPEN) {
CloseIndexRequest closeIndexRequest = new CloseIndexRequest(followerIndex);
getClient().admin().indices().close(closeIndexRequest, ActionListener.wrap(
r -> {
assert r.isAcknowledged() : "close index response is not acknowledged";
listener.onResponse(true);
},
listener::onFailure)
);
} else {
listener.onResponse(true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,17 @@ final class OpenFollowerIndexStep extends AsyncActionStep {
@Override
public void performAction(IndexMetaData indexMetaData, ClusterState currentClusterState,
ClusterStateObserver observer, Listener listener) {
OpenIndexRequest request = new OpenIndexRequest(indexMetaData.getIndex().getName());
getClient().admin().indices().open(request, ActionListener.wrap(
r -> {
assert r.isAcknowledged() : "open index response is not acknowledged";
listener.onResponse(true);
},
listener::onFailure
));
if (indexMetaData.getState() == IndexMetaData.State.CLOSE) {
OpenIndexRequest request = new OpenIndexRequest(indexMetaData.getIndex().getName());
getClient().admin().indices().open(request, ActionListener.wrap(
r -> {
assert r.isAcknowledged() : "open index response is not acknowledged";
listener.onResponse(true);
},
listener::onFailure
));
} else {
listener.onResponse(true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,30 @@ public void onFailure(Exception e) {
Mockito.verifyNoMoreInteractions(indicesClient);
}

public void testCloseFollowerIndexIsNoopForAlreadyClosedIndex() {
IndexMetaData indexMetadata = IndexMetaData.builder("follower-index")
.settings(settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_INDEXING_COMPLETE, "true"))
.putCustom(CCR_METADATA_KEY, Collections.emptyMap())
.state(IndexMetaData.State.CLOSE)
.numberOfShards(1)
.numberOfReplicas(0)
.build();
Client client = Mockito.mock(Client.class);
CloseFollowerIndexStep step = new CloseFollowerIndexStep(randomStepKey(), randomStepKey(), client);
step.performAction(indexMetadata, null, null, new AsyncActionStep.Listener() {
@Override
public void onResponse(boolean complete) {
assertThat(complete, is(true));
}

@Override
public void onFailure(Exception e) {
}
});

Mockito.verifyZeroInteractions(client);
}

@Override
protected CloseFollowerIndexStep createRandomInstance() {
Step.StepKey stepKey = randomStepKey();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,35 @@ protected OpenFollowerIndexStep copyInstance(OpenFollowerIndexStep instance) {
return new OpenFollowerIndexStep(instance.getKey(), instance.getNextStepKey(), instance.getClient());
}

public void testOpenFollowerIndexIsNoopForAlreadyOpenIndex() {
IndexMetaData indexMetadata = IndexMetaData.builder("follower-index")
.settings(settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_INDEXING_COMPLETE, "true"))
.putCustom(CCR_METADATA_KEY, Collections.emptyMap())
.state(IndexMetaData.State.OPEN)
.numberOfShards(1)
.numberOfReplicas(0)
.build();
Client client = Mockito.mock(Client.class);
OpenFollowerIndexStep step = new OpenFollowerIndexStep(randomStepKey(), randomStepKey(), client);
step.performAction(indexMetadata, null, null, new AsyncActionStep.Listener() {
@Override
public void onResponse(boolean complete) {
assertThat(complete, is(true));
}

@Override
public void onFailure(Exception e) {
}
});

Mockito.verifyZeroInteractions(client);
}

public void testOpenFollowingIndex() {
IndexMetaData indexMetadata = IndexMetaData.builder("follower-index")
.settings(settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_INDEXING_COMPLETE, "true"))
.putCustom(CCR_METADATA_KEY, Collections.emptyMap())
.state(IndexMetaData.State.CLOSE)
.numberOfShards(1)
.numberOfReplicas(0)
.build();
Expand Down Expand Up @@ -95,6 +120,7 @@ public void onFailure(Exception e) {
public void testOpenFollowingIndexFailed() {
IndexMetaData indexMetadata = IndexMetaData.builder("follower-index")
.settings(settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_INDEXING_COMPLETE, "true"))
.state(IndexMetaData.State.CLOSE)
.putCustom(CCR_METADATA_KEY, Collections.emptyMap())
.numberOfShards(1)
.numberOfReplicas(0)
Expand Down

0 comments on commit 1586002

Please sign in to comment.