Skip to content

Commit 2ac9ad9

Browse files
committed
Increment settings version when upgrading index (#34566)
When we upgrade an index, we set the settings version upgraded setting. This should be considered a settings change, and therefore we need to increment the settings version. This commit addresses that.
1 parent cbd0406 commit 2ac9ad9

File tree

2 files changed

+60
-6
lines changed

2 files changed

+60
-6
lines changed

server/src/main/java/org/elasticsearch/cluster/metadata/MetaDataUpdateSettingsService.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -259,12 +259,16 @@ public ClusterState execute(ClusterState currentState) {
259259
IndexMetaData indexMetaData = metaDataBuilder.get(index);
260260
if (indexMetaData != null) {
261261
if (Version.CURRENT.equals(indexMetaData.getCreationVersion()) == false) {
262-
// No reason to pollute the settings, we didn't really upgrade anything
263-
metaDataBuilder.put(IndexMetaData.builder(indexMetaData)
264-
.settings(Settings.builder().put(indexMetaData.getSettings())
265-
.put(IndexMetaData.SETTING_VERSION_UPGRADED, entry.getValue().v1())
266-
)
267-
);
262+
// no reason to pollute the settings, we didn't really upgrade anything
263+
metaDataBuilder.put(
264+
IndexMetaData
265+
.builder(indexMetaData)
266+
.settings(
267+
Settings
268+
.builder()
269+
.put(indexMetaData.getSettings())
270+
.put(IndexMetaData.SETTING_VERSION_UPGRADED, entry.getValue().v1()))
271+
.settingsVersion(1 + indexMetaData.getSettingsVersion()));
268272
}
269273
}
270274
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.elasticsearch.cluster.metadata;
21+
22+
import org.elasticsearch.Version;
23+
import org.elasticsearch.common.settings.Settings;
24+
import org.elasticsearch.test.ESSingleNodeTestCase;
25+
26+
import static org.hamcrest.Matchers.equalTo;
27+
28+
public class UpgradeIndexSettingsIT extends ESSingleNodeTestCase {
29+
30+
@Override
31+
protected boolean forbidPrivateIndexSettings() {
32+
return false;
33+
}
34+
35+
public void testSettingsVersion() {
36+
createIndex(
37+
"test",
38+
Settings
39+
.builder()
40+
.put(IndexMetaData.SETTING_INDEX_VERSION_CREATED.getKey(), Version.CURRENT.minimumIndexCompatibilityVersion())
41+
.build());
42+
final long settingsVersion =
43+
client().admin().cluster().prepareState().get().getState().metaData().index("test").getSettingsVersion();
44+
client().admin().indices().prepareUpgrade("test").get();
45+
assertThat(
46+
client().admin().cluster().prepareState().get().getState().metaData().index("test").getSettingsVersion(),
47+
equalTo(1 + settingsVersion));
48+
}
49+
50+
}

0 commit comments

Comments
 (0)