Skip to content

Commit 91f09a1

Browse files
committed
CCR: Do not follow if leader does not have soft-deletes (#34767)
We should not create a follower index and abort a follow request if the leader does not have soft-deletes. Moreover, we also should not auto-follow an index if it does not have soft-deletes.
1 parent fb365ea commit 91f09a1

File tree

4 files changed

+34
-14
lines changed

4 files changed

+34
-14
lines changed

x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/AutoFollowCoordinator.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.elasticsearch.common.util.concurrent.AtomicArray;
2727
import org.elasticsearch.common.util.concurrent.CountDown;
2828
import org.elasticsearch.index.Index;
29+
import org.elasticsearch.index.IndexSettings;
2930
import org.elasticsearch.license.LicenseUtils;
3031
import org.elasticsearch.threadpool.ThreadPool;
3132
import org.elasticsearch.xpack.ccr.CcrLicenseChecker;
@@ -371,7 +372,9 @@ static List<Index> getLeaderIndicesToFollow(String remoteCluster,
371372
// has a leader index uuid custom metadata entry that matches with uuid of leaderIndexMetaData variable
372373
// If so then handle it differently: not follow it, but just add an entry to
373374
// AutoFollowMetadata#followedLeaderIndexUUIDs
374-
leaderIndicesToFollow.add(leaderIndexMetaData.getIndex());
375+
if (leaderIndexMetaData.getSettings().getAsBoolean(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), false)) {
376+
leaderIndicesToFollow.add(leaderIndexMetaData.getIndex());
377+
}
375378
}
376379
}
377380
}

x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportPutFollowAction.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ private void createFollowerIndex(
125125
listener.onFailure(new IllegalArgumentException("leader index [" + request.getLeaderIndex() + "] does not exist"));
126126
return;
127127
}
128+
if (leaderIndexMetaData.getSettings().getAsBoolean(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), false) == false) {
129+
listener.onFailure(
130+
new IllegalArgumentException("leader index [" + request.getLeaderIndex() + "] does not have soft deletes enabled"));
131+
}
128132

129133
ActionListener<Boolean> handler = ActionListener.wrap(
130134
result -> {

x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/LocalIndexFollowingIT.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,21 @@ public void testFollowIndex() throws Exception {
6868
ensureEmptyWriteBuffers();
6969
}
7070

71+
public void testDoNotCreateFollowerIfLeaderDoesNotHaveSoftDeletes() throws Exception {
72+
final String leaderIndexSettings = getIndexSettings(2, 0,
73+
singletonMap(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), "false"));
74+
assertAcked(client().admin().indices().prepareCreate("leader-index").setSource(leaderIndexSettings, XContentType.JSON));
75+
ResumeFollowAction.Request followRequest = getResumeFollowRequest();
76+
followRequest.setFollowerIndex("follower-index");
77+
PutFollowAction.Request putFollowRequest = getPutFollowRequest();
78+
putFollowRequest.setLeaderIndex("leader-index");
79+
putFollowRequest.setFollowRequest(followRequest);
80+
IllegalArgumentException error = expectThrows(IllegalArgumentException.class,
81+
() -> client().execute(PutFollowAction.INSTANCE, putFollowRequest).actionGet());
82+
assertThat(error.getMessage(), equalTo("leader index [leader-index] does not have soft deletes enabled"));
83+
assertThat(client().admin().indices().prepareExists("follower-index").get().isExists(), equalTo(false));
84+
}
85+
7186
private String getIndexSettings(final int numberOfShards, final int numberOfReplicas,
7287
final Map<String, String> additionalIndexSettings) throws IOException {
7388
final String settings;

x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/AutoFollowCoordinatorTests.java

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.elasticsearch.common.collect.Tuple;
1616
import org.elasticsearch.common.settings.Settings;
1717
import org.elasticsearch.index.Index;
18+
import org.elasticsearch.index.IndexSettings;
1819
import org.elasticsearch.test.ESTestCase;
1920
import org.elasticsearch.xpack.ccr.CcrLicenseChecker;
2021
import org.elasticsearch.xpack.ccr.action.AutoFollowCoordinator.AutoFollower;
@@ -50,7 +51,7 @@ public void testAutoFollower() {
5051

5152
ClusterState leaderState = ClusterState.builder(new ClusterName("remote"))
5253
.metaData(MetaData.builder().put(IndexMetaData.builder("logs-20190101")
53-
.settings(settings(Version.CURRENT))
54+
.settings(settings(Version.CURRENT).put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), true))
5455
.numberOfShards(1)
5556
.numberOfReplicas(0)))
5657
.build();
@@ -172,7 +173,7 @@ public void testAutoFollowerUpdateClusterStateFailure() {
172173

173174
ClusterState leaderState = ClusterState.builder(new ClusterName("remote"))
174175
.metaData(MetaData.builder().put(IndexMetaData.builder("logs-20190101")
175-
.settings(settings(Version.CURRENT))
176+
.settings(settings(Version.CURRENT).put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), true))
176177
.numberOfShards(1)
177178
.numberOfReplicas(0)))
178179
.build();
@@ -235,7 +236,7 @@ public void testAutoFollowerCreateAndFollowApiCallFailure() {
235236

236237
ClusterState leaderState = ClusterState.builder(new ClusterName("remote"))
237238
.metaData(MetaData.builder().put(IndexMetaData.builder("logs-20190101")
238-
.settings(settings(Version.CURRENT))
239+
.settings(settings(Version.CURRENT).put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), true))
239240
.numberOfShards(1)
240241
.numberOfReplicas(0)))
241242
.build();
@@ -306,7 +307,8 @@ public void testGetLeaderIndicesToFollow() {
306307
for (int i = 0; i < 5; i++) {
307308
Settings.Builder builder = Settings.builder()
308309
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
309-
.put(IndexMetaData.SETTING_INDEX_UUID, "metrics-" + i);
310+
.put(IndexMetaData.SETTING_INDEX_UUID, "metrics-" + i)
311+
.put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), i % 2 == 0);
310312
imdBuilder.put(IndexMetaData.builder("metrics-" + i)
311313
.settings(builder)
312314
.numberOfShards(1)
@@ -324,21 +326,17 @@ public void testGetLeaderIndicesToFollow() {
324326
List<Index> result = AutoFollower.getLeaderIndicesToFollow("remote", autoFollowPattern, leaderState, followerState,
325327
Collections.emptyList());
326328
result.sort(Comparator.comparing(Index::getName));
327-
assertThat(result.size(), equalTo(5));
329+
assertThat(result.size(), equalTo(3));
328330
assertThat(result.get(0).getName(), equalTo("metrics-0"));
329-
assertThat(result.get(1).getName(), equalTo("metrics-1"));
330-
assertThat(result.get(2).getName(), equalTo("metrics-2"));
331-
assertThat(result.get(3).getName(), equalTo("metrics-3"));
332-
assertThat(result.get(4).getName(), equalTo("metrics-4"));
331+
assertThat(result.get(1).getName(), equalTo("metrics-2"));
332+
assertThat(result.get(2).getName(), equalTo("metrics-4"));
333333

334334
List<String> followedIndexUUIDs = Collections.singletonList(leaderState.metaData().index("metrics-2").getIndexUUID());
335335
result = AutoFollower.getLeaderIndicesToFollow("remote", autoFollowPattern, leaderState, followerState, followedIndexUUIDs);
336336
result.sort(Comparator.comparing(Index::getName));
337-
assertThat(result.size(), equalTo(4));
337+
assertThat(result.size(), equalTo(2));
338338
assertThat(result.get(0).getName(), equalTo("metrics-0"));
339-
assertThat(result.get(1).getName(), equalTo("metrics-1"));
340-
assertThat(result.get(2).getName(), equalTo("metrics-3"));
341-
assertThat(result.get(3).getName(), equalTo("metrics-4"));
339+
assertThat(result.get(1).getName(), equalTo("metrics-4"));
342340
}
343341

344342
public void testGetFollowerIndexName() {

0 commit comments

Comments
 (0)