Skip to content

Commit f669e03

Browse files
committed
tweak
1 parent 7655d7c commit f669e03

File tree

2 files changed

+33
-35
lines changed

2 files changed

+33
-35
lines changed

server/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/status/TransportSnapshotsStatusAction.java

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -362,39 +362,39 @@ private void loadRepositoryData(
362362
delegate.onResponse(new SnapshotsStatusResponse(Collections.unmodifiableList(builder)));
363363
} else {
364364
final List<SnapshotStatus> threadSafeBuilder = Collections.synchronizedList(builder);
365-
repositoriesService.repository(projectId, repositoryName)
366-
.getSnapshotInfo(snapshotIdsToLoad, true, task::isCancelled, snapshotInfo -> {
367-
List<SnapshotIndexShardStatus> shardStatusBuilder = new ArrayList<>();
368-
final Map<ShardId, IndexShardSnapshotStatus.Copy> shardStatuses;
369-
shardStatuses = snapshotShards(projectId, repositoryName, repositoryData, task, snapshotInfo);
370-
// an exception here stops further fetches of snapshotInfo since context is fail-fast
371-
for (final var shardStatus : shardStatuses.entrySet()) {
372-
IndexShardSnapshotStatus.Copy lastSnapshotStatus = shardStatus.getValue();
373-
shardStatusBuilder.add(new SnapshotIndexShardStatus(shardStatus.getKey(), lastSnapshotStatus));
374-
}
375-
final SnapshotsInProgress.State state = switch (snapshotInfo.state()) {
376-
case FAILED -> SnapshotsInProgress.State.FAILED;
377-
case SUCCESS, PARTIAL ->
378-
// Both of these means the snapshot has completed.
379-
SnapshotsInProgress.State.SUCCESS;
380-
default -> throw new IllegalArgumentException("Unexpected snapshot state " + snapshotInfo.state());
381-
};
382-
final long startTime = snapshotInfo.startTime();
383-
final long endTime = snapshotInfo.endTime();
384-
assert endTime >= startTime || (endTime == 0L && snapshotInfo.state().completed() == false)
385-
: "Inconsistent timestamps found in SnapshotInfo [" + snapshotInfo + "]";
386-
threadSafeBuilder.add(
387-
new SnapshotStatus(
388-
new Snapshot(projectId, repositoryName, snapshotInfo.snapshotId()),
389-
state,
390-
Collections.unmodifiableList(shardStatusBuilder),
391-
snapshotInfo.includeGlobalState(),
392-
startTime,
393-
// Use current time to calculate overall runtime for in-progress snapshots that have endTime == 0
394-
(endTime == 0 ? threadPool.absoluteTimeInMillis() : endTime) - startTime
395-
)
396-
);
397-
}, delegate.map(v -> new SnapshotsStatusResponse(List.copyOf(threadSafeBuilder))));
365+
final Repository repository = repositoriesService.repository(projectId, repositoryName);
366+
repository.getSnapshotInfo(snapshotIdsToLoad, true, task::isCancelled, snapshotInfo -> {
367+
List<SnapshotIndexShardStatus> shardStatusBuilder = new ArrayList<>();
368+
final Map<ShardId, IndexShardSnapshotStatus.Copy> shardStatuses;
369+
shardStatuses = snapshotShards(projectId, repositoryName, repositoryData, task, snapshotInfo);
370+
// an exception here stops further fetches of snapshotInfo since context is fail-fast
371+
for (final var shardStatus : shardStatuses.entrySet()) {
372+
IndexShardSnapshotStatus.Copy lastSnapshotStatus = shardStatus.getValue();
373+
shardStatusBuilder.add(new SnapshotIndexShardStatus(shardStatus.getKey(), lastSnapshotStatus));
374+
}
375+
final SnapshotsInProgress.State state = switch (snapshotInfo.state()) {
376+
case FAILED -> SnapshotsInProgress.State.FAILED;
377+
case SUCCESS, PARTIAL ->
378+
// Both of these means the snapshot has completed.
379+
SnapshotsInProgress.State.SUCCESS;
380+
default -> throw new IllegalArgumentException("Unexpected snapshot state " + snapshotInfo.state());
381+
};
382+
final long startTime = snapshotInfo.startTime();
383+
final long endTime = snapshotInfo.endTime();
384+
assert endTime >= startTime || (endTime == 0L && snapshotInfo.state().completed() == false)
385+
: "Inconsistent timestamps found in SnapshotInfo [" + snapshotInfo + "]";
386+
threadSafeBuilder.add(
387+
new SnapshotStatus(
388+
new Snapshot(projectId, repositoryName, snapshotInfo.snapshotId()),
389+
state,
390+
Collections.unmodifiableList(shardStatusBuilder),
391+
snapshotInfo.includeGlobalState(),
392+
startTime,
393+
// Use current time to calculate overall runtime for in-progress snapshots that have endTime == 0
394+
(endTime == 0 ? threadPool.absoluteTimeInMillis() : endTime) - startTime
395+
)
396+
);
397+
}, delegate.map(v -> new SnapshotsStatusResponse(List.copyOf(threadSafeBuilder))));
398398
}
399399
}));
400400
}

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,10 +1479,8 @@ private void finalizeSnapshotEntry(Snapshot snapshot, Metadata metadata, Reposit
14791479
final ProjectId projectId = snapshot.getProjectId();
14801480
final Metadata effectiveMetadata;
14811481
if (supportsMultipleProjects) {
1482-
assert ProjectId.DEFAULT.equals(projectId) == false : "should not snapshot for default project when multi-project is enabled";
14831482
effectiveMetadata = Metadata.builder().put(metadata.getProject(projectId)).build();
14841483
} else {
1485-
assert ProjectId.DEFAULT.equals(projectId) : "expect snapshots for only the default project when multi-project is disabled";
14861484
effectiveMetadata = metadata;
14871485
}
14881486
threadPool.executor(ThreadPool.Names.SNAPSHOT).execute(new SnapshotFinalization(snapshot, effectiveMetadata, repositoryData));

0 commit comments

Comments
 (0)