Search in sources :

Example 1 with RestoreInfo

use of org.opensearch.snapshots.RestoreInfo in project OpenSearch by opensearch-project.

the class RestoreClusterStateListener method clusterChanged.

@Override
public void clusterChanged(ClusterChangedEvent changedEvent) {
    final RestoreInProgress.Entry prevEntry = restoreInProgress(changedEvent.previousState(), uuid);
    final RestoreInProgress.Entry newEntry = restoreInProgress(changedEvent.state(), uuid);
    if (prevEntry == null) {
        // When there is a cluster-manager failure after a restore has been started, this listener might not be registered
        // on the current cluster-manager and as such it might miss some intermediary cluster states due to batching.
        // Clean up listener in that case and acknowledge completion of restore operation to client.
        clusterService.removeListener(this);
        listener.onResponse(new RestoreSnapshotResponse((RestoreInfo) null));
    } else if (newEntry == null) {
        clusterService.removeListener(this);
        ImmutableOpenMap<ShardId, RestoreInProgress.ShardRestoreStatus> shards = prevEntry.shards();
        assert prevEntry.state().completed() : "expected completed snapshot state but was " + prevEntry.state();
        assert RestoreService.completed(shards) : "expected all restore entries to be completed";
        RestoreInfo ri = new RestoreInfo(prevEntry.snapshot().getSnapshotId().getName(), prevEntry.indices(), shards.size(), shards.size() - RestoreService.failedShards(shards));
        RestoreSnapshotResponse response = new RestoreSnapshotResponse(ri);
        logger.debug("restore of [{}] completed", prevEntry.snapshot().getSnapshotId());
        listener.onResponse(response);
    } else {
    // restore not completed yet, wait for next cluster state update
    }
}
Also used : RestoreInProgress(org.opensearch.cluster.RestoreInProgress) RestoreInfo(org.opensearch.snapshots.RestoreInfo) ImmutableOpenMap(org.opensearch.common.collect.ImmutableOpenMap)

Example 2 with RestoreInfo

use of org.opensearch.snapshots.RestoreInfo in project OpenSearch by opensearch-project.

the class RestoreSnapshotResponseTests method createTestInstance.

@Override
protected RestoreSnapshotResponse createTestInstance() {
    if (randomBoolean()) {
        String name = randomRealisticUnicodeOfCodepointLengthBetween(1, 30);
        List<String> indices = new ArrayList<>();
        indices.add("test0");
        indices.add("test1");
        int totalShards = randomIntBetween(1, 1000);
        int successfulShards = randomIntBetween(0, totalShards);
        return new RestoreSnapshotResponse(new RestoreInfo(name, indices, totalShards, successfulShards));
    } else {
        return new RestoreSnapshotResponse((RestoreInfo) null);
    }
}
Also used : RestoreInfo(org.opensearch.snapshots.RestoreInfo) ArrayList(java.util.ArrayList)

Example 3 with RestoreInfo

use of org.opensearch.snapshots.RestoreInfo in project OpenSearch by opensearch-project.

the class DiskThresholdDeciderIT method testRestoreSnapshotAllocationDoesNotExceedWatermark.

public void testRestoreSnapshotAllocationDoesNotExceedWatermark() throws Exception {
    internalCluster().startClusterManagerOnlyNode();
    internalCluster().startDataOnlyNode();
    final String dataNodeName = internalCluster().startDataOnlyNode();
    ensureStableCluster(3);
    assertAcked(client().admin().cluster().preparePutRepository("repo").setType(FsRepository.TYPE).setSettings(Settings.builder().put("location", randomRepoPath()).put("compress", randomBoolean())));
    final InternalClusterInfoService clusterInfoService = (InternalClusterInfoService) internalCluster().getCurrentMasterNodeInstance(ClusterInfoService.class);
    internalCluster().getCurrentMasterNodeInstance(ClusterService.class).addListener(event -> clusterInfoService.refresh());
    final String dataNode0Id = internalCluster().getInstance(NodeEnvironment.class, dataNodeName).nodeId();
    final Path dataNode0Path = internalCluster().getInstance(Environment.class, dataNodeName).dataFiles()[0];
    final String indexName = randomAlphaOfLength(10).toLowerCase(Locale.ROOT);
    createIndex(indexName, Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0).put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 6).put(INDEX_STORE_STATS_REFRESH_INTERVAL_SETTING.getKey(), "0ms").build());
    final long minShardSize = createReasonableSizedShards(indexName);
    final CreateSnapshotResponse createSnapshotResponse = client().admin().cluster().prepareCreateSnapshot("repo", "snap").setWaitForCompletion(true).get();
    final SnapshotInfo snapshotInfo = createSnapshotResponse.getSnapshotInfo();
    assertThat(snapshotInfo.successfulShards(), is(snapshotInfo.totalShards()));
    assertThat(snapshotInfo.state(), is(SnapshotState.SUCCESS));
    assertAcked(client().admin().indices().prepareDelete(indexName).get());
    // reduce disk size of node 0 so that no shards fit below the low watermark, forcing shards to be assigned to the other data node
    fileSystemProvider.getTestFileStore(dataNode0Path).setTotalSpace(minShardSize + WATERMARK_BYTES - 1L);
    refreshDiskUsage();
    assertAcked(client().admin().cluster().prepareUpdateSettings().setTransientSettings(Settings.builder().put(EnableAllocationDecider.CLUSTER_ROUTING_REBALANCE_ENABLE_SETTING.getKey(), Rebalance.NONE.toString()).build()).get());
    final RestoreSnapshotResponse restoreSnapshotResponse = client().admin().cluster().prepareRestoreSnapshot("repo", "snap").setWaitForCompletion(true).get();
    final RestoreInfo restoreInfo = restoreSnapshotResponse.getRestoreInfo();
    assertThat(restoreInfo.successfulShards(), is(snapshotInfo.totalShards()));
    assertThat(restoreInfo.failedShards(), is(0));
    assertBusy(() -> assertThat(getShardRoutings(dataNode0Id, indexName), empty()));
    assertAcked(client().admin().cluster().prepareUpdateSettings().setTransientSettings(Settings.builder().putNull(EnableAllocationDecider.CLUSTER_ROUTING_REBALANCE_ENABLE_SETTING.getKey()).build()).get());
    // increase disk size of node 0 to allow just enough room for one shard, and check that it's rebalanced back
    fileSystemProvider.getTestFileStore(dataNode0Path).setTotalSpace(minShardSize + WATERMARK_BYTES + 1L);
    assertBusyWithDiskUsageRefresh(dataNode0Id, indexName, hasSize(1));
}
Also used : FilterPath(org.apache.lucene.tests.mockfile.FilterPath) Path(java.nio.file.Path) SnapshotInfo(org.opensearch.snapshots.SnapshotInfo) ClusterService(org.opensearch.cluster.service.ClusterService) RestoreInfo(org.opensearch.snapshots.RestoreInfo) CreateSnapshotResponse(org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse) InternalClusterInfoService(org.opensearch.cluster.InternalClusterInfoService) ClusterInfoService(org.opensearch.cluster.ClusterInfoService) NodeEnvironment(org.opensearch.env.NodeEnvironment) InternalClusterInfoService(org.opensearch.cluster.InternalClusterInfoService) RestoreSnapshotResponse(org.opensearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse)

Example 4 with RestoreInfo

use of org.opensearch.snapshots.RestoreInfo in project OpenSearch by opensearch-project.

the class SnapshotClientDocumentationIT method testRestoreSnapshot.

public void testRestoreSnapshot() throws IOException {
    RestHighLevelClient client = highLevelClient();
    createTestRepositories();
    createTestIndex();
    createTestSnapshots();
    // tag::restore-snapshot-request
    RestoreSnapshotRequest request = new RestoreSnapshotRequest(repositoryName, snapshotName);
    // end::restore-snapshot-request
    // we need to restore as a different index name
    // tag::restore-snapshot-request-masterTimeout
    // <1>
    request.masterNodeTimeout(TimeValue.timeValueMinutes(1));
    // <2>
    request.masterNodeTimeout("1m");
    // end::restore-snapshot-request-masterTimeout
    // tag::restore-snapshot-request-waitForCompletion
    // <1>
    request.waitForCompletion(true);
    // end::restore-snapshot-request-waitForCompletion
    // tag::restore-snapshot-request-partial
    // <1>
    request.partial(false);
    // end::restore-snapshot-request-partial
    // tag::restore-snapshot-request-include-global-state
    // <1>
    request.includeGlobalState(false);
    // end::restore-snapshot-request-include-global-state
    // tag::restore-snapshot-request-include-aliases
    // <1>
    request.includeAliases(false);
    // end::restore-snapshot-request-include-aliases
    // tag::restore-snapshot-request-indices
    // <1>
    request.indices("test_index");
    // end::restore-snapshot-request-indices
    String restoredIndexName = "restored_index";
    // tag::restore-snapshot-request-rename
    // <1>
    request.renamePattern("test_(.+)");
    // <2>
    request.renameReplacement("restored_$1");
    // end::restore-snapshot-request-rename
    // tag::restore-snapshot-request-index-settings
    // <1>
    request.indexSettings(Settings.builder().put("index.number_of_replicas", 0).build());
    // <2>
    request.ignoreIndexSettings("index.refresh_interval", "index.search.idle.after");
    request.indicesOptions(new // <3>
    IndicesOptions(EnumSet.of(IndicesOptions.Option.IGNORE_UNAVAILABLE), EnumSet.of(IndicesOptions.WildcardStates.OPEN)));
    // end::restore-snapshot-request-index-settings
    // tag::restore-snapshot-execute
    RestoreSnapshotResponse response = client.snapshot().restore(request, RequestOptions.DEFAULT);
    // end::restore-snapshot-execute
    // tag::restore-snapshot-response
    RestoreInfo restoreInfo = response.getRestoreInfo();
    // <1>
    List<String> indices = restoreInfo.indices();
    // end::restore-snapshot-response
    assertEquals(Collections.singletonList(restoredIndexName), indices);
    assertEquals(0, restoreInfo.failedShards());
    assertTrue(restoreInfo.successfulShards() > 0);
}
Also used : RestoreInfo(org.opensearch.snapshots.RestoreInfo) RestoreSnapshotRequest(org.opensearch.action.admin.cluster.snapshots.restore.RestoreSnapshotRequest) RestHighLevelClient(org.opensearch.client.RestHighLevelClient) RestoreSnapshotResponse(org.opensearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse)

Example 5 with RestoreInfo

use of org.opensearch.snapshots.RestoreInfo in project OpenSearch by opensearch-project.

the class SnapshotIT method testRestoreSnapshot.

public void testRestoreSnapshot() throws IOException {
    String testRepository = "test";
    String testSnapshot = "snapshot_1";
    String testIndex = "test_index";
    String restoredIndex = testIndex + "_restored";
    AcknowledgedResponse putRepositoryResponse = createTestRepository(testRepository, FsRepository.TYPE, "{\"location\": \".\"}");
    assertTrue(putRepositoryResponse.isAcknowledged());
    createIndex(testIndex, Settings.EMPTY);
    assertTrue("index [" + testIndex + "] should have been created", indexExists(testIndex));
    CreateSnapshotRequest createSnapshotRequest = new CreateSnapshotRequest(testRepository, testSnapshot);
    createSnapshotRequest.indices(testIndex);
    createSnapshotRequest.waitForCompletion(true);
    if (randomBoolean()) {
        createSnapshotRequest.userMetadata(randomUserMetadata());
    }
    CreateSnapshotResponse createSnapshotResponse = createTestSnapshot(createSnapshotRequest);
    assertEquals(RestStatus.OK, createSnapshotResponse.status());
    deleteIndex(testIndex);
    assertFalse("index [" + testIndex + "] should have been deleted", indexExists(testIndex));
    RestoreSnapshotRequest request = new RestoreSnapshotRequest(testRepository, testSnapshot);
    request.waitForCompletion(true);
    request.renamePattern(testIndex);
    request.renameReplacement(restoredIndex);
    RestoreSnapshotResponse response = execute(request, highLevelClient().snapshot()::restore, highLevelClient().snapshot()::restoreAsync);
    RestoreInfo restoreInfo = response.getRestoreInfo();
    assertThat(restoreInfo.name(), equalTo(testSnapshot));
    assertThat(restoreInfo.indices(), equalTo(Collections.singletonList(restoredIndex)));
    assertThat(restoreInfo.successfulShards(), greaterThan(0));
    assertThat(restoreInfo.failedShards(), equalTo(0));
}
Also used : RestoreInfo(org.opensearch.snapshots.RestoreInfo) CreateSnapshotResponse(org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse) CreateSnapshotRequest(org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotRequest) AcknowledgedResponse(org.opensearch.action.support.master.AcknowledgedResponse) RestoreSnapshotRequest(org.opensearch.action.admin.cluster.snapshots.restore.RestoreSnapshotRequest) RestoreSnapshotResponse(org.opensearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse)

Aggregations

RestoreInfo (org.opensearch.snapshots.RestoreInfo)6 RestoreSnapshotResponse (org.opensearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse)4 CreateSnapshotResponse (org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse)3 RestoreSnapshotRequest (org.opensearch.action.admin.cluster.snapshots.restore.RestoreSnapshotRequest)3 CreateSnapshotRequest (org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotRequest)2 AcknowledgedResponse (org.opensearch.action.support.master.AcknowledgedResponse)2 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 FilterPath (org.apache.lucene.tests.mockfile.FilterPath)1 RestHighLevelClient (org.opensearch.client.RestHighLevelClient)1 ClusterInfoService (org.opensearch.cluster.ClusterInfoService)1 InternalClusterInfoService (org.opensearch.cluster.InternalClusterInfoService)1 RestoreInProgress (org.opensearch.cluster.RestoreInProgress)1 ClusterService (org.opensearch.cluster.service.ClusterService)1 ImmutableOpenMap (org.opensearch.common.collect.ImmutableOpenMap)1 NodeEnvironment (org.opensearch.env.NodeEnvironment)1 SnapshotInfo (org.opensearch.snapshots.SnapshotInfo)1