diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadata.java b/server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadata.java index d4f3b919a2b22..3daef056f551f 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadata.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadata.java @@ -389,6 +389,7 @@ public static APIBlock readFrom(StreamInput input) throws IOException { private final ActiveShardCount waitForActiveShards; private final ImmutableOpenMap rolloverInfos; private final boolean isSystem; + private final boolean isHidden; private final IndexLongFieldRange timestampRange; @@ -421,6 +422,7 @@ private IndexMetadata( final ActiveShardCount waitForActiveShards, final ImmutableOpenMap rolloverInfos, final boolean isSystem, + final boolean isHidden, final IndexLongFieldRange timestampRange, final int priority, final long creationDate) { @@ -455,6 +457,8 @@ private IndexMetadata( this.waitForActiveShards = waitForActiveShards; this.rolloverInfos = rolloverInfos; this.isSystem = isSystem; + assert isHidden == INDEX_HIDDEN_SETTING.get(settings); + this.isHidden = isHidden; this.timestampRange = timestampRange; this.priority = priority; this.creationDate = creationDate; @@ -938,6 +942,10 @@ public boolean isSystem() { return isSystem; } + public boolean isHidden() { + return isHidden; + } + public int priority() { return priority; } @@ -1318,6 +1326,7 @@ public IndexMetadata build() { waitForActiveShards, rolloverInfos.build(), isSystem, + INDEX_HIDDEN_SETTING.get(settings), timestampRange, IndexMetadata.INDEX_PRIORITY_SETTING.get(settings), settings.getAsLong(SETTING_CREATION_DATE, -1L) diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/Metadata.java b/server/src/main/java/org/elasticsearch/cluster/metadata/Metadata.java index 30c3442d8c0c9..cce12421ee6e0 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/Metadata.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/Metadata.java @@ -1450,7 +1450,7 @@ public Metadata build() { final String name = indexMetadata.getIndex().getName(); boolean added = allIndices.add(name); assert added : "double index named [" + name + "]"; - final boolean visible = IndexMetadata.INDEX_HIDDEN_SETTING.get(indexMetadata.getSettings()) == false; + final boolean visible = indexMetadata.isHidden() == false; if (visible) { visibleIndices.add(name); } diff --git a/server/src/main/java/org/elasticsearch/snapshots/RestoreService.java b/server/src/main/java/org/elasticsearch/snapshots/RestoreService.java index be817c71885ed..f8514a50bdd74 100644 --- a/server/src/main/java/org/elasticsearch/snapshots/RestoreService.java +++ b/server/src/main/java/org/elasticsearch/snapshots/RestoreService.java @@ -1545,7 +1545,7 @@ private static IndexMetadata.Builder restoreOverClosedIndex(IndexMetadata snapsh } private void ensureValidIndexName(ClusterState currentState, IndexMetadata snapshotIndexMetadata, String renamedIndexName) { - final boolean isHidden = IndexMetadata.INDEX_HIDDEN_SETTING.get(snapshotIndexMetadata.getSettings()); + final boolean isHidden = snapshotIndexMetadata.isHidden(); createIndexService.validateIndexName(renamedIndexName, currentState); createIndexService.validateDotIndex(renamedIndexName, isHidden); createIndexService.validateIndexSettings(renamedIndexName, snapshotIndexMetadata.getSettings(), false); diff --git a/server/src/test/java/org/elasticsearch/cluster/metadata/IndexMetadataTests.java b/server/src/test/java/org/elasticsearch/cluster/metadata/IndexMetadataTests.java index 727b43e4cbdce..10c679224b875 100644 --- a/server/src/test/java/org/elasticsearch/cluster/metadata/IndexMetadataTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/metadata/IndexMetadataTests.java @@ -8,6 +8,7 @@ package org.elasticsearch.cluster.metadata; +import org.elasticsearch.Version; import org.elasticsearch.action.admin.indices.rollover.MaxAgeCondition; import org.elasticsearch.action.admin.indices.rollover.MaxDocsCondition; import org.elasticsearch.action.admin.indices.rollover.MaxPrimaryShardSizeCondition; @@ -40,6 +41,7 @@ import java.util.Map; import java.util.Set; +import static org.elasticsearch.cluster.metadata.IndexMetadata.INDEX_HIDDEN_SETTING; import static org.elasticsearch.cluster.metadata.IndexMetadata.parseIndexNameCounter; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; @@ -366,4 +368,24 @@ public void testParseIndexNameCannotFormatNumber() { } } + public void testIsHidden() { + Settings.Builder settings = Settings.builder() + .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, randomIntBetween(1, 8)) + .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) + .put(IndexMetadata.SETTING_VERSION_CREATED, Version.CURRENT); + IndexMetadata indexMetadata = IndexMetadata.builder("test").settings(settings).build(); + assertFalse(indexMetadata.isHidden()); + + settings.put(INDEX_HIDDEN_SETTING.getKey(), "false"); + indexMetadata = IndexMetadata.builder(indexMetadata).settings(settings).build(); + assertFalse(indexMetadata.isHidden()); + + settings.put(INDEX_HIDDEN_SETTING.getKey(), "true"); + indexMetadata = IndexMetadata.builder(indexMetadata).settings(settings).build(); + assertTrue(indexMetadata.isHidden()); + + indexMetadata = IndexMetadata.builder(indexMetadata).build(); + assertTrue(indexMetadata.isHidden()); // preserved if settings unchanged + } + }