Skip to content

Commit

Permalink
TransportUnfollowAction should increase settings version (#37859)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tlrx committed Jan 25, 2019
1 parent b124d65 commit f7a430c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,19 @@ static ClusterState unfollow(String followerIndex, ClusterState current) {
}
}

IndexMetaData.Builder newIMD = IndexMetaData.builder(followerIMD);
// Remove index.xpack.ccr.following_index setting
Settings.Builder builder = Settings.builder();
builder.put(followerIMD.getSettings());
builder.remove(CcrSettings.CCR_FOLLOWING_INDEX_SETTING.getKey());

newIMD.settings(builder);
final IndexMetaData.Builder newIndexMetaData = IndexMetaData.builder(followerIMD);
newIndexMetaData.settings(builder);
newIndexMetaData.settingsVersion(followerIMD.getSettingsVersion() + 1);
// Remove ccr custom metadata
newIMD.removeCustom(Ccr.CCR_CUSTOM_METADATA_KEY);
newIndexMetaData.removeCustom(Ccr.CCR_CUSTOM_METADATA_KEY);

MetaData newMetaData = MetaData.builder(current.metaData())
.put(newIMD)
.put(newIndexMetaData)
.build();
return ClusterState.builder(current)
.metaData(newMetaData)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@
public class TransportUnfollowActionTests extends ESTestCase {

public void testUnfollow() {
final long settingsVersion = randomNonNegativeLong();
IndexMetaData.Builder followerIndex = IndexMetaData.builder("follow_index")
.settings(settings(Version.CURRENT).put(CcrSettings.CCR_FOLLOWING_INDEX_SETTING.getKey(), true))
.settingsVersion(settingsVersion)
.numberOfShards(1)
.numberOfReplicas(0)
.state(IndexMetaData.State.CLOSE)
Expand All @@ -47,6 +49,7 @@ public void testUnfollow() {
IndexMetaData resultIMD = result.metaData().index("follow_index");
assertThat(resultIMD.getSettings().get(CcrSettings.CCR_FOLLOWING_INDEX_SETTING.getKey()), nullValue());
assertThat(resultIMD.getCustomData(Ccr.CCR_CUSTOM_METADATA_KEY), nullValue());
assertThat(resultIMD.getSettingsVersion(), equalTo(settingsVersion + 1));
}

public void testUnfollowIndexOpen() {
Expand Down

0 comments on commit f7a430c

Please sign in to comment.