Skip to content

Commit 0c41d29

Browse files
committed
Make writerWithOffset fully delegate to the writer it wraps
writerWithOffset uses a lambda to create a RangeMissingHandler however, the RangeMissingHandler interface has a default implementation for `sharedInputStreamFactory`. This makes `writerWithOffset` delegate to the received writer only for the `fillCacheRange` method where the writer itself perhaps didn't have the `sharedInputStream` method invoked (always invoking `sharedInputStream` before `fillCacheRange` is part of the contract of the RangeMissingHandler interface) This PR makes `writerWithOffset` delegate the `sharedInputStream` to the underlying writer.
1 parent 115062c commit 0c41d29

File tree

1 file changed

+28
-9
lines changed

1 file changed

+28
-9
lines changed

x-pack/plugin/blob-cache/src/main/java/org/elasticsearch/blobcache/shared/SharedBlobCacheService.java

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -648,15 +648,34 @@ private RangeMissingHandler writerWithOffset(RangeMissingHandler writer, int wri
648648
// no need to allocate a new capturing lambda if the offset isn't adjusted
649649
return writer;
650650
}
651-
return (channel, channelPos, streamFactory, relativePos, len, progressUpdater, completionListener) -> writer.fillCacheRange(
652-
channel,
653-
channelPos,
654-
streamFactory,
655-
relativePos - writeOffset,
656-
len,
657-
progressUpdater,
658-
completionListener
659-
);
651+
652+
return new RangeMissingHandler() {
653+
@Override
654+
public void fillCacheRange(
655+
SharedBytes.IO channel,
656+
int channelPos,
657+
SourceInputStreamFactory streamFactory,
658+
int relativePos,
659+
int length,
660+
IntConsumer progressUpdater,
661+
ActionListener<Void> completionListener
662+
) throws IOException {
663+
writer.fillCacheRange(
664+
channel,
665+
channelPos,
666+
streamFactory,
667+
relativePos - writeOffset,
668+
length,
669+
progressUpdater,
670+
completionListener
671+
);
672+
}
673+
674+
@Override
675+
public SourceInputStreamFactory sharedInputStreamFactory(List<SparseFileTracker.Gap> gaps) {
676+
return writer.sharedInputStreamFactory(gaps);
677+
}
678+
};
660679
}
661680

662681
// used by tests

0 commit comments

Comments
 (0)