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

Adjust snapshot index resolution behavior to be more intuitive #79670

Merged
merged 26 commits into from
Nov 30, 2021

Conversation

gwbrown
Copy link
Contributor

@gwbrown gwbrown commented Oct 22, 2021

This PR removes the logic used to ensure backwards-compatible behavior
in the Snapshot and Restore APIs and updates the tests to check the new
logic. This is technically a breaking change, but significantly improves
the usability of snapshots in the presence of system indices.

The new behavior is as follows:

  • When creating a snapshot, system indices are not resolved based on the
    indices field in the request. System indices are included or excluded
    using the include_global_state or feature_states fields, defaulting
    to snapshotting all system indices.
  • When restoring a snapshot, system indices cannot be requested using
    the indices field in the request. System indices are included or
    excluded using the include_global_state or feature_states fields,
    defaulting to restoring no system indices.

Fixes #78320


It's worth noting that this is a breaking change, but we deprecated the behavior that won't work anymore a while ago, and I don't think anyone likes the current behavior - it's a mess because of shenanigans we had to pull to maintain BWC.

This PR removes the logic used to ensure backwards-compatible behavior
in the Snapshot and Restore APIs and updates the tests to check the new
logic. This is technically a breaking change, but significantly improves
the usability of snapshots in the presence of system indices.

The new behavior is as follows:
- When creating a snapshot, system indices are not resolved based on the
`indices` field in the request. System indices are included or excluded
using the `include_global_state` or `feature_states` fields, defaulting
to snapshotting all system indices.
- When restoring a snapshot, system indices cannot be requested using
the `indices` field in the request. System indices are included or
excluded using the `include_global_state` or `feature_states` fields,
defaulting to restoring no system indices.
@gwbrown gwbrown added >enhancement >breaking :Distributed Coordination/Snapshot/Restore Anything directly related to the `_snapshot/*` APIs v8.0.0 labels Oct 22, 2021
@elasticmachine elasticmachine added the Team:Distributed (Obsolete) Meta label for distributed team (obsolete). Replaced by Distributed Indexing/Coordination. label Oct 22, 2021
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-distributed (Team:Distributed)

mockLogAppender.stop();
Loggers.removeAppender(LogManager.getLogger("org.elasticsearch.deprecation.snapshots.RestoreService"), mockLogAppender);
IndexNotFoundException ex = expectThrows(
IndexNotFoundException.class,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't love that this results in an IndexNotFoundException vs something more informative - I'd like to improve this and welcome suggestions on what to do instead. Unfortunately, I think anything reasonable here is going to mean more involved changes to RestoreService.

Copy link
Contributor

@williamrandolph williamrandolph left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Production code changes look straightforward. I only have a couple of cleanup nitpicks and suggestions, and it looks like there might be a nontrivial test failure to fix.

@@ -237,7 +227,6 @@ public void testRestoreByFeature() {
// restore indices by feature, with only the regular index named explicitly
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: this comment is now out of date

@@ -484,7 +456,6 @@ public void testRestoreSystemIndicesAsGlobalStateWithEmptyListOfFeatureStates()

// restore regular index, with global state and an empty list of feature states
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: comment is out of date, since we're not specifying the single index anymore

.setFeatureStates(new String[] { randomFrom("none", "NONE") })
.get();
assertThat(restoreResponse.getRestoreInfo().successfulShards(), equalTo(restoreResponse.getRestoreInfo().successfulShards()));
// GWB> What do we check here?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we delete the system index before restoring, then verify that the snapshot didn't recreate it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test case was now a duplicate of another! So I deleted it.

@@ -753,7 +710,6 @@ public void testNoneFeatureStateOnRestore() {

// Restore the snapshot specifying the regular index and "none" for feature states
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: update comment

// Strip system indices out of the list of "available" indices - these should only come from feature states.
List<String> availableNonSystemIndices = new ArrayList<>(snapshotInfo.indices());
{
Set<String> systemIndicesInSnapshot = snapshotInfo.featureStates()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code might make sense as a method on the SnapshotInfo object, but I wouldn't insist on it.

Copy link
Member

@original-brownbear original-brownbear left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM from my end :) Sorry for the delay here!

@gwbrown gwbrown added the auto-backport Automatically create backport pull requests when merged label Nov 30, 2021
@gwbrown gwbrown merged commit 66dc626 into elastic:master Nov 30, 2021
@elasticsearchmachine
Copy link
Collaborator

💚 Backport successful

Status Branch Result
8.0

gwbrown added a commit to gwbrown/elasticsearch that referenced this pull request Nov 30, 2021
…ic#79670)

This PR removes the logic used to ensure backwards-compatible behavior
in the Snapshot and Restore APIs and updates the tests to check the new
logic. This is technically a breaking change, but significantly improves
the usability of snapshots in the presence of system indices.

The new behavior is as follows:
- When creating a snapshot, system indices are not resolved based on the
`indices` field in the request. System indices are included or excluded
using the `include_global_state` or `feature_states` fields, defaulting
to snapshotting all system indices.
- When restoring a snapshot, system indices cannot be requested using
the `indices` field in the request. System indices are included or
excluded using the `include_global_state` or `feature_states` fields,
defaulting to restoring no system indices.
elasticsearchmachine pushed a commit that referenced this pull request Nov 30, 2021
… (#81180)

This PR removes the logic used to ensure backwards-compatible behavior
in the Snapshot and Restore APIs and updates the tests to check the new
logic. This is technically a breaking change, but significantly improves
the usability of snapshots in the presence of system indices.

The new behavior is as follows:
- When creating a snapshot, system indices are not resolved based on the
`indices` field in the request. System indices are included or excluded
using the `include_global_state` or `feature_states` fields, defaulting
to snapshotting all system indices.
- When restoring a snapshot, system indices cannot be requested using
the `indices` field in the request. System indices are included or
excluded using the `include_global_state` or `feature_states` fields,
defaulting to restoring no system indices.
@jrodewig jrodewig added the v8.1.0 label Dec 1, 2021
elasticsearchmachine pushed a commit that referenced this pull request Dec 4, 2021
This commit changes SnapshotsService to throw an error when a system
index is explicitly requested, rather than silently dropping it, and
adds a test to verify that behavior. Note that *only* system indices
requested by full name return an error, requesting e.g. `"indices":
".geo*"` (which would normally resolve to `.geoip_databases`) does not
include its system index and does not error, but requesting `"indices":
".geoip_databases"` *will* return an error. Follow-up to #79670 --- This
should have been part of the original change - I thought we had already
done this, but @jrodewig pointed out to me that it silently dropped
system indices instead.
gwbrown added a commit to gwbrown/elasticsearch that referenced this pull request Dec 4, 2021
…1235)

This commit changes SnapshotsService to throw an error when a system
index is explicitly requested, rather than silently dropping it, and
adds a test to verify that behavior. Note that *only* system indices
requested by full name return an error, requesting e.g. `"indices":
".geo*"` (which would normally resolve to `.geoip_databases`) does not
include its system index and does not error, but requesting `"indices":
".geoip_databases"` *will* return an error. Follow-up to elastic#79670 --- This
should have been part of the original change - I thought we had already
done this, but @jrodewig pointed out to me that it silently dropped
system indices instead.
elasticsearchmachine pushed a commit that referenced this pull request Dec 4, 2021
…81346)

This commit changes SnapshotsService to throw an error when a system
index is explicitly requested, rather than silently dropping it, and
adds a test to verify that behavior. Note that *only* system indices
requested by full name return an error, requesting e.g. `"indices":
".geo*"` (which would normally resolve to `.geoip_databases`) does not
include its system index and does not error, but requesting `"indices":
".geoip_databases"` *will* return an error. Follow-up to #79670 --- This
should have been part of the original change - I thought we had already
done this, but @jrodewig pointed out to me that it silently dropped
system indices instead.
jrodewig added a commit that referenced this pull request Dec 8, 2021
Updates the snapshot and restore docs for #79670.

Closes #81183
jrodewig added a commit to elastic/kibana that referenced this pull request Dec 8, 2021
With elastic/elasticsearch#79670, you can only include system indices in a snapshot using feature states. This updates some references to taking a snapshots of the `.kibana*` system indices.

Relates to elastic/elasticsearch#81226
elasticsearchmachine pushed a commit that referenced this pull request Dec 8, 2021
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Dec 8, 2021
With elastic/elasticsearch#79670, you can only include system indices in a snapshot using feature states. This updates some references to taking a snapshots of the `.kibana*` system indices.

Relates to elastic/elasticsearch#81226
kibanamachine added a commit to elastic/kibana that referenced this pull request Dec 8, 2021
With elastic/elasticsearch#79670, you can only include system indices in a snapshot using feature states. This updates some references to taking a snapshots of the `.kibana*` system indices.

Relates to elastic/elasticsearch#81226

Co-authored-by: James Rodewig <james.rodewig@elastic.co>
TinLe pushed a commit to TinLe/kibana that referenced this pull request Dec 22, 2021
With elastic/elasticsearch#79670, you can only include system indices in a snapshot using feature states. This updates some references to taking a snapshots of the `.kibana*` system indices.

Relates to elastic/elasticsearch#81226
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Automatically create backport pull requests when merged >breaking :Distributed Coordination/Snapshot/Restore Anything directly related to the `_snapshot/*` APIs >enhancement Team:Distributed (Obsolete) Meta label for distributed team (obsolete). Replaced by Distributed Indexing/Coordination. v8.0.0-rc1 v8.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot restore snapshot on new cluster
7 participants