Search in sources :

Example 6 with SnapshotInfo

use of org.elasticsearch.snapshots.SnapshotInfo in project elasticsearch by elastic.

the class GetSnapshotsResponse method readFrom.

@Override
public void readFrom(StreamInput in) throws IOException {
    super.readFrom(in);
    int size = in.readVInt();
    List<SnapshotInfo> builder = new ArrayList<>();
    for (int i = 0; i < size; i++) {
        builder.add(new SnapshotInfo(in));
    }
    snapshots = Collections.unmodifiableList(builder);
}
Also used : SnapshotInfo(org.elasticsearch.snapshots.SnapshotInfo) ArrayList(java.util.ArrayList)

Example 7 with SnapshotInfo

use of org.elasticsearch.snapshots.SnapshotInfo in project elasticsearch by elastic.

the class TransportGetSnapshotsAction method masterOperation.

@Override
protected void masterOperation(final GetSnapshotsRequest request, ClusterState state, final ActionListener<GetSnapshotsResponse> listener) {
    try {
        final String repository = request.repository();
        List<SnapshotInfo> snapshotInfoBuilder = new ArrayList<>();
        final Map<String, SnapshotId> allSnapshotIds = new HashMap<>();
        final List<SnapshotId> currentSnapshotIds = new ArrayList<>();
        for (SnapshotInfo snapshotInfo : snapshotsService.currentSnapshots(repository)) {
            SnapshotId snapshotId = snapshotInfo.snapshotId();
            allSnapshotIds.put(snapshotId.getName(), snapshotId);
            currentSnapshotIds.add(snapshotId);
        }
        if (isCurrentSnapshotsOnly(request.snapshots()) == false) {
            for (SnapshotId snapshotId : snapshotsService.getRepositoryData(repository).getAllSnapshotIds()) {
                allSnapshotIds.put(snapshotId.getName(), snapshotId);
            }
        }
        final Set<SnapshotId> toResolve = new HashSet<>();
        if (isAllSnapshots(request.snapshots())) {
            toResolve.addAll(allSnapshotIds.values());
        } else {
            for (String snapshotOrPattern : request.snapshots()) {
                if (GetSnapshotsRequest.CURRENT_SNAPSHOT.equalsIgnoreCase(snapshotOrPattern)) {
                    toResolve.addAll(currentSnapshotIds);
                } else if (Regex.isSimpleMatchPattern(snapshotOrPattern) == false) {
                    if (allSnapshotIds.containsKey(snapshotOrPattern)) {
                        toResolve.add(allSnapshotIds.get(snapshotOrPattern));
                    } else if (request.ignoreUnavailable() == false) {
                        throw new SnapshotMissingException(repository, snapshotOrPattern);
                    }
                } else {
                    for (Map.Entry<String, SnapshotId> entry : allSnapshotIds.entrySet()) {
                        if (Regex.simpleMatch(snapshotOrPattern, entry.getKey())) {
                            toResolve.add(entry.getValue());
                        }
                    }
                }
            }
            if (toResolve.isEmpty() && request.ignoreUnavailable() == false && isCurrentSnapshotsOnly(request.snapshots()) == false) {
                throw new SnapshotMissingException(repository, request.snapshots()[0]);
            }
        }
        snapshotInfoBuilder.addAll(snapshotsService.snapshots(repository, new ArrayList<>(toResolve), request.ignoreUnavailable()));
        listener.onResponse(new GetSnapshotsResponse(snapshotInfoBuilder));
    } catch (Exception e) {
        listener.onFailure(e);
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SnapshotMissingException(org.elasticsearch.snapshots.SnapshotMissingException) ClusterBlockException(org.elasticsearch.cluster.block.ClusterBlockException) SnapshotId(org.elasticsearch.snapshots.SnapshotId) SnapshotInfo(org.elasticsearch.snapshots.SnapshotInfo) SnapshotMissingException(org.elasticsearch.snapshots.SnapshotMissingException) HashSet(java.util.HashSet)

Example 8 with SnapshotInfo

use of org.elasticsearch.snapshots.SnapshotInfo in project elasticsearch by elastic.

the class RestoreBackwardsCompatIT method testOldSnapshot.

private void testOldSnapshot(String version, String repo, String snapshot) throws IOException {
    logger.info("--> get snapshot and check its version");
    GetSnapshotsResponse getSnapshotsResponse = client().admin().cluster().prepareGetSnapshots(repo).setSnapshots(snapshot).get();
    assertThat(getSnapshotsResponse.getSnapshots().size(), equalTo(1));
    SnapshotInfo snapshotInfo = getSnapshotsResponse.getSnapshots().get(0);
    assertThat(snapshotInfo.version().toString(), equalTo(version));
    logger.info("--> restoring snapshot");
    RestoreSnapshotResponse response = client().admin().cluster().prepareRestoreSnapshot(repo, snapshot).setRestoreGlobalState(true).setWaitForCompletion(true).get();
    assertThat(response.status(), equalTo(RestStatus.OK));
    RestoreInfo restoreInfo = response.getRestoreInfo();
    assertThat(restoreInfo.successfulShards(), greaterThan(0));
    assertThat(restoreInfo.successfulShards(), equalTo(restoreInfo.totalShards()));
    assertThat(restoreInfo.failedShards(), equalTo(0));
    String index = restoreInfo.indices().get(0);
    logger.info("--> check search");
    SearchResponse searchResponse = client().prepareSearch(index).get();
    assertThat(searchResponse.getHits().getTotalHits(), greaterThan(1L));
    logger.info("--> check settings");
    ClusterState clusterState = client().admin().cluster().prepareState().get().getState();
    assertThat(clusterState.metaData().persistentSettings().get(FilterAllocationDecider.CLUSTER_ROUTING_EXCLUDE_GROUP_SETTING.getKey() + "version_attr"), equalTo(version));
    logger.info("--> check templates");
    IndexTemplateMetaData template = clusterState.getMetaData().templates().get("template_" + version.toLowerCase(Locale.ROOT));
    assertThat(template, notNullValue());
    assertThat(template.patterns(), equalTo(Collections.singletonList("te*")));
    assertThat(template.settings().getAsInt(IndexMetaData.SETTING_NUMBER_OF_SHARDS, -1), equalTo(1));
    assertThat(template.mappings().size(), equalTo(1));
    assertThat(template.mappings().get("type1").string(), anyOf(equalTo("{\"type1\":{\"_source\":{\"enabled\":false}}}"), equalTo("{\"type1\":{\"_source\":{\"enabled\":\"false\"}}}"), equalTo("{\"type1\":{\"_source\":{\"enabled\":\"0\"}}}"), equalTo("{\"type1\":{\"_source\":{\"enabled\":0}}}"), equalTo("{\"type1\":{\"_source\":{\"enabled\":\"off\"}}}"), equalTo("{\"type1\":{\"_source\":{\"enabled\":\"no\"}}}")));
    assertThat(template.aliases().size(), equalTo(3));
    assertThat(template.aliases().get("alias1"), notNullValue());
    assertThat(template.aliases().get("alias2").filter().string(), containsString(version));
    assertThat(template.aliases().get("alias2").indexRouting(), equalTo("kimchy"));
    assertThat(template.aliases().get("{index}-alias"), notNullValue());
    logger.info("--> cleanup");
    cluster().wipeIndices(restoreInfo.indices().toArray(new String[restoreInfo.indices().size()]));
    cluster().wipeTemplates();
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) GetSnapshotsResponse(org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse) SnapshotInfo(org.elasticsearch.snapshots.SnapshotInfo) RestoreInfo(org.elasticsearch.snapshots.RestoreInfo) IndexTemplateMetaData(org.elasticsearch.cluster.metadata.IndexTemplateMetaData) Matchers.containsString(org.hamcrest.Matchers.containsString) RestoreSnapshotResponse(org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Example 9 with SnapshotInfo

use of org.elasticsearch.snapshots.SnapshotInfo in project crate by crate.

the class SnapshotRestoreDDLDispatcherTest method testResolveMultiTablesIndexNamesFromSnapshot.

@Test
public void testResolveMultiTablesIndexNamesFromSnapshot() throws Exception {
    List<RestoreSnapshotAnalyzedStatement.RestoreTableInfo> tables = Arrays.asList(new RestoreSnapshotAnalyzedStatement.RestoreTableInfo(new TableIdent(null, "my_table"), null), new RestoreSnapshotAnalyzedStatement.RestoreTableInfo(new TableIdent(null, "my_partitioned_table"), null));
    List<SnapshotInfo> snapshots = Arrays.asList(new SnapshotInfo(new Snapshot("snapshot01", Collections.singletonList(".partitioned.my_partitioned_table.046jcchm6krj4e1g60o30c0"), 0)), new SnapshotInfo(new Snapshot("snapshot03", Collections.singletonList("my_table"), 0)));
    CompletableFuture<List<String>> future = new CompletableFuture<>();
    SnapshotRestoreDDLDispatcher.ResolveFromSnapshotActionListener actionListener = new SnapshotRestoreDDLDispatcher.ResolveFromSnapshotActionListener(future, tables, new HashSet<>());
    // need to mock here as constructor is not accessible
    GetSnapshotsResponse response = mock(GetSnapshotsResponse.class);
    when(response.getSnapshots()).thenReturn(snapshots);
    actionListener.onResponse(response);
    assertThat(future.get(), containsInAnyOrder("my_table", PartitionName.templateName(null, "my_partitioned_table") + "*"));
}
Also used : TableIdent(io.crate.metadata.TableIdent) RestoreSnapshotAnalyzedStatement(io.crate.analyze.RestoreSnapshotAnalyzedStatement) Snapshot(org.elasticsearch.snapshots.Snapshot) SnapshotInfo(org.elasticsearch.snapshots.SnapshotInfo) CompletableFuture(java.util.concurrent.CompletableFuture) GetSnapshotsResponse(org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse) List(java.util.List) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 10 with SnapshotInfo

use of org.elasticsearch.snapshots.SnapshotInfo in project crate by crate.

the class SnapshotRestoreIntegrationTest method waitForCompletion.

private SnapshotInfo waitForCompletion(String repository, String snapshot, TimeValue timeout) throws InterruptedException {
    long start = System.currentTimeMillis();
    SnapshotId snapshotId = new SnapshotId(repository, snapshot);
    while (System.currentTimeMillis() - start < timeout.millis()) {
        List<SnapshotInfo> snapshotInfos = client().admin().cluster().prepareGetSnapshots(repository).setSnapshots(snapshot).get().getSnapshots();
        assertThat(snapshotInfos.size(), equalTo(1));
        if (snapshotInfos.get(0).state().completed()) {
            // Make sure that snapshot clean up operations are finished
            ClusterStateResponse stateResponse = client().admin().cluster().prepareState().get();
            SnapshotsInProgress snapshotsInProgress = stateResponse.getState().getMetaData().custom(SnapshotsInProgress.TYPE);
            if (snapshotsInProgress == null || snapshotsInProgress.snapshot(snapshotId) == null) {
                return snapshotInfos.get(0);
            }
        }
        Thread.sleep(100);
    }
    fail("Timeout waiting for snapshot completion!");
    return null;
}
Also used : SnapshotId(org.elasticsearch.cluster.metadata.SnapshotId) SnapshotInfo(org.elasticsearch.snapshots.SnapshotInfo) ClusterStateResponse(org.elasticsearch.action.admin.cluster.state.ClusterStateResponse) SnapshotsInProgress(org.elasticsearch.cluster.SnapshotsInProgress)

Aggregations

SnapshotInfo (org.elasticsearch.snapshots.SnapshotInfo)15 Snapshot (org.elasticsearch.snapshots.Snapshot)4 SnapshotId (org.elasticsearch.snapshots.SnapshotId)4 TableIdent (io.crate.metadata.TableIdent)3 CrateUnitTest (io.crate.test.integration.CrateUnitTest)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 SnapshotMissingException (org.elasticsearch.snapshots.SnapshotMissingException)3 Test (org.junit.Test)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 List (java.util.List)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 GetSnapshotsResponse (org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse)2 ClusterState (org.elasticsearch.cluster.ClusterState)2 SnapshotsInProgress (org.elasticsearch.cluster.SnapshotsInProgress)2 ClusterBlockException (org.elasticsearch.cluster.block.ClusterBlockException)2 IndexId (org.elasticsearch.repositories.IndexId)2 RepositoryData (org.elasticsearch.repositories.RepositoryData)2 RepositoryException (org.elasticsearch.repositories.RepositoryException)2