Skip to content

Commit f7d9e7b

Browse files
Better Exceptions on Concurrent Snapshot Operations (#49220) (#49237)
* Better Exceptions on Concurrent Snapshot Operations It is somewhat tricky to debug test failures from concurrent operations without having the exact knowledge of what ran concurrently so I added it to these exceptions in all spots.
1 parent a817cf5 commit f7d9e7b

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

server/src/main/java/org/elasticsearch/action/admin/cluster/repositories/cleanup/TransportCleanupRepositoryAction.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,15 +176,18 @@ public ClusterState execute(ClusterState currentState) {
176176
final RepositoryCleanupInProgress repositoryCleanupInProgress = currentState.custom(RepositoryCleanupInProgress.TYPE);
177177
if (repositoryCleanupInProgress != null && repositoryCleanupInProgress.cleanupInProgress() == false) {
178178
throw new IllegalStateException(
179-
"Cannot cleanup [" + repositoryName + "] - a repository cleanup is already in-progress");
179+
"Cannot cleanup [" + repositoryName + "] - a repository cleanup is already in-progress in ["
180+
+ repositoryCleanupInProgress + "]");
180181
}
181182
SnapshotDeletionsInProgress deletionsInProgress = currentState.custom(SnapshotDeletionsInProgress.TYPE);
182183
if (deletionsInProgress != null && deletionsInProgress.hasDeletionsInProgress()) {
183-
throw new IllegalStateException("Cannot cleanup [" + repositoryName + "] - a snapshot is currently being deleted");
184+
throw new IllegalStateException("Cannot cleanup [" + repositoryName
185+
+ "] - a snapshot is currently being deleted in [" + deletionsInProgress + "]");
184186
}
185187
SnapshotsInProgress snapshots = currentState.custom(SnapshotsInProgress.TYPE);
186188
if (snapshots != null && !snapshots.entries().isEmpty()) {
187-
throw new IllegalStateException("Cannot cleanup [" + repositoryName + "] - a snapshot is currently running");
189+
throw new IllegalStateException(
190+
"Cannot cleanup [" + repositoryName + "] - a snapshot is currently running in [" + snapshots + "]");
188191
}
189192
return ClusterState.builder(currentState).putCustom(RepositoryCleanupInProgress.TYPE,
190193
new RepositoryCleanupInProgress(

server/src/main/java/org/elasticsearch/cluster/RestoreInProgress.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,10 @@ public int hashCode() {
8282

8383
@Override
8484
public String toString() {
85-
return new StringBuilder("RestoreInProgress[").append(entries).append("]").toString();
85+
StringBuilder builder = new StringBuilder("RestoreInProgress[");
86+
entries.forEach(entry -> builder.append("{").append(entry.key).append("}{").append(entry.value.snapshot).append("},"));
87+
builder.setCharAt(builder.length() - 1, ']');
88+
return builder.toString();
8689
}
8790

8891
public Entry get(String restoreUUID) {

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -278,12 +278,12 @@ public ClusterState execute(ClusterState currentState) {
278278
SnapshotDeletionsInProgress deletionsInProgress = currentState.custom(SnapshotDeletionsInProgress.TYPE);
279279
if (deletionsInProgress != null && deletionsInProgress.hasDeletionsInProgress()) {
280280
throw new ConcurrentSnapshotExecutionException(repositoryName, snapshotName,
281-
"cannot snapshot while a snapshot deletion is in-progress");
281+
"cannot snapshot while a snapshot deletion is in-progress in [" + deletionsInProgress + "]");
282282
}
283283
final RepositoryCleanupInProgress repositoryCleanupInProgress = currentState.custom(RepositoryCleanupInProgress.TYPE);
284284
if (repositoryCleanupInProgress != null && repositoryCleanupInProgress.cleanupInProgress() == false) {
285285
throw new ConcurrentSnapshotExecutionException(repositoryName, snapshotName,
286-
"cannot snapshot while a repository cleanup is in-progress");
286+
"cannot snapshot while a repository cleanup is in-progress in [" + repositoryCleanupInProgress + "]");
287287
}
288288
SnapshotsInProgress snapshots = currentState.custom(SnapshotsInProgress.TYPE);
289289
if (snapshots == null || snapshots.entries().isEmpty()) {
@@ -1195,20 +1195,21 @@ public ClusterState execute(ClusterState currentState) {
11951195
SnapshotDeletionsInProgress deletionsInProgress = currentState.custom(SnapshotDeletionsInProgress.TYPE);
11961196
if (deletionsInProgress != null && deletionsInProgress.hasDeletionsInProgress()) {
11971197
throw new ConcurrentSnapshotExecutionException(snapshot,
1198-
"cannot delete - another snapshot is currently being deleted");
1198+
"cannot delete - another snapshot is currently being deleted in [" + deletionsInProgress + "]");
11991199
}
12001200
final RepositoryCleanupInProgress repositoryCleanupInProgress = currentState.custom(RepositoryCleanupInProgress.TYPE);
12011201
if (repositoryCleanupInProgress != null && repositoryCleanupInProgress.cleanupInProgress() == false) {
12021202
throw new ConcurrentSnapshotExecutionException(snapshot.getRepository(), snapshot.getSnapshotId().getName(),
1203-
"cannot delete snapshot while a repository cleanup is in-progress");
1203+
"cannot delete snapshot while a repository cleanup is in-progress in [" + repositoryCleanupInProgress + "]");
12041204
}
12051205
RestoreInProgress restoreInProgress = currentState.custom(RestoreInProgress.TYPE);
12061206
if (restoreInProgress != null) {
12071207
// don't allow snapshot deletions while a restore is taking place,
12081208
// otherwise we could end up deleting a snapshot that is being restored
12091209
// and the files the restore depends on would all be gone
12101210
if (restoreInProgress.isEmpty() == false) {
1211-
throw new ConcurrentSnapshotExecutionException(snapshot, "cannot delete snapshot during a restore");
1211+
throw new ConcurrentSnapshotExecutionException(snapshot,
1212+
"cannot delete snapshot during a restore in progress in [" + restoreInProgress + "]");
12121213
}
12131214
}
12141215
ClusterState.Builder clusterStateBuilder = ClusterState.builder(currentState);

0 commit comments

Comments
 (0)