Skip to content

Commit a3baa8f

Browse files
authored
Freezing an index should increase its index settings version (#37813)
When an index is frozen, two index settings are updated (index.frozen and index.search.throttled) but the settings version is left unchanged and does not reflect the settings update. This commit change the TransportFreezeIndexAction so that it also increases the settings version when an index is frozen/unfrozen. This issue has been caught while working on the replication of closed indices (#3388) in which index metadata for a closed index are updated to frozen metadata and this specific assertion tripped.
1 parent 9e7fd8c commit a3baa8f

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/action/TransportFreezeIndexAction.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ public ClusterState execute(ClusterState currentState) {
183183
throw new IllegalStateException("index [" + index.getName() + "] is not closed");
184184
}
185185
final IndexMetaData.Builder imdBuilder = IndexMetaData.builder(meta);
186+
imdBuilder.settingsVersion(meta.getSettingsVersion() + 1);
186187
final Settings.Builder settingsBuilder =
187188
Settings.builder()
188189
.put(currentState.metaData().index(index).getSettings())

x-pack/plugin/core/src/test/java/org/elasticsearch/index/engine/FrozenIndexTests.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import static org.elasticsearch.action.support.WriteRequest.RefreshPolicy.IMMEDIATE;
4646
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
4747
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
48+
import static org.hamcrest.Matchers.equalTo;
4849

4950
public class FrozenIndexTests extends ESSingleNodeTestCase {
5051

@@ -324,4 +325,19 @@ public void testUnfreezeClosedIndex() throws ExecutionException, InterruptedExce
324325
assertEquals(IndexMetaData.State.OPEN,
325326
client().admin().cluster().prepareState().get().getState().metaData().index("idx").getState());
326327
}
328+
329+
public void testFreezeIndexIncreasesIndexSettingsVersion() throws ExecutionException, InterruptedException {
330+
final String index = "test";
331+
createIndex(index, Settings.builder().put("index.number_of_shards", 1).put("index.number_of_replicas", 0).build());
332+
client().prepareIndex(index, "_doc").setSource("field", "value").execute().actionGet();
333+
334+
final long settingsVersion = client().admin().cluster().prepareState().get()
335+
.getState().metaData().index(index).getSettingsVersion();
336+
337+
XPackClient xPackClient = new XPackClient(client());
338+
assertAcked(xPackClient.freeze(new TransportFreezeIndexAction.FreezeRequest(index)));
339+
assertIndexFrozen(index);
340+
assertThat(client().admin().cluster().prepareState().get().getState().metaData().index(index).getSettingsVersion(),
341+
equalTo(settingsVersion + 1));
342+
}
327343
}

0 commit comments

Comments
 (0)