-
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
Conversation
|
Pinging @elastic/es-distributed (Team:Distributed) |
original-brownbear
left a comment
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: maybe use Arrays.asList() or some other thing that's JDK8 compatible to make the backport cleaner? :)
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
| IllegalArgumentException.class, | ||
| () -> client().admin().indices().prepareResizeIndex("mounted-index", "cloned-index").setResizeType(ResizeType.CLONE).get() | ||
| ); | ||
| assertThat( |
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.
nit: just assertEquals? (here and in other similar spots)
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.
I do prefer the error messages returned by assertThat than assertEquals, if that's ok.
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.
Ah sure :) didn't even know they were different :D
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.
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.
Choose a reason for hiding this comment
The 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?
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.
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.
Choose a reason for hiding this comment
The 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?
| .prepareResizeIndex("mounted-index", "shrunk-index") | ||
| .setResizeType(ResizeType.SHRINK) | ||
| .setSettings( | ||
| Settings.builder() |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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_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.
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)
DaveCTurner
left a comment
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.
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)