* Remove Redundant Cluster State during Snapshot INIT + Master Failover (#54420) Similar to #54395 we know that a snapshot in INIT state has not written anything to the repository yet. If we see one from a master failover, there is no point in moving it to ABORTED before removing it from the cluster state in a subsequent CS update. Instead, we can simply remove its job from the CS the first time we see it on master failover and be done with it.
This commit is contained in:
parent
d1123281b1
commit
e164c9aaee
|
@ -335,10 +335,9 @@ public class SnapshotsService extends AbstractLifecycleComponent implements Clus
|
||||||
repository.initializeSnapshot(
|
repository.initializeSnapshot(
|
||||||
snapshot.snapshot().getSnapshotId(), snapshot.indices(),
|
snapshot.snapshot().getSnapshotId(), snapshot.indices(),
|
||||||
metadataForSnapshot(snapshot, clusterState.metadata()));
|
metadataForSnapshot(snapshot, clusterState.metadata()));
|
||||||
|
snapshotCreated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
snapshotCreated = true;
|
|
||||||
|
|
||||||
logger.info("snapshot [{}] started", snapshot.snapshot());
|
logger.info("snapshot [{}] started", snapshot.snapshot());
|
||||||
final Version version =
|
final Version version =
|
||||||
minCompatibleVersion(clusterState.nodes().getMinNodeVersion(), snapshot.repository(), repositoryData, null);
|
minCompatibleVersion(clusterState.nodes().getMinNodeVersion(), snapshot.repository(), repositoryData, null);
|
||||||
|
@ -408,7 +407,7 @@ public class SnapshotsService extends AbstractLifecycleComponent implements Clus
|
||||||
logger.warn(() -> new ParameterizedMessage("[{}] failed to create snapshot",
|
logger.warn(() -> new ParameterizedMessage("[{}] failed to create snapshot",
|
||||||
snapshot.snapshot().getSnapshotId()), e);
|
snapshot.snapshot().getSnapshotId()), e);
|
||||||
removeSnapshotFromClusterState(snapshot.snapshot(), null, e,
|
removeSnapshotFromClusterState(snapshot.snapshot(), null, e,
|
||||||
new CleanupAfterErrorListener(snapshot, true, userCreateSnapshotListener, e));
|
new CleanupAfterErrorListener(snapshot, snapshotCreated, userCreateSnapshotListener, e));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -471,9 +470,12 @@ public class SnapshotsService extends AbstractLifecycleComponent implements Clus
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(Exception e) {
|
public void onFailure(@Nullable Exception e) {
|
||||||
e.addSuppressed(this.e);
|
if (snapshotCreated) {
|
||||||
cleanupAfterError(e);
|
cleanupAfterError(ExceptionsHelper.useOrSuppress(e, this.e));
|
||||||
|
} else {
|
||||||
|
userCreateSnapshotListener.onFailure(ExceptionsHelper.useOrSuppress(e, this.e));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onNoLongerMaster() {
|
public void onNoLongerMaster() {
|
||||||
|
@ -482,29 +484,25 @@ public class SnapshotsService extends AbstractLifecycleComponent implements Clus
|
||||||
|
|
||||||
private void cleanupAfterError(Exception exception) {
|
private void cleanupAfterError(Exception exception) {
|
||||||
threadPool.generic().execute(() -> {
|
threadPool.generic().execute(() -> {
|
||||||
if (snapshotCreated) {
|
final Metadata metadata = clusterService.state().metadata();
|
||||||
final Metadata metadata = clusterService.state().metadata();
|
repositoriesService.repository(snapshot.snapshot().getRepository())
|
||||||
repositoriesService.repository(snapshot.snapshot().getRepository())
|
|
||||||
.finalizeSnapshot(snapshot.snapshot().getSnapshotId(),
|
.finalizeSnapshot(snapshot.snapshot().getSnapshotId(),
|
||||||
buildGenerations(snapshot, metadata),
|
buildGenerations(snapshot, metadata),
|
||||||
snapshot.startTime(),
|
snapshot.startTime(),
|
||||||
ExceptionsHelper.stackTrace(exception),
|
ExceptionsHelper.stackTrace(exception),
|
||||||
0,
|
0,
|
||||||
Collections.emptyList(),
|
Collections.emptyList(),
|
||||||
snapshot.repositoryStateId(),
|
snapshot.repositoryStateId(),
|
||||||
snapshot.includeGlobalState(),
|
snapshot.includeGlobalState(),
|
||||||
metadataForSnapshot(snapshot, metadata),
|
metadataForSnapshot(snapshot, metadata),
|
||||||
snapshot.userMetadata(),
|
snapshot.userMetadata(),
|
||||||
snapshot.version(),
|
snapshot.version(),
|
||||||
ActionListener.runAfter(ActionListener.wrap(ignored -> {
|
ActionListener.runAfter(ActionListener.wrap(ignored -> {
|
||||||
}, inner -> {
|
}, inner -> {
|
||||||
inner.addSuppressed(exception);
|
inner.addSuppressed(exception);
|
||||||
logger.warn(() -> new ParameterizedMessage("[{}] failed to finalize snapshot in repository",
|
logger.warn(() -> new ParameterizedMessage("[{}] failed to finalize snapshot in repository",
|
||||||
snapshot.snapshot()), inner);
|
snapshot.snapshot()), inner);
|
||||||
}), () -> userCreateSnapshotListener.onFailure(e)));
|
}), () -> userCreateSnapshotListener.onFailure(e)));
|
||||||
} else {
|
|
||||||
userCreateSnapshotListener.onFailure(e);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1016,7 +1014,7 @@ public class SnapshotsService extends AbstractLifecycleComponent implements Clus
|
||||||
endingSnapshots.remove(snapshot);
|
endingSnapshots.remove(snapshot);
|
||||||
}
|
}
|
||||||
if (listener != null) {
|
if (listener != null) {
|
||||||
listener.onResponse(snapshotInfo);
|
listener.onFailure(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue