Skip to content

Commit f7a430c

Browse files
committed
TransportUnfollowAction should increase settings version (#37859)
The TransportUnfollowAction updates the index settings but does not increase the settings version to reflect that change. This issue has been caught while working on the replication of closed indices (#33888). The IndexFollowingIT.testUnfollowIndex() started to fail and this specific assertion tripped. It does not happen on master branch today because index metadata for closed indices are never updated in IndexService instances, but this is something that is going to change with the replication of closed indices.
1 parent b124d65 commit f7a430c

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,18 +105,19 @@ static ClusterState unfollow(String followerIndex, ClusterState current) {
105105
}
106106
}
107107

108-
IndexMetaData.Builder newIMD = IndexMetaData.builder(followerIMD);
109108
// Remove index.xpack.ccr.following_index setting
110109
Settings.Builder builder = Settings.builder();
111110
builder.put(followerIMD.getSettings());
112111
builder.remove(CcrSettings.CCR_FOLLOWING_INDEX_SETTING.getKey());
113112

114-
newIMD.settings(builder);
113+
final IndexMetaData.Builder newIndexMetaData = IndexMetaData.builder(followerIMD);
114+
newIndexMetaData.settings(builder);
115+
newIndexMetaData.settingsVersion(followerIMD.getSettingsVersion() + 1);
115116
// Remove ccr custom metadata
116-
newIMD.removeCustom(Ccr.CCR_CUSTOM_METADATA_KEY);
117+
newIndexMetaData.removeCustom(Ccr.CCR_CUSTOM_METADATA_KEY);
117118

118119
MetaData newMetaData = MetaData.builder(current.metaData())
119-
.put(newIMD)
120+
.put(newIndexMetaData)
120121
.build();
121122
return ClusterState.builder(current)
122123
.metaData(newMetaData)

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@
3030
public class TransportUnfollowActionTests extends ESTestCase {
3131

3232
public void testUnfollow() {
33+
final long settingsVersion = randomNonNegativeLong();
3334
IndexMetaData.Builder followerIndex = IndexMetaData.builder("follow_index")
3435
.settings(settings(Version.CURRENT).put(CcrSettings.CCR_FOLLOWING_INDEX_SETTING.getKey(), true))
36+
.settingsVersion(settingsVersion)
3537
.numberOfShards(1)
3638
.numberOfReplicas(0)
3739
.state(IndexMetaData.State.CLOSE)
@@ -47,6 +49,7 @@ public void testUnfollow() {
4749
IndexMetaData resultIMD = result.metaData().index("follow_index");
4850
assertThat(resultIMD.getSettings().get(CcrSettings.CCR_FOLLOWING_INDEX_SETTING.getKey()), nullValue());
4951
assertThat(resultIMD.getCustomData(Ccr.CCR_CUSTOM_METADATA_KEY), nullValue());
52+
assertThat(resultIMD.getSettingsVersion(), equalTo(settingsVersion + 1));
5053
}
5154

5255
public void testUnfollowIndexOpen() {

0 commit comments

Comments
 (0)