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

Fail earlier Put Follow requests for closed leader indices #47582

Merged
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,6 +32,7 @@
import org.elasticsearch.index.engine.CommitStats;
import org.elasticsearch.index.engine.Engine;
import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.indices.IndexClosedException;
import org.elasticsearch.license.RemoteClusterLicenseChecker;
import org.elasticsearch.license.XPackLicenseState;
import org.elasticsearch.rest.RestStatus;
Expand Down Expand Up @@ -130,7 +131,10 @@ public void checkRemoteClusterLicenseAndFetchLeaderIndexMetadataAndHistoryUUIDs(
onFailure.accept(new IndexNotFoundException(leaderIndex));
return;
}

if (leaderIndexMetaData.getState() == IndexMetaData.State.CLOSE) {
onFailure.accept(new IndexClosedException(leaderIndexMetaData.getIndex()));
return;
}
final Client remoteClient = client.getRemoteClusterClient(clusterAlias);
hasPrivilegesToFollowIndices(remoteClient, new String[] {leaderIndex}, e -> {
if (e == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
import org.elasticsearch.index.seqno.ReplicationTracker;
import org.elasticsearch.index.seqno.RetentionLeaseActions;
import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.indices.IndexClosedException;
import org.elasticsearch.persistent.PersistentTasksCustomMetaData;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.rest.RestStatus;
Expand Down Expand Up @@ -109,6 +110,7 @@
import java.util.function.BooleanSupplier;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;

import static java.util.Collections.singletonMap;
Expand Down Expand Up @@ -743,6 +745,47 @@ public void testDeleteLeaderIndex() throws Exception {
ensureNoCcrTasks();
}

public void testFollowClosedIndex() {
final String leaderIndex = "test-index";
assertAcked(leaderClient().admin().indices().prepareCreate(leaderIndex)
.setSettings(Settings.builder()
.put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), true)
.build()));
assertAcked(leaderClient().admin().indices().prepareClose(leaderIndex));

final String followerIndex = "follow-test-index";
expectThrows(IndexClosedException.class,
() -> followerClient().execute(PutFollowAction.INSTANCE, putFollow(leaderIndex, followerIndex)).actionGet());
assertFalse(ESIntegTestCase.indexExists(followerIndex, followerClient()));
}

public void testResumeFollowOnClosedIndex() throws Exception {
final String leaderIndex = "test-index";
assertAcked(leaderClient().admin().indices().prepareCreate(leaderIndex)
.setSettings(Settings.builder()
.put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), true)
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
.build()));
ensureLeaderGreen(leaderIndex);

final int nbDocs = randomIntBetween(10, 100);
IntStream.of(nbDocs).forEach(i -> leaderClient().prepareIndex().setIndex(leaderIndex).setSource("field", i).get());

final String followerIndex = "follow-test-index";
PutFollowAction.Response response =
followerClient().execute(PutFollowAction.INSTANCE, putFollow(leaderIndex, followerIndex)).actionGet();
assertTrue(response.isFollowIndexCreated());
assertTrue(response.isFollowIndexShardsAcked());
assertTrue(response.isIndexFollowingStarted());

pauseFollow(followerIndex);
assertAcked(leaderClient().admin().indices().prepareClose(leaderIndex));

expectThrows(IndexClosedException.class, () ->
followerClient().execute(ResumeFollowAction.INSTANCE, resumeFollow(followerIndex)).actionGet());
}

public void testDeleteFollowerIndex() throws Exception {
assertAcked(leaderClient().admin().indices().prepareCreate("index1")
.setSettings(Settings.builder()
Expand Down