Skip to content

Commit 01d0865

Browse files
authored
Correctly log exceptions that are thrown during cache prewarming (#74419)
Today if an exception is thrown during the prewarming of (parts of) the files it is simply swallowed. This is confusing because the shard recovery state is left in a FINALIZE state but nothing in the logs can help troubleshooting why the recovery has been interrupted. This commit adds log traces to warn when an exception occurred during the prewarming of a part of a file.
1 parent d03a69c commit 01d0865

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/store/SearchableSnapshotDirectory.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -506,8 +506,9 @@ private void prewarmCache(ActionListener<Void> listener) {
506506
}, listener::onFailure), snapshot().totalFileCount());
507507

508508
for (BlobStoreIndexShardSnapshot.FileInfo file : snapshot().indexFiles()) {
509-
if (file.metadata().hashEqualsContents() || isExcludedFromCache(file.physicalName())) {
510-
if (file.metadata().hashEqualsContents()) {
509+
boolean hashEqualsContents = file.metadata().hashEqualsContents();
510+
if (hashEqualsContents || isExcludedFromCache(file.physicalName())) {
511+
if (hashEqualsContents) {
511512
recoveryState.getIndex().addFileDetail(file.physicalName(), file.length(), true);
512513
} else {
513514
recoveryState.ignoreFile(file.physicalName());
@@ -516,17 +517,24 @@ private void prewarmCache(ActionListener<Void> listener) {
516517
continue;
517518
}
518519
recoveryState.getIndex().addFileDetail(file.physicalName(), file.length(), false);
520+
boolean submitted = false;
519521
try {
520522
final IndexInput input = openInput(file.physicalName(), CachedBlobContainerIndexInput.CACHE_WARMING_CONTEXT);
521523
assert input instanceof CachedBlobContainerIndexInput : "expected cached index input but got " + input.getClass();
522524

523525
final int numberOfParts = file.numberOfParts();
524526
final StepListener<Collection<Void>> fileCompletionListener = new StepListener<>();
525-
fileCompletionListener.whenComplete(voids -> input.close(), e -> IOUtils.closeWhileHandlingException(input));
526527
fileCompletionListener.addListener(completionListener.map(voids -> null));
528+
fileCompletionListener.whenComplete(voids -> {
529+
logger.debug("{} file [{}] prewarmed", shardId, file.physicalName());
530+
input.close();
531+
}, e -> {
532+
logger.warn(() -> new ParameterizedMessage("{} prewarming failed for file [{}]", shardId, file.physicalName()), e);
533+
IOUtils.closeWhileHandlingException(input);
534+
});
527535

528536
final GroupedActionListener<Void> partsListener = new GroupedActionListener<>(fileCompletionListener, numberOfParts);
529-
537+
submitted = true;
530538
for (int p = 0; p < numberOfParts; p++) {
531539
final int part = p;
532540
queue.add(Tuple.tuple(partsListener, () -> {
@@ -555,6 +563,9 @@ private void prewarmCache(ActionListener<Void> listener) {
555563
}
556564
} catch (IOException e) {
557565
logger.warn(() -> new ParameterizedMessage("{} unable to prewarm file [{}]", shardId, file.physicalName()), e);
566+
if (submitted == false) {
567+
completionListener.onFailure(e);
568+
}
558569
}
559570
}
560571

0 commit comments

Comments
 (0)