-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Add system data streams to feature state snapshots #75902
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
Merged
williamrandolph
merged 21 commits into
elastic:master
from
williamrandolph:system-data-streams-in-snapshots
Aug 16, 2021
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
e5ecfd0
Add system data streams to feature state snapshots
williamrandolph 46871d1
Spotless formatting
williamrandolph 1df9725
Don't pass system data streams through index name resolution
williamrandolph de6cd83
Don't add no-op features to snapshots
williamrandolph faeac56
Merge branch 'master' into system-data-streams-in-snapshots
williamrandolph 9083f5d
Refactor and clean up
williamrandolph bb6385f
Checkstyle and spotless
williamrandolph 8e8eb55
Add test todo
williamrandolph f1984b5
Hook in system data streams for snapshot restoration
williamrandolph 6df6980
Merge branch 'master' into system-data-streams-in-snapshots
williamrandolph 2461699
Clean up test class
williamrandolph 7ecba14
Merge branch 'master' into system-data-streams-in-snapshots
williamrandolph 33daff6
Built automaton in constructor
williamrandolph 59fb331
Remove low-value comment
williamrandolph a44a442
server/src/main
williamrandolph b578ed2
Merge branch 'master' into system-data-streams-in-snapshots
williamrandolph 231d094
Merge branch 'master' into system-data-streams-in-snapshots
williamrandolph f573027
Cleanup from PR review
williamrandolph 9c09345
Apply spotless formatting
williamrandolph 2d1bee5
Merge branch 'master' into system-data-streams-in-snapshots
williamrandolph 2a84b43
Improve warn logging
williamrandolph File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,6 @@ | |
| package org.elasticsearch.datastreams; | ||
|
|
||
| import org.elasticsearch.action.DocWriteRequest; | ||
| import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse; | ||
| import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse; | ||
| import org.elasticsearch.action.admin.indices.get.GetIndexResponse; | ||
| import org.elasticsearch.action.index.IndexResponse; | ||
|
|
@@ -20,6 +19,7 @@ | |
| import org.elasticsearch.plugins.Plugin; | ||
| import org.elasticsearch.plugins.SystemIndexPlugin; | ||
| import org.elasticsearch.snapshots.AbstractSnapshotIntegTestCase; | ||
| import org.elasticsearch.snapshots.SnapshotInfo; | ||
| import org.elasticsearch.snapshots.mockstore.MockRepository; | ||
| import org.elasticsearch.threadpool.ThreadPool; | ||
| import org.elasticsearch.xpack.core.action.CreateDataStreamAction; | ||
|
|
@@ -35,8 +35,11 @@ | |
| import java.util.Map; | ||
|
|
||
| import static org.elasticsearch.datastreams.SystemDataStreamSnapshotIT.SystemDataStreamTestPlugin.SYSTEM_DATA_STREAM_NAME; | ||
| import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; | ||
| import static org.hamcrest.Matchers.arrayWithSize; | ||
| import static org.hamcrest.Matchers.empty; | ||
| import static org.hamcrest.Matchers.hasSize; | ||
| import static org.hamcrest.Matchers.not; | ||
| import static org.hamcrest.Matchers.oneOf; | ||
|
|
||
| public class SystemDataStreamSnapshotIT extends AbstractSnapshotIntegTestCase { | ||
|
|
@@ -82,12 +85,91 @@ public void testSystemDataStreamSnapshotIT() throws Exception { | |
| assertTrue(response.getDataStreams().get(0).getDataStream().isSystem()); | ||
| } | ||
|
|
||
| CreateSnapshotResponse createSnapshotResponse = client().admin() | ||
| assertSuccessful( | ||
| client().admin() | ||
| .cluster() | ||
| .prepareCreateSnapshot(REPO, SNAPSHOT) | ||
| .setWaitForCompletion(true) | ||
| .setIncludeGlobalState(false) | ||
| .execute() | ||
| ); | ||
|
|
||
| // We have to delete the data stream directly, as the feature reset API doesn't clean up system data streams yet | ||
| // See https://github.com/elastic/elasticsearch/issues/75818 | ||
| { | ||
| DeleteDataStreamAction.Request request = new DeleteDataStreamAction.Request(new String[] { SYSTEM_DATA_STREAM_NAME }); | ||
| AcknowledgedResponse response = client().execute(DeleteDataStreamAction.INSTANCE, request).get(); | ||
| assertTrue(response.isAcknowledged()); | ||
| } | ||
|
|
||
| { | ||
| GetIndexResponse indicesRemaining = client().admin().indices().prepareGetIndex().addIndices("_all").get(); | ||
| assertThat(indicesRemaining.indices(), arrayWithSize(0)); | ||
| } | ||
|
|
||
| RestoreSnapshotResponse restoreSnapshotResponse = client().admin() | ||
| .cluster() | ||
| .prepareCreateSnapshot(REPO, SNAPSHOT) | ||
| .prepareRestoreSnapshot(REPO, SNAPSHOT) | ||
| .setWaitForCompletion(true) | ||
| .setIncludeGlobalState(false) | ||
| .setRestoreGlobalState(false) | ||
| .get(); | ||
| assertEquals(restoreSnapshotResponse.getRestoreInfo().totalShards(), restoreSnapshotResponse.getRestoreInfo().successfulShards()); | ||
|
|
||
| { | ||
| GetDataStreamAction.Request request = new GetDataStreamAction.Request(new String[] { SYSTEM_DATA_STREAM_NAME }); | ||
| GetDataStreamAction.Response response = client().execute(GetDataStreamAction.INSTANCE, request).get(); | ||
| assertThat(response.getDataStreams(), hasSize(1)); | ||
| assertTrue(response.getDataStreams().get(0).getDataStream().isSystem()); | ||
| } | ||
| } | ||
|
|
||
| public void testSystemDataStreamInFeatureState() throws Exception { | ||
| Path location = randomRepoPath(); | ||
| createRepository(REPO, "fs", location); | ||
|
|
||
| { | ||
| CreateDataStreamAction.Request request = new CreateDataStreamAction.Request(SYSTEM_DATA_STREAM_NAME); | ||
| final AcknowledgedResponse response = client().execute(CreateDataStreamAction.INSTANCE, request).get(); | ||
| assertTrue(response.isAcknowledged()); | ||
| } | ||
|
|
||
| // Index a doc so that a concrete backing index will be created | ||
| IndexResponse indexToDataStreamResponse = client().prepareIndex(SYSTEM_DATA_STREAM_NAME) | ||
| .setId("42") | ||
| .setSource("{ \"@timestamp\": \"2099-03-08T11:06:07.000Z\", \"name\": \"my-name\" }", XContentType.JSON) | ||
| .setOpType(DocWriteRequest.OpType.CREATE) | ||
| .execute() | ||
| .actionGet(); | ||
| assertThat(indexToDataStreamResponse.status().getStatus(), oneOf(200, 201)); | ||
|
|
||
| // Index a doc so that a concrete backing index will be created | ||
| IndexResponse indexResponse = client().prepareIndex("my-index") | ||
| .setId("42") | ||
| .setSource("{ \"name\": \"my-name\" }", XContentType.JSON) | ||
| .setOpType(DocWriteRequest.OpType.CREATE) | ||
| .execute() | ||
| .get(); | ||
| assertThat(indexResponse.status().getStatus(), oneOf(200, 201)); | ||
|
|
||
| { | ||
| GetDataStreamAction.Request request = new GetDataStreamAction.Request(new String[] { SYSTEM_DATA_STREAM_NAME }); | ||
| GetDataStreamAction.Response response = client().execute(GetDataStreamAction.INSTANCE, request).get(); | ||
| assertThat(response.getDataStreams(), hasSize(1)); | ||
| assertTrue(response.getDataStreams().get(0).getDataStream().isSystem()); | ||
| } | ||
|
|
||
| SnapshotInfo snapshotInfo = assertSuccessful( | ||
| client().admin() | ||
| .cluster() | ||
| .prepareCreateSnapshot(REPO, SNAPSHOT) | ||
| .setIndices("my-index") | ||
| .setFeatureStates(SystemDataStreamTestPlugin.class.getSimpleName()) | ||
| .setWaitForCompletion(true) | ||
| .setIncludeGlobalState(false) | ||
| .execute() | ||
| ); | ||
|
|
||
| assertThat(snapshotInfo.dataStreams(), not(empty())); | ||
|
|
||
| // We have to delete the data stream directly, as the feature reset API doesn't clean up system data streams yet | ||
| // See https://github.com/elastic/elasticsearch/issues/75818 | ||
|
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. Added a comment to the linked issue so we remember to clean up the places we have to work around this in tests. No action required here, just noting. |
||
|
|
@@ -97,6 +179,8 @@ public void testSystemDataStreamSnapshotIT() throws Exception { | |
| assertTrue(response.isAcknowledged()); | ||
| } | ||
|
|
||
| assertAcked(client().admin().indices().prepareDelete("my-index")); | ||
|
|
||
| { | ||
| GetIndexResponse indicesRemaining = client().admin().indices().prepareGetIndex().addIndices("_all").get(); | ||
| assertThat(indicesRemaining.indices(), arrayWithSize(0)); | ||
|
|
@@ -106,7 +190,8 @@ public void testSystemDataStreamSnapshotIT() throws Exception { | |
| .cluster() | ||
| .prepareRestoreSnapshot(REPO, SNAPSHOT) | ||
| .setWaitForCompletion(true) | ||
| .setRestoreGlobalState(false) | ||
| .setIndices("my-index") | ||
| .setFeatureStates(SystemDataStreamTestPlugin.class.getSimpleName()) | ||
| .get(); | ||
| assertEquals(restoreSnapshotResponse.getRestoreInfo().totalShards(), restoreSnapshotResponse.getRestoreInfo().successfulShards()); | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.