Skip to content

Commit 5065cac

Browse files
committed
Apply feedback
1 parent 76806b0 commit 5065cac

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

core/src/main/java/org/elasticsearch/snapshots/SnapshotsService.java

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,8 @@ private void beginSnapshot(final ClusterState clusterState,
372372
return;
373373
}
374374
clusterService.submitStateUpdateTask("update_snapshot [" + snapshot.snapshot() + "]", new ClusterStateUpdateTask() {
375-
boolean accepted = false;
376-
SnapshotsInProgress.Entry updatedSnapshot;
375+
376+
SnapshotsInProgress.Entry endSnapshot;
377377
String failure = null;
378378

379379
@Override
@@ -394,9 +394,10 @@ public ClusterState execute(ClusterState currentState) {
394394
Set<String> missing = indicesWithMissingShards.v1();
395395
Set<String> closed = indicesWithMissingShards.v2();
396396
if (missing.isEmpty() == false || closed.isEmpty() == false) {
397-
StringBuilder failureMessage = new StringBuilder();
398-
updatedSnapshot = new SnapshotsInProgress.Entry(entry, State.FAILED, shards);
399-
entries.add(updatedSnapshot);
397+
endSnapshot = new SnapshotsInProgress.Entry(entry, State.FAILED, shards);
398+
entries.add(endSnapshot);
399+
400+
final StringBuilder failureMessage = new StringBuilder();
400401
if (missing.isEmpty() == false) {
401402
failureMessage.append("Indices don't have primary shards ");
402403
failureMessage.append(missing);
@@ -412,15 +413,16 @@ public ClusterState execute(ClusterState currentState) {
412413
continue;
413414
}
414415
}
415-
updatedSnapshot = new SnapshotsInProgress.Entry(entry, State.STARTED, shards);
416+
SnapshotsInProgress.Entry updatedSnapshot = new SnapshotsInProgress.Entry(entry, State.STARTED, shards);
416417
entries.add(updatedSnapshot);
417-
if (completed(shards.values()) == false) {
418-
accepted = true;
418+
if (completed(shards.values())) {
419+
endSnapshot = updatedSnapshot;
419420
}
420421
} else {
421-
failure = "snapshot state changed to " + entry.state() + " during initialization";
422-
updatedSnapshot = entry;
423-
entries.add(updatedSnapshot);
422+
assert entry.state() == State.ABORTED : "expecting snapshot to be aborted during initialization";
423+
failure = "snapshot was aborted during initialization";
424+
endSnapshot = entry;
425+
entries.add(endSnapshot);
424426
}
425427
}
426428
return ClusterState.builder(currentState)
@@ -455,8 +457,8 @@ public void clusterStateProcessed(String source, ClusterState oldState, ClusterS
455457
// We should end snapshot only if 1) we didn't accept it for processing (which happens when there
456458
// is nothing to do) and 2) there was a snapshot in metadata that we should end. Otherwise we should
457459
// go ahead and continue working on this snapshot rather then end here.
458-
if (!accepted && updatedSnapshot != null) {
459-
endSnapshot(updatedSnapshot, failure);
460+
if (endSnapshot != null) {
461+
endSnapshot(endSnapshot, failure);
460462
}
461463
}
462464
});
@@ -1164,7 +1166,7 @@ public ClusterState execute(ClusterState currentState) throws Exception {
11641166
// snapshot is still initializing, mark it as aborted
11651167
shards = snapshotEntry.shards();
11661168

1167-
} else if (snapshotEntry.state() == State.STARTED) {
1169+
} else if (state == State.STARTED) {
11681170
// snapshot is started - mark every non completed shard as aborted
11691171
final ImmutableOpenMap.Builder<ShardId, ShardSnapshotStatus> shardsBuilder = ImmutableOpenMap.builder();
11701172
for (ObjectObjectCursor<ShardId, ShardSnapshotStatus> shardEntry : snapshotEntry.shards()) {

0 commit comments

Comments
 (0)