-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Drop alloc filters on mount of searchable snapshot #70007
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
Merged
DaveCTurner
merged 2 commits into
elastic:master
from
DaveCTurner:2021-03-05-searchable-snapshot-allocation-filtering
Mar 5, 2021
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
175 changes: 175 additions & 0 deletions
175
...rTest/java/org/elasticsearch/xpack/searchablesnapshots/AllocationFilteringIntegTests.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,175 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| package org.elasticsearch.xpack.searchablesnapshots; | ||
|
|
||
| import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse; | ||
| import org.elasticsearch.common.Nullable; | ||
| import org.elasticsearch.common.Strings; | ||
| import org.elasticsearch.common.settings.Setting; | ||
| import org.elasticsearch.common.settings.Settings; | ||
| import org.elasticsearch.index.IndexSettings; | ||
| import org.elasticsearch.test.ESIntegTestCase; | ||
| import org.elasticsearch.xpack.core.searchablesnapshots.MountSearchableSnapshotAction; | ||
| import org.elasticsearch.xpack.core.searchablesnapshots.MountSearchableSnapshotRequest; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Locale; | ||
|
|
||
| import static org.elasticsearch.cluster.metadata.IndexMetadata.INDEX_ROUTING_EXCLUDE_GROUP_SETTING; | ||
| import static org.elasticsearch.cluster.metadata.IndexMetadata.INDEX_ROUTING_INCLUDE_GROUP_SETTING; | ||
| import static org.elasticsearch.cluster.metadata.IndexMetadata.INDEX_ROUTING_REQUIRE_GROUP_SETTING; | ||
| import static org.elasticsearch.cluster.metadata.IndexMetadata.SETTING_NUMBER_OF_REPLICAS; | ||
| import static org.elasticsearch.cluster.routing.allocation.decider.FilterAllocationDecider.CLUSTER_ROUTING_EXCLUDE_GROUP_SETTING; | ||
| import static org.elasticsearch.index.IndexSettings.INDEX_SOFT_DELETES_SETTING; | ||
| import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; | ||
| import static org.hamcrest.Matchers.equalTo; | ||
|
|
||
| @ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST, numDataNodes = 0) | ||
| public class AllocationFilteringIntegTests extends BaseSearchableSnapshotsIntegTestCase { | ||
|
|
||
| private MountSearchableSnapshotRequest prepareMountRequest( | ||
| Settings.Builder originalIndexSettings, | ||
| Settings.Builder mountedIndexSettings | ||
| ) throws InterruptedException { | ||
|
|
||
| final String fsRepoName = randomAlphaOfLength(10); | ||
| final String indexName = randomAlphaOfLength(10).toLowerCase(Locale.ROOT); | ||
| final String snapshotName = randomAlphaOfLength(10).toLowerCase(Locale.ROOT); | ||
|
|
||
| createRepository(fsRepoName, "fs", Settings.builder().put("location", randomRepoPath())); | ||
| assertAcked( | ||
| prepareCreate( | ||
| indexName, | ||
| Settings.builder() | ||
| .put(INDEX_SOFT_DELETES_SETTING.getKey(), true) | ||
| .put(SETTING_NUMBER_OF_REPLICAS, 0) | ||
| .put(originalIndexSettings.build()) | ||
| ) | ||
| ); | ||
| populateIndex(indexName, 10); | ||
| ensureGreen(indexName); | ||
| createFullSnapshot(fsRepoName, snapshotName); | ||
| assertAcked(client().admin().indices().prepareDelete(indexName)); | ||
|
|
||
| final Settings.Builder indexSettingsBuilder = Settings.builder() | ||
| .put(SearchableSnapshots.SNAPSHOT_CACHE_ENABLED_SETTING.getKey(), true) | ||
| .put(IndexSettings.INDEX_CHECK_ON_STARTUP.getKey(), Boolean.FALSE.toString()) | ||
| .put(mountedIndexSettings.build()); | ||
|
|
||
| return new MountSearchableSnapshotRequest( | ||
| indexName, | ||
| fsRepoName, | ||
| snapshotName, | ||
| indexName, | ||
| indexSettingsBuilder.build(), | ||
| Strings.EMPTY_ARRAY, | ||
| true, | ||
| MountSearchableSnapshotRequest.Storage.FULL_COPY | ||
| ); | ||
| } | ||
|
|
||
| public void testRemovesRequireFilter() throws InterruptedException { | ||
| runTest(INDEX_ROUTING_REQUIRE_GROUP_SETTING, true, null, true); | ||
| } | ||
|
|
||
| public void testRemovesIncludeFilter() throws InterruptedException { | ||
| runTest(INDEX_ROUTING_INCLUDE_GROUP_SETTING, true, null, true); | ||
| } | ||
|
|
||
| public void testRemovesExcludeFilter() throws InterruptedException { | ||
| runTest(INDEX_ROUTING_EXCLUDE_GROUP_SETTING, false, null, true); | ||
| } | ||
|
|
||
| public void testReplacesRequireFilter() throws InterruptedException { | ||
| runTest(INDEX_ROUTING_REQUIRE_GROUP_SETTING, true, INDEX_ROUTING_REQUIRE_GROUP_SETTING, true); | ||
| } | ||
|
|
||
| public void testReplacesIncludeFilter() throws InterruptedException { | ||
| runTest(INDEX_ROUTING_INCLUDE_GROUP_SETTING, true, INDEX_ROUTING_INCLUDE_GROUP_SETTING, true); | ||
| } | ||
|
|
||
| public void testReplacesExcludeFilter() throws InterruptedException { | ||
| runTest(INDEX_ROUTING_EXCLUDE_GROUP_SETTING, false, INDEX_ROUTING_EXCLUDE_GROUP_SETTING, false); | ||
| } | ||
|
|
||
| public void testReplacesIncludeFilterWithExcludeFilter() throws InterruptedException { | ||
| runTest(INDEX_ROUTING_INCLUDE_GROUP_SETTING, true, INDEX_ROUTING_EXCLUDE_GROUP_SETTING, false); | ||
| } | ||
|
|
||
| /** | ||
| * Starts two nodes, allocates the original index on the first node but then excludes that node and verifies that the index can still be | ||
| * mounted and allocated to the other node. | ||
| * | ||
| * @param indexSetting an allocation filter setting to apply to the original index | ||
| * @param mountSetting an (optional) allocation filter setting to apply at mount time | ||
| * @param indexSettingIsPositive whether {@code indexSetting} is positive (i.e. include/require) or negative (i.e. exclude) | ||
| * @param mountSettingIsPositive whether {@code mountSetting} is positive (i.e. include/require) or negative (i.e. exclude) | ||
| */ | ||
| private void runTest( | ||
| Setting.AffixSetting<String> indexSetting, | ||
| boolean indexSettingIsPositive, | ||
| @Nullable Setting.AffixSetting<String> mountSetting, | ||
| boolean mountSettingIsPositive | ||
| ) throws InterruptedException { | ||
| final List<String> nodes = internalCluster().startNodes(2); | ||
|
|
||
| // apply an index setting to restrict the original index to node 0 | ||
| final Settings.Builder indexSettings = Settings.builder() | ||
| .put(indexSetting.getConcreteSettingForNamespace("_name").getKey(), nodes.get(indexSettingIsPositive ? 0 : 1)); | ||
|
|
||
| final Settings.Builder mountSettings = Settings.builder(); | ||
| if (mountSetting != null) { | ||
| // apply an index setting to restrict the mounted index to node 1 | ||
| mountSettings.put(mountSetting.getConcreteSettingForNamespace("_name").getKey(), nodes.get(mountSettingIsPositive ? 1 : 0)); | ||
| } | ||
|
|
||
| final MountSearchableSnapshotRequest mountRequest = prepareMountRequest(indexSettings, mountSettings); | ||
|
|
||
| // block allocation to node 0 at the cluster level | ||
| assertAcked( | ||
| client().admin() | ||
| .cluster() | ||
| .prepareUpdateSettings() | ||
| .setPersistentSettings( | ||
| Settings.builder() | ||
| .put(CLUSTER_ROUTING_EXCLUDE_GROUP_SETTING.getConcreteSettingForNamespace("_name").getKey(), nodes.get(0)) | ||
| ) | ||
| ); | ||
|
|
||
| // mount snapshot and verify it is allocated as expected | ||
| final RestoreSnapshotResponse restoreSnapshotResponse = client().execute(MountSearchableSnapshotAction.INSTANCE, mountRequest) | ||
| .actionGet(); | ||
| assertThat(restoreSnapshotResponse.getRestoreInfo().failedShards(), equalTo(0)); | ||
| ensureGreen(mountRequest.mountedIndexName()); | ||
|
|
||
| final Settings mountedIndexSettings = client().admin() | ||
| .indices() | ||
| .prepareGetSettings(mountRequest.mountedIndexName()) | ||
| .get() | ||
| .getIndexToSettings() | ||
| .get(mountRequest.mountedIndexName()); | ||
|
|
||
| if (mountSetting != null) { | ||
| assertTrue(mountedIndexSettings.toString(), mountSetting.getConcreteSettingForNamespace("_name").exists(mountedIndexSettings)); | ||
| } | ||
|
|
||
| if (indexSetting != mountSetting) { | ||
| assertFalse(mountedIndexSettings.toString(), indexSetting.getConcreteSettingForNamespace("_name").exists(mountedIndexSettings)); | ||
| } | ||
|
|
||
| assertAcked( | ||
| client().admin() | ||
| .cluster() | ||
| .prepareUpdateSettings() | ||
| .setPersistentSettings( | ||
| Settings.builder().putNull(CLUSTER_ROUTING_EXCLUDE_GROUP_SETTING.getConcreteSettingForNamespace("_name").getKey()) | ||
| ) | ||
| ); | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice to also check that the setting is not actually set (when it is different from
mountSetting).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, done in 1bcdbc2.