Search in sources :

Example 6 with RestoreInProgress

use of org.elasticsearch.cluster.RestoreInProgress in project elasticsearch by elastic.

the class RestoreService method cleanupRestoreState.

private void cleanupRestoreState(ClusterChangedEvent event) {
    ClusterState state = event.state();
    RestoreInProgress restoreInProgress = state.custom(RestoreInProgress.TYPE);
    if (restoreInProgress != null) {
        for (RestoreInProgress.Entry entry : restoreInProgress.entries()) {
            if (entry.state().completed()) {
                assert completed(entry.shards()) : "state says completed but restore entries are not";
                clusterService.submitStateUpdateTask("clean up snapshot restore state", new CleanRestoreStateTaskExecutor.Task(entry.snapshot()), ClusterStateTaskConfig.build(Priority.URGENT), cleanRestoreStateTaskExecutor, cleanRestoreStateTaskExecutor);
            }
        }
    }
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) RestoreInProgress(org.elasticsearch.cluster.RestoreInProgress)

Example 7 with RestoreInProgress

use of org.elasticsearch.cluster.RestoreInProgress in project elasticsearch by elastic.

the class ClusterSerializationTests method testSnapshotDeletionsInProgressSerialization.

public void testSnapshotDeletionsInProgressSerialization() throws Exception {
    boolean includeRestore = randomBoolean();
    ClusterState.Builder builder = ClusterState.builder(ClusterState.EMPTY_STATE).putCustom(SnapshotDeletionsInProgress.TYPE, SnapshotDeletionsInProgress.newInstance(new SnapshotDeletionsInProgress.Entry(new Snapshot("repo1", new SnapshotId("snap1", UUIDs.randomBase64UUID())), randomNonNegativeLong(), randomNonNegativeLong())));
    if (includeRestore) {
        builder.putCustom(RestoreInProgress.TYPE, new RestoreInProgress(new RestoreInProgress.Entry(new Snapshot("repo2", new SnapshotId("snap2", UUIDs.randomBase64UUID())), RestoreInProgress.State.STARTED, Collections.singletonList("index_name"), ImmutableOpenMap.of())));
    }
    ClusterState clusterState = builder.incrementVersion().build();
    Diff<ClusterState> diffs = clusterState.diff(ClusterState.EMPTY_STATE);
    // serialize with current version
    BytesStreamOutput outStream = new BytesStreamOutput();
    diffs.writeTo(outStream);
    StreamInput inStream = outStream.bytes().streamInput();
    inStream = new NamedWriteableAwareStreamInput(inStream, new NamedWriteableRegistry(ClusterModule.getNamedWriteables()));
    Diff<ClusterState> serializedDiffs = ClusterState.readDiffFrom(inStream, clusterState.nodes().getLocalNode());
    ClusterState stateAfterDiffs = serializedDiffs.apply(ClusterState.EMPTY_STATE);
    assertThat(stateAfterDiffs.custom(RestoreInProgress.TYPE), includeRestore ? notNullValue() : nullValue());
    assertThat(stateAfterDiffs.custom(SnapshotDeletionsInProgress.TYPE), notNullValue());
    // serialize with old version
    outStream = new BytesStreamOutput();
    outStream.setVersion(Version.CURRENT.minimumCompatibilityVersion());
    diffs.writeTo(outStream);
    inStream = outStream.bytes().streamInput();
    inStream = new NamedWriteableAwareStreamInput(inStream, new NamedWriteableRegistry(ClusterModule.getNamedWriteables()));
    serializedDiffs = ClusterState.readDiffFrom(inStream, clusterState.nodes().getLocalNode());
    stateAfterDiffs = serializedDiffs.apply(ClusterState.EMPTY_STATE);
    assertThat(stateAfterDiffs.custom(RestoreInProgress.TYPE), includeRestore ? notNullValue() : nullValue());
    assertThat(stateAfterDiffs.custom(SnapshotDeletionsInProgress.TYPE), nullValue());
    // remove the custom and try serializing again with old version
    clusterState = ClusterState.builder(clusterState).removeCustom(SnapshotDeletionsInProgress.TYPE).incrementVersion().build();
    outStream = new BytesStreamOutput();
    diffs.writeTo(outStream);
    inStream = outStream.bytes().streamInput();
    inStream = new NamedWriteableAwareStreamInput(inStream, new NamedWriteableRegistry(ClusterModule.getNamedWriteables()));
    serializedDiffs = ClusterState.readDiffFrom(inStream, clusterState.nodes().getLocalNode());
    stateAfterDiffs = serializedDiffs.apply(stateAfterDiffs);
    assertThat(stateAfterDiffs.custom(RestoreInProgress.TYPE), includeRestore ? notNullValue() : nullValue());
    assertThat(stateAfterDiffs.custom(SnapshotDeletionsInProgress.TYPE), nullValue());
}
Also used : NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) Snapshot(org.elasticsearch.snapshots.Snapshot) SnapshotId(org.elasticsearch.snapshots.SnapshotId) ClusterState(org.elasticsearch.cluster.ClusterState) RestoreInProgress(org.elasticsearch.cluster.RestoreInProgress) NamedWriteableAwareStreamInput(org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput) StreamInput(org.elasticsearch.common.io.stream.StreamInput) NamedWriteableAwareStreamInput(org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput)

Aggregations

RestoreInProgress (org.elasticsearch.cluster.RestoreInProgress)7 ClusterState (org.elasticsearch.cluster.ClusterState)6 ImmutableOpenMap (org.elasticsearch.common.collect.ImmutableOpenMap)5 RoutingTable (org.elasticsearch.cluster.routing.RoutingTable)3 Priority (org.elasticsearch.common.Priority)3 ObjectObjectCursor (com.carrotsearch.hppc.cursors.ObjectObjectCursor)2 ArrayList (java.util.ArrayList)2 Set (java.util.Set)2 ActionListener (org.elasticsearch.action.ActionListener)2 ClusterStateUpdateTask (org.elasticsearch.cluster.ClusterStateUpdateTask)2 ShardRestoreStatus (org.elasticsearch.cluster.RestoreInProgress.ShardRestoreStatus)2 SnapshotDeletionsInProgress (org.elasticsearch.cluster.SnapshotDeletionsInProgress)2 ClusterBlocks (org.elasticsearch.cluster.block.ClusterBlocks)2 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)2 MetaData (org.elasticsearch.cluster.metadata.MetaData)2 AllocationService (org.elasticsearch.cluster.routing.allocation.AllocationService)2 ClusterService (org.elasticsearch.cluster.service.ClusterService)2 AbstractComponent (org.elasticsearch.common.component.AbstractComponent)2 Inject (org.elasticsearch.common.inject.Inject)2 Settings (org.elasticsearch.common.settings.Settings)2