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.
This commit is contained in:
parent
be9df101bf
commit
8b22e297ed
|
@ -32,13 +32,17 @@ final class CloseFollowerIndexStep extends AsyncRetryDuringSnapshotActionStep {
|
|||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -110,6 +110,30 @@ public class CloseFollowerIndexStepTests extends AbstractStepTestCase<CloseFollo
|
|||
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();
|
||||
|
|
|
@ -51,10 +51,35 @@ public class OpenFollowerIndexStepTests extends AbstractStepTestCase<OpenFollowe
|
|||
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();
|
||||
|
@ -95,6 +120,7 @@ public class OpenFollowerIndexStepTests extends AbstractStepTestCase<OpenFollowe
|
|||
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)
|
||||
|
|
Loading…
Reference in New Issue