-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Prevent searchable snapshots indices to be shrunk/split #75227
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
Changes from all commits
3a4b958
c5b050d
66196ca
95a2f5c
c3a2997
022627b
c0be556
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| /* | ||
| * 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.indices.shrink.ResizeType; | ||
| import org.elasticsearch.common.settings.Settings; | ||
| import org.elasticsearch.index.IndexModule; | ||
| import org.elasticsearch.repositories.fs.FsRepository; | ||
| import org.elasticsearch.test.ESIntegTestCase; | ||
| import org.elasticsearch.xpack.cluster.routing.allocation.DataTierAllocationDecider; | ||
| import org.elasticsearch.xpack.core.DataTier; | ||
| import org.junit.After; | ||
| import org.junit.Before; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import static org.elasticsearch.cluster.metadata.IndexMetadata.INDEX_NUMBER_OF_REPLICAS_SETTING; | ||
| import static org.elasticsearch.cluster.metadata.IndexMetadata.INDEX_NUMBER_OF_ROUTING_SHARDS_SETTING; | ||
| import static org.elasticsearch.cluster.metadata.IndexMetadata.INDEX_NUMBER_OF_SHARDS_SETTING; | ||
| import static org.elasticsearch.index.IndexSettings.INDEX_SOFT_DELETES_SETTING; | ||
| import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; | ||
| import static org.elasticsearch.xpack.core.searchablesnapshots.MountSearchableSnapshotRequest.Storage; | ||
| import static org.hamcrest.Matchers.equalTo; | ||
|
|
||
| @ESIntegTestCase.ClusterScope(numDataNodes = 1) | ||
| public class SearchableSnapshotsResizeIntegTests extends BaseFrozenSearchableSnapshotsIntegTestCase { | ||
|
|
||
| @Before | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need for this annotation I think, this is automatically called since the annotation is on the parent?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At least on my Intellij 2021.1.3 this is required for integ tests for JUnit to correctly set up the internal test cluster. |
||
| @Override | ||
| public void setUp() throws Exception { | ||
| super.setUp(); | ||
| createRepository("repository", FsRepository.TYPE); | ||
| assertAcked( | ||
| prepareCreate( | ||
| "index", | ||
| Settings.builder() | ||
| .put(INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), 0) | ||
| .put(INDEX_NUMBER_OF_SHARDS_SETTING.getKey(), 2) | ||
| .put(INDEX_NUMBER_OF_ROUTING_SHARDS_SETTING.getKey(), 4) | ||
| .put(INDEX_SOFT_DELETES_SETTING.getKey(), true) | ||
| ) | ||
| ); | ||
| indexRandomDocs("index", scaledRandomIntBetween(0, 1_000)); | ||
| createSnapshot("repository", "snapshot", List.of("index")); | ||
| assertAcked(client().admin().indices().prepareDelete("index")); | ||
| mountSnapshot("repository", "snapshot", "index", "mounted-index", Settings.EMPTY, randomFrom(Storage.values())); | ||
| ensureGreen("mounted-index"); | ||
| } | ||
|
|
||
| @After | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need for this annotation I think, this is automatically called since the annotation is on the parent? |
||
| @Override | ||
| public void tearDown() throws Exception { | ||
| assertAcked(client().admin().indices().prepareDelete("mounted-*")); | ||
| assertAcked(client().admin().cluster().prepareDeleteSnapshot("repository", "snapshot").get()); | ||
| assertAcked(client().admin().cluster().prepareDeleteRepository("repository")); | ||
| super.tearDown(); | ||
| } | ||
|
|
||
| public void testShrinkSearchableSnapshotIndex() { | ||
| final IllegalArgumentException exception = expectThrows( | ||
| IllegalArgumentException.class, | ||
| () -> client().admin() | ||
| .indices() | ||
| .prepareResizeIndex("mounted-index", "shrunk-index") | ||
| .setResizeType(ResizeType.SHRINK) | ||
| .setSettings(indexSettingsNoReplicas(1).build()) | ||
| .get() | ||
| ); | ||
| assertThat(exception.getMessage(), equalTo("can't shrink searchable snapshot index [mounted-index]")); | ||
| } | ||
|
|
||
| public void testSplitSearchableSnapshotIndex() { | ||
| final IllegalArgumentException exception = expectThrows( | ||
| IllegalArgumentException.class, | ||
| () -> client().admin() | ||
| .indices() | ||
| .prepareResizeIndex("mounted-index", "split-index") | ||
| .setResizeType(ResizeType.SPLIT) | ||
| .setSettings(indexSettingsNoReplicas(4).build()) | ||
| .get() | ||
| ); | ||
| assertThat(exception.getMessage(), equalTo("can't split searchable snapshot index [mounted-index]")); | ||
| } | ||
|
|
||
| public void testCloneSearchableSnapshotIndex() { | ||
| IllegalArgumentException exception = expectThrows( | ||
| IllegalArgumentException.class, | ||
| () -> client().admin().indices().prepareResizeIndex("mounted-index", "cloned-index").setResizeType(ResizeType.CLONE).get() | ||
| ); | ||
| assertThat( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: just
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do prefer the error messages returned by
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah sure :) didn't even know they were different :D
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm with Tanguy on this one, I find the argument order for |
||
| exception.getMessage(), | ||
| equalTo("can't clone searchable snapshot index [mounted-index]; setting [index.store.type] should be overridden") | ||
| ); | ||
|
|
||
| exception = expectThrows( | ||
| IllegalArgumentException.class, | ||
| () -> client().admin() | ||
| .indices() | ||
| .prepareResizeIndex("mounted-index", "cloned-index") | ||
| .setResizeType(ResizeType.CLONE) | ||
| .setSettings(Settings.builder().putNull(IndexModule.INDEX_STORE_TYPE_SETTING.getKey()).build()) | ||
| .get() | ||
| ); | ||
| assertThat( | ||
| exception.getMessage(), | ||
| equalTo("can't clone searchable snapshot index [mounted-index]; setting [index.recovery.type] should be overridden") | ||
| ); | ||
|
|
||
| assertAcked( | ||
| client().admin() | ||
| .indices() | ||
| .prepareResizeIndex("mounted-index", "cloned-index") | ||
| .setResizeType(ResizeType.CLONE) | ||
| .setSettings( | ||
| Settings.builder() | ||
| .putNull(IndexModule.INDEX_STORE_TYPE_SETTING.getKey()) | ||
| .putNull(IndexModule.INDEX_RECOVERY_TYPE_SETTING.getKey()) | ||
| .put(DataTierAllocationDecider.INDEX_ROUTING_PREFER, DataTier.DATA_HOT) | ||
| .put(INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), 0) | ||
| .build() | ||
| ) | ||
| ); | ||
| ensureGreen("cloned-index"); | ||
| assertAcked(client().admin().indices().prepareDelete("cloned-index")); | ||
| } | ||
| } | ||
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.
Could we move
SearchableSnapshotsConstants#SNAPSHOT_DIRECTORY_FACTORY_KEYandSearchableSnapshotsConstants#isSearchableSnapshotStoretoserverrather than just using the literal"snapshot"throughout? Either that or add an independent constant inserverand then add a static constructor too.e.x.c.searchablesnapshots.SearchableSnapshotsConstantsto assert that the constant inserveris equal toSNAPSHOT_DIRECTORY_FACTORY_KEY?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.
Yes, I'll do something like this in a follow-up (it touches places outside of this pull request too)