Prevent searchable snapshots indices to be shrunk/split#75227
Prevent searchable snapshots indices to be shrunk/split#75227tlrx merged 7 commits intoelastic:masterfrom
Conversation
|
Pinging @elastic/es-distributed (Team:Distributed) |
original-brownbear
left a comment
There was a problem hiding this comment.
LGTM, just a few optional nits :)
| static void validateCloneIndex(ClusterState state, String sourceIndex, String targetIndexName, Settings targetIndexSettings) { | ||
| IndexMetadata sourceMetadata = validateResize(state, sourceIndex, targetIndexName, targetIndexSettings); | ||
| if ("snapshot".equals(INDEX_STORE_TYPE_SETTING.get(sourceMetadata.getSettings()))) { | ||
| for (Setting<?> nonCloneableSetting : List.of(INDEX_STORE_TYPE_SETTING, INDEX_RECOVERY_TYPE_SETTING)) { |
There was a problem hiding this comment.
NIT: maybe use Arrays.asList() or some other thing that's JDK8 compatible to make the backport cleaner? :)
| IllegalArgumentException.class, | ||
| () -> client().admin().indices().prepareResizeIndex("mounted-index", "cloned-index").setResizeType(ResizeType.CLONE).get() | ||
| ); | ||
| assertThat( |
There was a problem hiding this comment.
nit: just assertEquals? (here and in other similar spots)
There was a problem hiding this comment.
I do prefer the error messages returned by assertThat than assertEquals, if that's ok.
There was a problem hiding this comment.
Ah sure :) didn't even know they were different :D
There was a problem hiding this comment.
I'm with Tanguy on this one, I find the argument order for assertEquals(expected, actual) confusing since it's the opposite to assertThat(actual, expectation).
| @ESIntegTestCase.ClusterScope(numDataNodes = 1) | ||
| public class SearchableSnapshotsResizeIntegTests extends BaseFrozenSearchableSnapshotsIntegTestCase { | ||
|
|
||
| @Before |
There was a problem hiding this comment.
No need for this annotation I think, this is automatically called since the annotation is on the parent?
There was a problem hiding this comment.
At least on my Intellij 2021.1.3 this is required for integ tests for JUnit to correctly set up the internal test cluster.
| ensureGreen("mounted-index"); | ||
| } | ||
|
|
||
| @After |
There was a problem hiding this comment.
No need for this annotation I think, this is automatically called since the annotation is on the parent?
| .prepareResizeIndex("mounted-index", "shrunk-index") | ||
| .setResizeType(ResizeType.SHRINK) | ||
| .setSettings( | ||
| Settings.builder() |
There was a problem hiding this comment.
NIT: I added org.elasticsearch.snapshots.AbstractSnapshotIntegTestCase#indexSettingsNoReplicas at one point for this because it's such a common kind of setting in tests :)
There was a problem hiding this comment.
Forgot about this one, thanks!
| .setResizeType(ResizeType.SPLIT) | ||
| .setSettings( | ||
| Settings.builder() | ||
| .put(INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), 0) |
There was a problem hiding this comment.
NIT: I added org.elasticsearch.snapshots.AbstractSnapshotIntegTestCase#indexSettingsNoReplicas at one point for this because it's such a common kind of setting in tests :)
DaveCTurner
left a comment
There was a problem hiding this comment.
I left a suggestion about avoiding repeated string literals, otherwise LGTM2.
| */ | ||
| static List<String> validateShrinkIndex(ClusterState state, String sourceIndex, String targetIndexName, Settings targetIndexSettings) { | ||
| IndexMetadata sourceMetadata = validateResize(state, sourceIndex, targetIndexName, targetIndexSettings); | ||
| if ("snapshot".equals(INDEX_STORE_TYPE_SETTING.get(sourceMetadata.getSettings()))) { |
There was a problem hiding this comment.
Could we move SearchableSnapshotsConstants#SNAPSHOT_DIRECTORY_FACTORY_KEY and SearchableSnapshotsConstants#isSearchableSnapshotStore to server rather than just using the literal "snapshot" throughout? Either that or add an independent constant in server and then add a static constructor to o.e.x.c.searchablesnapshots.SearchableSnapshotsConstants to assert that the constant in server is equal to SNAPSHOT_DIRECTORY_FACTORY_KEY?
There was a problem hiding this comment.
Yes, I'll do something like this in a follow-up (it touches places outside of this pull request too)
DaveCTurner
left a comment
There was a problem hiding this comment.
A follow-up is fine with me; LGTM
|
Thanks Armin and David! |
Today if we try to shrink or to split a searchable snapshot index using the Resize API a new index will be created but can't be assigned, and even if it was assigned it won't work as the number of shards can't be changed and must always match the number of shards from the snapshot. This commit adds some verification to prevent a snapshot backed indices to be resized and if an attempt is made, throw a better error message. Note that cloning is supported since elastic#56595 and in this change we make sure that it is only used to convert the searchable snapshot index back to a regular index. Relates elastic#74977 (comment)
) Today if we try to shrink or to split a searchable snapshot index using the Resize API a new index will be created but can't be assigned, and even if it was assigned it won't work as the number of shards can't be changed and must always match the number of shards from the snapshot. This commit adds some verification to prevent a snapshot backed indices to be resized and if an attempt is made, throw a better error message. Note that cloning is supported since #56595 and in this change we make sure that it is only used to convert the searchable snapshot index back to a regular index. Relates #74977 (comment)
Today if we try to shrink or to split a searchable snapshot index using the Resize API a new index will be created but can't be assigned, and even if it was assigned it won't work as the number of shards can't be changed and must always match the number of shards from the snapshot.
This pull request adds some verification to prevent a snapshot backed indices to be resized and if an attempt is made, throw a better error message.
Note that cloning is supported since #56595 and in this pull request we make sure that it is only used to convert the searchable snapshot index back to a regular index.
Relates #74977 (comment)