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

Get snapshots support for multiple repositories #42090

Merged
merged 40 commits into from
Jun 19, 2019
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
80edff1
Get snapshots support for multiple repositories
May 10, 2019
c2e24f2
Run on GENERIC thread pool
May 23, 2019
94e60dd
Use GroupedActionListener
May 23, 2019
3bbea57
Use fs repository
May 23, 2019
94f4d63
Remove supplier
May 23, 2019
845ed5f
Add assertions
May 23, 2019
c00640f
Use GetSnapshotsResponse.Response in GroupedActionListener
May 23, 2019
3963638
Use unmodifiableMap in the constructor
May 23, 2019
e8ec22c
Checkstyle
May 23, 2019
0e956ae
Moar checkstyle
May 24, 2019
71f6aa1
BWC
May 24, 2019
adaa376
Fix indentation
May 24, 2019
2a49439
Merge branch 'master' into multi_repos
May 24, 2019
85b2953
Add docs
May 24, 2019
5fa3d16
Fix docs
May 24, 2019
3a8743f
Fix FullClusterRestartIT
May 24, 2019
ec8bce7
Fix tests
May 28, 2019
12a563d
Checkstyle
May 28, 2019
62a7acc
Moar fixes
May 28, 2019
94d3a5b
Fix
May 28, 2019
068324a
Merge branch 'master' into multi_repos
May 28, 2019
cf0bbda
Fix merge
May 28, 2019
04d494b
Merge branch 'master' into multi_repos
May 31, 2019
ff4c89b
More fixes
May 31, 2019
16c69ac
Fix yml
May 31, 2019
265f18e
s3 yml fixes
May 31, 2019
be898f4
Revert reformatting
Jun 3, 2019
33cad5e
Use ActionRunnable
Jun 3, 2019
ca011e3
buildSimpleSnapshotInfos
Jun 3, 2019
752fbc8
Merge branch 'master' into multi_repos
Jun 14, 2019
84430b2
Fix typo lost during force push
Jun 14, 2019
6582508
Change cat shapshots docs
Jun 14, 2019
35a171f
\n
Jun 14, 2019
dc64cea
Fix "Get snapshot info with metadata"
Jun 14, 2019
682d583
readFrom should throw UnsupportedOpExc
Jun 17, 2019
f19ff8f
Add exceptions as cause in cat API
Jun 17, 2019
e2f2e9a
Make repositories final
Jun 17, 2019
e441032
Fix GetRepositoriesResponse streamable and get rid of rid of readFrom
Jun 17, 2019
c6435a1
Fix HDFS yml tests
Jun 17, 2019
77a7328
Merge branch 'master' into multi_repos
Jun 18, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ static Request createSnapshot(CreateSnapshotRequest createSnapshotRequest) throw

static Request getSnapshots(GetSnapshotsRequest getSnapshotsRequest) {
RequestConverters.EndpointBuilder endpointBuilder = new RequestConverters.EndpointBuilder().addPathPartAsIs("_snapshot")
.addPathPart(getSnapshotsRequest.repository());
.addCommaSeparatedPathParts(getSnapshotsRequest.repositories());
String endpoint;
if (getSnapshotsRequest.snapshots().length == 0) {
endpoint = endpointBuilder.addPathPart("_all").build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@
import org.elasticsearch.repositories.fs.FsRepository;
import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.snapshots.RestoreInfo;
import org.mockito.internal.util.collections.Sets;

import java.io.IOException;
import java.util.Collections;
import java.util.stream.Collectors;

import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;

public class SnapshotIT extends ESRestHighLevelClientTestCase {
Expand Down Expand Up @@ -155,39 +155,48 @@ public void testCreateSnapshot() throws IOException {
}

public void testGetSnapshots() throws IOException {
String repository = "test_repository";
String repository1 = "test_repository1";
String repository2 = "test_repository2";
String snapshot1 = "test_snapshot1";
String snapshot2 = "test_snapshot2";

AcknowledgedResponse putRepositoryResponse = createTestRepository(repository, FsRepository.TYPE, "{\"location\": \".\"}");
AcknowledgedResponse putRepositoryResponse =
createTestRepository(repository1, FsRepository.TYPE, "{\"location\": \"loc1\"}");
assertTrue(putRepositoryResponse.isAcknowledged());

CreateSnapshotRequest createSnapshotRequest1 = new CreateSnapshotRequest(repository, snapshot1);
AcknowledgedResponse putRepositoryResponse2 =
createTestRepository(repository2, FsRepository.TYPE, "{\"location\": \"loc2\"}");
assertTrue(putRepositoryResponse2.isAcknowledged());

CreateSnapshotRequest createSnapshotRequest1 = new CreateSnapshotRequest(repository1, snapshot1);
createSnapshotRequest1.waitForCompletion(true);
CreateSnapshotResponse putSnapshotResponse1 = createTestSnapshot(createSnapshotRequest1);
CreateSnapshotRequest createSnapshotRequest2 = new CreateSnapshotRequest(repository, snapshot2);
CreateSnapshotRequest createSnapshotRequest2 = new CreateSnapshotRequest(repository2, snapshot2);
createSnapshotRequest2.waitForCompletion(true);
CreateSnapshotResponse putSnapshotResponse2 = createTestSnapshot(createSnapshotRequest2);
// check that the request went ok without parsing JSON here. When using the high level client, check acknowledgement instead.
assertEquals(RestStatus.OK, putSnapshotResponse1.status());
assertEquals(RestStatus.OK, putSnapshotResponse2.status());

GetSnapshotsRequest request;
if (randomBoolean()) {
request = new GetSnapshotsRequest(repository);
} else if (randomBoolean()) {
request = new GetSnapshotsRequest(repository, new String[] {"_all"});
GetSnapshotsRequest request = new GetSnapshotsRequest(
randomFrom(new String[]{"_all"}, new String[]{"*"}, new String[]{repository1, repository2}),
randomFrom(new String[]{"_all"}, new String[]{"*"}, new String[]{snapshot1, snapshot2})
);
request.ignoreUnavailable(true);

} else {
request = new GetSnapshotsRequest(repository, new String[] {snapshot1, snapshot2});
}
GetSnapshotsResponse response = execute(request, highLevelClient().snapshot()::get, highLevelClient().snapshot()::getAsync);

assertEquals(2, response.getSnapshots().size());
assertThat(response.getSnapshots().stream().map((s) -> s.snapshotId().getName()).collect(Collectors.toList()),
contains("test_snapshot1", "test_snapshot2"));
assertThat(response.isFailed(), is(false));
assertThat(response.getRepositories(), equalTo(Sets.newSet(repository1, repository2)));

assertThat(response.getSnapshots(repository1), hasSize(1));
assertThat(response.getSnapshots(repository1).get(0).snapshotId().getName(), equalTo(snapshot1));

assertThat(response.getSnapshots(repository2), hasSize(1));
assertThat(response.getSnapshots(repository2).get(0).snapshotId().getName(), equalTo(snapshot2));
}


public void testSnapshotsStatus() throws IOException {
String testRepository = "test";
String testSnapshot = "snapshot";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@

import java.io.IOException;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
Expand Down Expand Up @@ -148,15 +147,16 @@ public void testCreateSnapshot() throws IOException {

public void testGetSnapshots() {
Map<String, String> expectedParams = new HashMap<>();
String repository = RequestConvertersTests.randomIndicesNames(1, 1)[0];
String repository1 = randomAlphaOfLength(10);
String repository2 = randomAlphaOfLength(10);
String snapshot1 = "snapshot1-" + randomAlphaOfLengthBetween(2, 5).toLowerCase(Locale.ROOT);
String snapshot2 = "snapshot2-" + randomAlphaOfLengthBetween(2, 5).toLowerCase(Locale.ROOT);

String endpoint = String.format(Locale.ROOT, "/_snapshot/%s/%s,%s", repository, snapshot1, snapshot2);
String endpoint = String.format(Locale.ROOT, "/_snapshot/%s,%s/%s,%s", repository1, repository2, snapshot1, snapshot2);

GetSnapshotsRequest getSnapshotsRequest = new GetSnapshotsRequest();
getSnapshotsRequest.repository(repository);
getSnapshotsRequest.snapshots(Arrays.asList(snapshot1, snapshot2).toArray(new String[0]));
getSnapshotsRequest.repositories(repository1, repository2);
getSnapshotsRequest.snapshots(new String[]{snapshot1, snapshot2});
RequestConvertersTests.setRandomMasterTimeout(getSnapshotsRequest, expectedParams);

if (randomBoolean()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ public void testSnapshotGetSnapshots() throws IOException {
// end::get-snapshots-request

// tag::get-snapshots-request-repositoryName
request.repository(repositoryName); // <1>
request.repositories(repositoryName); // <1>
// end::get-snapshots-request-repositoryName

// tag::get-snapshots-request-snapshots
Expand All @@ -616,7 +616,7 @@ public void testSnapshotGetSnapshots() throws IOException {
// end::get-snapshots-execute

// tag::get-snapshots-response
List<SnapshotInfo> snapshotsInfos = response.getSnapshots();
List<SnapshotInfo> snapshotsInfos = response.getSnapshots(repositoryName);
SnapshotInfo snapshotInfo = snapshotsInfos.get(0);
RestStatus restStatus = snapshotInfo.status(); // <1>
SnapshotId snapshotId = snapshotInfo.snapshotId(); // <2>
Expand Down
23 changes: 19 additions & 4 deletions docs/reference/cat/snapshots.asciidoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[[cat-snapshots]]
== cat snapshots
== Cat single repository snapshots
Copy link
Contributor

Choose a reason for hiding this comment

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

I wouldn't create a separate heading for single repo vs multi repo, but instead revise the existing docs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not exactly, re-writing the existing docs, I've made it like this 6582508


The `snapshots` command shows all snapshots that belong to a specific repository.
To find a list of available repositories to query, the command `/_cat/repositories` can be used.
Expand All @@ -18,9 +18,9 @@ Which looks like:

[source,txt]
--------------------------------------------------
id status start_epoch start_time end_epoch end_time duration indices successful_shards failed_shards total_shards
snap1 FAILED 1445616705 18:11:45 1445616978 18:16:18 4.6m 1 4 1 5
snap2 SUCCESS 1445634298 23:04:58 1445634672 23:11:12 6.2m 2 10 0 10
id repository status start_epoch start_time end_epoch end_time duration indices successful_shards failed_shards total_shards
snap1 repo1 FAILED 1445616705 18:11:45 1445616978 18:16:18 4.6m 1 4 1 5
snap2 repo1 SUCCESS 1445634298 23:04:58 1445634672 23:11:12 6.2m 2 10 0 10
--------------------------------------------------
// TESTRESPONSE[s/FAILED/SUCCESS/ s/14456\d+/\\d+/ s/\d+(\.\d+)?(m|s|ms)/\\d+(\\.\\d+)?(m|s|ms)/]
// TESTRESPONSE[s/\d+:\d+:\d+/\\d+:\\d+:\\d+/]
Expand All @@ -32,3 +32,18 @@ Each snapshot contains information about when it was started and stopped.
Start and stop timestamps are available in two formats.
The `HH:MM:SS` output is simply for quick human consumption.
The epoch time retains more information, including date, and is machine sortable if the snapshot process spans days.

== Cat multiple repositories snapshots
It is also possible to get the list of snapshots from multiple repositories.
Here are some examples:

[source,js]
--------------------------------------------------
GET /_cat/snapshots/_all
GET /_cat/snapshots/repo1,repo2
GET /_cat/snapshots/repo*
--------------------------------------------------
// CONSOLE
// TEST[skip:no repo2]

Please note that if one of the repositories fails during the request you will get an exception instead of the table.
5 changes: 5 additions & 0 deletions docs/reference/migration/migrate_8_0/snapshots.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@

// end::notable-breaking-changes[]

[float]
=== Get snapshots response format is changed
It's possible to get snapshots from multiple repositories in one go. The response format has changed
and now contains separate response for each repository. See <<modules-snapshots>> for more information.

[float]
==== Deprecated node level compress setting removed

Expand Down
10 changes: 10 additions & 0 deletions docs/reference/modules/snapshots.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,16 @@ that setting `verbose` to `false` will omit all other information about the snap
such as status information, the number of snapshotted shards, etc. The default
value of the `verbose` parameter is `true`.

It is also possible to retrieve snapshots for multiple repositories in one go, for example:
andrershov marked this conversation as resolved.
Show resolved Hide resolved
[source,sh]
-----------------------------------
GET /_snapshot/_all
GET /_snapshot/my_backup,my_fs_backup
GET /_snapshot/my*/snap*
-----------------------------------
// CONSOLE
// TEST[skip:no my_fs_backup]

A currently running snapshot can be retrieved using the following command:

[source,sh]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void testUrlRepository() throws Exception {
.prepareGetSnapshots("test-repo")
.setSnapshots("test-snap")
.get()
.getSnapshots()
.getSnapshots("test-repo")
.get(0)
.state();
assertThat(state, equalTo(SnapshotState.SUCCESS));
Expand Down Expand Up @@ -116,16 +116,16 @@ public void testUrlRepository() throws Exception {

logger.info("--> list available shapshots");
GetSnapshotsResponse getSnapshotsResponse = client.admin().cluster().prepareGetSnapshots("url-repo").get();
assertThat(getSnapshotsResponse.getSnapshots(), notNullValue());
assertThat(getSnapshotsResponse.getSnapshots().size(), equalTo(1));
assertThat(getSnapshotsResponse.getSnapshots("url-repo"), notNullValue());
assertThat(getSnapshotsResponse.getSnapshots("url-repo").size(), equalTo(1));

logger.info("--> delete snapshot");
AcknowledgedResponse deleteSnapshotResponse = client.admin().cluster().prepareDeleteSnapshot("test-repo", "test-snap").get();
assertAcked(deleteSnapshotResponse);

logger.info("--> list available shapshot again, no snapshots should be returned");
getSnapshotsResponse = client.admin().cluster().prepareGetSnapshots("url-repo").get();
assertThat(getSnapshotsResponse.getSnapshots(), notNullValue());
assertThat(getSnapshotsResponse.getSnapshots().size(), equalTo(0));
assertThat(getSnapshotsResponse.getSnapshots("url-repo"), notNullValue());
assertThat(getSnapshotsResponse.getSnapshots("url-repo").size(), equalTo(0));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ teardown:

---
"Restore with repository-url using http://":
- skip:
version: " - 7.9.99"
reason: "8.0 changes get snapshots response format"

# Ensure that the URL repository is registered
- do:
Expand All @@ -126,9 +129,9 @@ teardown:
repository: repository-url
snapshot: snapshot-one,snapshot-two

- is_true: snapshots
- match: { snapshots.0.state : SUCCESS }
- match: { snapshots.1.state : SUCCESS }
- is_true: responses.0.snapshots
- match: { responses.0.snapshots.0.state : SUCCESS }
- match: { responses.0.snapshots.1.state : SUCCESS }

# Delete the index
- do:
Expand Down Expand Up @@ -174,6 +177,9 @@ teardown:

---
"Restore with repository-url using file://":
- skip:
version: " - 7.9.99"
reason: "8.0 changes get snapshots response format"

# Ensure that the URL repository is registered
- do:
Expand All @@ -188,9 +194,9 @@ teardown:
repository: repository-file
snapshot: snapshot-one,snapshot-two

- is_true: snapshots
- match: { snapshots.0.state : SUCCESS }
- match: { snapshots.1.state : SUCCESS }
- is_true: responses.0.snapshots
- match: { responses.0.snapshots.0.state : SUCCESS }
- match: { responses.0.snapshots.1.state : SUCCESS }

# Delete the index
- do:
Expand Down Expand Up @@ -236,13 +242,18 @@ teardown:

---
"Get a non existing snapshot":
- skip:
version: " - 7.9.99"
reason: "8.0 changes get snapshots response format"

- do:
catch: /snapshot_missing_exception/
snapshot.get:
repository: repository-url
snapshot: missing

- is_true: responses.0.error
- match: { responses.0.error.type: snapshot_missing_exception }

---
"Delete a non existing snapshot":

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ setup:

---
"Snapshot/Restore with repository-azure":
- skip:
version: " - 7.9.99"
reason: "8.0 changes get snapshots response format"

# Get repository
- do:
Expand Down Expand Up @@ -121,9 +124,9 @@ setup:
repository: repository
snapshot: snapshot-one,snapshot-two

- is_true: snapshots
- match: { snapshots.0.state : SUCCESS }
- match: { snapshots.1.state : SUCCESS }
- is_true: responses.0.snapshots
- match: { responses.0.snapshots.0.state: SUCCESS }
- match: { responses.0.snapshots.1.state: SUCCESS }

# Delete the index
- do:
Expand Down Expand Up @@ -203,13 +206,18 @@ setup:

---
"Get a non existing snapshot":
- skip:
version: " - 7.9.99"
reason: "8.0 changes get snapshots response format"

- do:
catch: /snapshot_missing_exception/
snapshot.get:
repository: repository
snapshot: missing

- is_true: responses.0.error
- match: { responses.0.error.type: snapshot_missing_exception }

---
"Delete a non existing snapshot":

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ setup:

---
"Snapshot/Restore with repository-gcs":
- skip:
version: " - 7.9.99"
reason: "8.0 changes get snapshots response format"

# Get repository
- do:
Expand Down Expand Up @@ -134,9 +137,9 @@ setup:
repository: repository
snapshot: snapshot-one,snapshot-two

- is_true: snapshots
- match: { snapshots.0.state : SUCCESS }
- match: { snapshots.1.state : SUCCESS }
- is_true: responses.0.snapshots
- match: { responses.0.snapshots.0.state : SUCCESS }
- match: { responses.0.snapshots.1.state : SUCCESS }

# Delete the index
- do:
Expand Down Expand Up @@ -213,13 +216,18 @@ setup:

---
"Get a non existing snapshot":
- skip:
version: " - 7.9.99"
reason: "8.0 changes get snapshots response format"

- do:
catch: /snapshot_missing_exception/
snapshot.get:
repository: repository
snapshot: missing

- is_true: responses.0.error
- match: { responses.0.error.type: snapshot_missing_exception }

---
"Delete a non existing snapshot":

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void testSimpleWorkflow() {
.prepareGetSnapshots("test-repo")
.setSnapshots("test-snap")
.get()
.getSnapshots()
.getSnapshots("test-repo")
.get(0)
.state(),
equalTo(SnapshotState.SUCCESS));
Expand Down
Loading