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

Fix Issue with Concurrent Snapshot Init + Delete #38518

Merged
merged 5 commits into from
Feb 8, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -331,7 +331,6 @@ public void onFailure(final Exception e) {
public TimeValue timeout() {
return request.masterNodeTimeout();
}

});
}

Expand Down Expand Up @@ -394,6 +393,8 @@ private void beginSnapshot(final ClusterState clusterState,

boolean snapshotCreated;

boolean hadAbortedInitializations;

@Override
protected void doRun() {
assert initializingSnapshots.contains(snapshot.snapshot());
Expand Down Expand Up @@ -433,6 +434,8 @@ public ClusterState execute(ClusterState currentState) {

if (entry.state() == State.ABORTED) {
entries.add(entry);
assert entry.shards().isEmpty();
hadAbortedInitializations = true;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we now don't finalise this case in applyClusterState we need to end it when the cluster state for the init has been processed, so we set the flag here to mark that case.

} else {
// Replace the snapshot that was just initialized
ImmutableOpenMap<ShardId, ShardSnapshotStatus> shards =
Expand Down Expand Up @@ -491,6 +494,16 @@ public void clusterStateProcessed(String source, ClusterState oldState, ClusterS
// completion listener in this method. For the snapshot completion to work properly, the snapshot
// should still exist when listener is registered.
userCreateSnapshotListener.onResponse(snapshot.snapshot());

if (hadAbortedInitializations) {
final SnapshotsInProgress snapshotsInProgress = newState.custom(SnapshotsInProgress.TYPE);
if (snapshotsInProgress != null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should be able to assert != null here?

final SnapshotsInProgress.Entry entry = snapshotsInProgress.snapshot(snapshot.snapshot());
if (entry != null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should be able to assert != null here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess I was paranoid about potentially throwing an NPE in the cluster state thread :D but yea, assert should in theory be just fine => moving to assert :)

endSnapshot(entry);
}
}
}
}
});
}
Expand Down Expand Up @@ -701,8 +714,8 @@ public void applyClusterState(ClusterChangedEvent event) {
// 3. Snapshots in any other state that have all their shard tasks completed
snapshotsInProgress.entries().stream().filter(
entry -> entry.state().completed()
|| entry.state() == State.INIT && initializingSnapshots.contains(entry.snapshot()) == false
|| entry.state() != State.INIT && completed(entry.shards().values())
|| initializingSnapshots.contains(entry.snapshot()) == false
Copy link
Member Author

@original-brownbear original-brownbear Feb 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before we were finalising all snapshots that had all their shards completed here.
This caught the case where a snapshot had just went from INIT to ABORTED and was finalised in the repository when at the same time we were initialising it in https://github.com/elastic/elasticsearch/pull/38518/files#diff-a0853be4492c052f24917b5c1464003dR413 (this is what the failing test in #38489 forced by setting the on init block in the MockRepository).

With this change we will never finalise a snapshot here that is still being initialised.

&& (entry.state() == State.INIT || completed(entry.shards().values()))
).forEach(this::endSnapshot);
}
if (newMaster) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,6 @@ public void testMasterShutdownDuringSnapshot() throws Exception {
assertEquals(0, snapshotInfo.failedShards());
}


public void testMasterAndDataShutdownDuringSnapshot() throws Exception {
logger.info("--> starting three master nodes and two data nodes");
internalCluster().startMasterOnlyNodes(3);
Expand Down