Skip to content

ILM open/close steps are noop if idx is open/close #48614

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

Merged
merged 1 commit into from
Oct 29, 2019
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 @@ -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