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.
This commit is contained in:
Tanguy Leroux 2019-01-25 16:31:26 +01:00 committed by GitHub
parent 85acc11ef7
commit f1f54e0f61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 4 deletions

View File

@ -105,18 +105,19 @@ public class TransportUnfollowAction extends TransportMasterNodeAction<UnfollowA
}
}
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)

View File

@ -30,8 +30,10 @@ import static org.hamcrest.Matchers.nullValue;
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)
@ -47,6 +49,7 @@ public class TransportUnfollowActionTests extends ESTestCase {
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() {