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

Remove Redundant Cleanup Step in Snapshot Failure #54395

Merged
Changes from all commits
Commits
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 @@ -417,8 +417,6 @@ private void beginSnapshot(final ClusterState clusterState,
final ActionListener<Snapshot> userCreateSnapshotListener) {
threadPool.executor(ThreadPool.Names.SNAPSHOT).execute(new AbstractRunnable() {

boolean snapshotCreated;

boolean hadAbortedInitializations;

@Override
Expand All @@ -437,8 +435,6 @@ protected void doRun() {
repository.getMetadata().name(), snapshotName, "snapshot with the same name already exists");
}

snapshotCreated = true;

logger.info("snapshot [{}] started", snapshot.snapshot());
final Version version =
minCompatibleVersion(clusterState.nodes().getMinNodeVersion(), snapshot.repository(), repositoryData, null);
Expand Down Expand Up @@ -508,7 +504,7 @@ public void onFailure(String source, Exception e) {
logger.warn(() -> new ParameterizedMessage("[{}] failed to create snapshot",
snapshot.snapshot().getSnapshotId()), e);
removeSnapshotFromClusterState(snapshot.snapshot(), null, e,
new CleanupAfterErrorListener(snapshot, true, userCreateSnapshotListener, e));
new CleanupAfterErrorListener(userCreateSnapshotListener, e));
}

@Override
Expand Down Expand Up @@ -545,68 +541,35 @@ public void onFailure(Exception e) {
logger.warn(() -> new ParameterizedMessage("failed to create snapshot [{}]",
snapshot.snapshot().getSnapshotId()), e);
removeSnapshotFromClusterState(snapshot.snapshot(), null, e,
new CleanupAfterErrorListener(snapshot, snapshotCreated, userCreateSnapshotListener, e));
new CleanupAfterErrorListener(userCreateSnapshotListener, e));
}
});
}

private class CleanupAfterErrorListener implements ActionListener<SnapshotInfo> {
private static class CleanupAfterErrorListener implements ActionListener<SnapshotInfo> {

private final SnapshotsInProgress.Entry snapshot;
private final boolean snapshotCreated;
private final ActionListener<Snapshot> userCreateSnapshotListener;
private final Exception e;

CleanupAfterErrorListener(SnapshotsInProgress.Entry snapshot, boolean snapshotCreated,
ActionListener<Snapshot> userCreateSnapshotListener, Exception e) {
this.snapshot = snapshot;
this.snapshotCreated = snapshotCreated;
CleanupAfterErrorListener(ActionListener<Snapshot> userCreateSnapshotListener, Exception e) {
this.userCreateSnapshotListener = userCreateSnapshotListener;
this.e = e;
}

@Override
public void onResponse(SnapshotInfo snapshotInfo) {
cleanupAfterError(this.e);
userCreateSnapshotListener.onFailure(e);
}

@Override
public void onFailure(Exception e) {
e.addSuppressed(this.e);
cleanupAfterError(e);
userCreateSnapshotListener.onFailure(e);
}

public void onNoLongerMaster() {
userCreateSnapshotListener.onFailure(e);
}

private void cleanupAfterError(Exception exception) {
threadPool.generic().execute(() -> {
if (snapshotCreated) {
final MetaData metaData = clusterService.state().metaData();
repositoriesService.repository(snapshot.snapshot().getRepository())
.finalizeSnapshot(snapshot.snapshot().getSnapshotId(),
buildGenerations(snapshot, metaData),
snapshot.startTime(),
ExceptionsHelper.stackTrace(exception),
0,
Collections.emptyList(),
snapshot.repositoryStateId(),
snapshot.includeGlobalState(),
metaDataForSnapshot(snapshot, metaData),
snapshot.userMetadata(),
snapshot.version(),
ActionListener.runAfter(ActionListener.wrap(ignored -> {
}, inner -> {
inner.addSuppressed(exception);
logger.warn(() -> new ParameterizedMessage("[{}] failed to finalize snapshot in repository",
snapshot.snapshot()), inner);
}), () -> userCreateSnapshotListener.onFailure(e)));
} else {
userCreateSnapshotListener.onFailure(e);
}
});
}
}

private static ShardGenerations buildGenerations(SnapshotsInProgress.Entry snapshot, MetaData metaData) {
Expand Down