Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache index.hidden setting #78612

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ public static APIBlock readFrom(StreamInput input) throws IOException {
private final ActiveShardCount waitForActiveShards;
private final ImmutableOpenMap<String, RolloverInfo> rolloverInfos;
private final boolean isSystem;
private final boolean isHidden;

private final IndexLongFieldRange timestampRange;

Expand Down Expand Up @@ -417,6 +418,7 @@ private IndexMetadata(
final ActiveShardCount waitForActiveShards,
final ImmutableOpenMap<String, RolloverInfo> rolloverInfos,
final boolean isSystem,
final boolean isHidden,
final IndexLongFieldRange timestampRange) {

this.index = index;
Expand Down Expand Up @@ -449,6 +451,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;
assert numberOfShards * routingFactor == routingNumShards : routingNumShards + " must be a multiple of " + numberOfShards;
}
Expand Down Expand Up @@ -930,6 +934,10 @@ public boolean isSystem() {
return isSystem;
}

public boolean isHidden() {
return isHidden;
}

public static Builder builder(String index) {
return new Builder(index);
}
Expand Down Expand Up @@ -1309,7 +1317,8 @@ public IndexMetadata build() {
waitForActiveShards,
rolloverInfos.build(),
isSystem,
timestampRange);
INDEX_HIDDEN_SETTING.get(settings),
timestampRange);
}

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
}

}