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

Prevent snapshots to be mounted as system indices #61517

Merged
merged 5 commits into from
Aug 31, 2020

Conversation

tlrx
Copy link
Member

@tlrx tlrx commented Aug 25, 2020

System and hidden indices can be snapshotted and are therefore potential candidates to be mounted as searchable snapshot indices. As of today nothing prevents a snapshot to be mounted under an index name starting with . and this can lead to conflicting situations because searchable snapshot indices are read-only and Elasticsearch expects some system indices to be writable; because searchable snapshot indices will soon use an internal system index (#60522) to speed up recoveries and we should prevent the system index to be itself a searchable snapshot index (leading to some deadlock situation for recovery).

This pull request introduces a changes to prevent snapshots to be mounted under a system index.

@tlrx tlrx added >bug :Distributed/Snapshot/Restore Anything directly related to the `_snapshot/*` APIs v8.0.0 v7.10.0 labels Aug 25, 2020
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-distributed (:Distributed/Snapshot/Restore)

Copy link
Contributor

@fcofdez fcofdez left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -132,6 +133,11 @@ protected void masterOperation(
) {
SearchableSnapshots.ensureValidLicense(licenseState);

final String mountedIndexName = request.mountedIndexName();
if (mountedIndexName.charAt(0) == '.') {
Copy link
Member

@jaymode jaymode Aug 25, 2020

Choose a reason for hiding this comment

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

I think it would be best to pull in the SystemIndices class since we're in a transport action. We can bind the instance in Node and make it available for guice to inject. Then a simple modification to the the SystemIndices class could be made that adds a method to check the name (currently there is a method that takes an Index object but only looks at the name) against the defined set of system indices.

The primary reason for this is users could have data indices in 7.x that start with a . so we shouldn't break that for them restrict them from being able to use this feature on that data.

Copy link
Contributor

Choose a reason for hiding this comment

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

There are also hidden indices that start with a dot (e.g. .watcher-history*), which there's no reason to prevent being backed by a searchable snapshot. Using the SystemIndices class would avoid that issue as well.

Copy link
Member

Choose a reason for hiding this comment

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

I merged #61540 which adds the method in SystemIndices to check a string name without needing the Index object.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks everybody. I'm waiting for #60522 to be merged and I'll update this PR.

@dakrone
Copy link
Member

dakrone commented Aug 25, 2020

As a drive-by comment, I'm slightly concerned that this will trip up users that are trying to mount data stream indices manually as searchable snapshots. Data stream backing indices start with a . and we don't currently have a way to add existing indices to a data stream, so I'm concerned a user that is manually closing an index and restoring it as a searchable version won't be able to do that.

Maybe it's not a big deal, but at the very least we should document this somewhere?

@tlrx
Copy link
Member Author

tlrx commented Aug 27, 2020

@jaymode @gwbrown @dakrone Thanks for your valuable feedback. I reverted some changes so that we are now more permissive and only prevent registered system indices to be mounted as searchable snapshots. I think this addresses your concerns.

@tlrx tlrx requested review from jaymode and gwbrown August 27, 2020 11:38
Copy link
Member

@jaymode jaymode left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks @tlrx

@tlrx tlrx requested a review from fcofdez August 31, 2020 07:26
Copy link
Contributor

@fcofdez fcofdez left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -132,6 +136,11 @@ protected void masterOperation(
) {
SearchableSnapshots.ensureValidLicense(licenseState);

final String mountedIndexName = request.mountedIndexName();
if (systemIndices.isSystemIndex(mountedIndexName)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks better than the previous approach 👍

.setSettings(Settings.builder().put(IndexMetadata.SETTING_INDEX_HIDDEN, isHidden).build())
);

final int nbDocs = scaledRandomIntBetween(0, 100);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: we could use createAndPopulateIndex instead of manually creating and populating the index?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes we can - I pushed 3e173cb

@tlrx
Copy link
Member Author

tlrx commented Aug 31, 2020

@elasticmachine run elasticsearch-ci/packaging-sample-windows

1 similar comment
@tlrx
Copy link
Member Author

tlrx commented Aug 31, 2020

@elasticmachine run elasticsearch-ci/packaging-sample-windows

@tlrx tlrx merged commit d16fa2d into elastic:master Aug 31, 2020
@tlrx tlrx deleted the prevent-system-indices-to-be-mounted branch August 31, 2020 14:23
@tlrx
Copy link
Member Author

tlrx commented Aug 31, 2020

Thanks all!

tlrx added a commit that referenced this pull request Sep 1, 2020
System indices can be snapshotted and are therefore potential candidates 
to be mounted as searchable snapshot indices. As of today nothing 
prevents a snapshot to be mounted under an index name starting with . 
and this can lead to conflicting situations because searchable snapshot 
indices are read-only and Elasticsearch expects some system indices 
to be writable; because searchable snapshot indices will soon use an 
internal system index (#60522) to speed up recoveries and we should
prevent the system index to be itself a searchable snapshot index 
(leading to some deadlock situation for recovery).

This commit introduces a changes to prevent snapshots to be mounted 
as a system index.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug :Distributed/Snapshot/Restore Anything directly related to the `_snapshot/*` APIs Team:Distributed Meta label for distributed team v7.10.0 v8.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants