Source:
private void processProbe() { verify(probe != null); SpillInfoSnapshot spillInfoSnapshot; long joinPositionWithinPartition; try (LookupSourceLease lookupSourceLease = lookupSourceProvider.leaseLookupSource()) { if (lookupSourceLease.spillEpoch() == inputPageSpillEpoch) { processProbe(lookupSourceLease.getLookupSource()); return; } spillInfoSnapshot = SpillInfoSnapshot.from(lookupSourceLease); if (joinPosition >= 0) { joinPositionWithinPartition = lookupSourceLease.getLookupSource().joinPositionWithinPartition(joinPosition); } else { joinPositionWithinPartition = -1; } } verify(spillInfoSnapshot.hasSpilled); verify(spillInfoSnapshot.spillEpoch > inputPageSpillEpoch); Page currentPage = probe.getPage(); int currentPosition = probe.getPosition(); long currentJoinPosition = this.joinPosition; boolean currentProbePositionProducedRow = this.currentProbePositionProducedRow; int joinSourcePositions = this.joinSourcePositions; probe = null; if (currentPosition < 0) { addInput(currentPage, spillInfoSnapshot); } else { int currentRowPartition = getPartitionGenerator().getPartition(currentPage, currentPosition); boolean currentRowSpilled = spillInfoSnapshot.spillMask.test(currentRowPartition); if (currentRowSpilled) { savedRows.merge( currentRowPartition, new SavedRow(currentPage, currentPosition, currentJoinPosition, joinPositionWithinPartition, currentProbePositionProducedRow, joinSourcePositions), (oldValue, newValue) -> { throw new IllegalStateException(format("How on earth this could happen that partition %s is spilled in the middle of processing twice?", currentRowPartition)); }); Page unprocessed = pageSlice(currentPage, currentPosition + 1); addInput(unprocessed, spillInfoSnapshot); } else { Page remaining = pageSlice(currentPage, currentPosition); restoreProbe(remaining, currentJoinPosition, currentProbePositionProducedRow, joinSourcePositions, spillInfoSnapshot); } } }

Target:
private void processProbe() { verify(probe != null); Optional<SpillInfoSnapshot> spillInfoSnapshotIfSpillChanged = lookupSourceProvider.withLease(lookupSourceLease -> { if (lookupSourceLease.spillEpoch() == inputPageSpillEpoch) { processProbe(lookupSourceLease.getLookupSource()); return Optional.empty(); } return Optional.of(SpillInfoSnapshot.from(lookupSourceLease)); }); if (!spillInfoSnapshotIfSpillChanged.isPresent()) { return; } SpillInfoSnapshot spillInfoSnapshot = spillInfoSnapshotIfSpillChanged.get(); long joinPositionWithinPartition; if (joinPosition >= 0) { joinPositionWithinPartition = lookupSourceProvider.withLease(lookupSourceLease -> lookupSourceLease.getLookupSource().joinPositionWithinPartition(joinPosition)); } else { joinPositionWithinPartition = -1; } verify(spillInfoSnapshot.hasSpilled()); verify(spillInfoSnapshot.getSpillEpoch() > inputPageSpillEpoch); Page currentPage = probe.getPage(); int currentPosition = probe.getPosition(); long currentJoinPosition = this.joinPosition; boolean currentProbePositionProducedRow = this.currentProbePositionProducedRow; probe = null; if (currentPosition < 0) { addInput(currentPage, spillInfoSnapshot); } else { int currentRowPartition = getPartitionGenerator().getPartition(currentPage, currentPosition); boolean currentRowSpilled = spillInfoSnapshot.getSpillMask().test(currentRowPartition); if (currentRowSpilled) { savedRows.merge( currentRowPartition, new SavedRow(currentPage, currentPosition, joinPositionWithinPartition, currentProbePositionProducedRow, joinSourcePositions), (oldValue, newValue) -> { throw new IllegalStateException(format("Partition %s is already spilled", currentRowPartition)); }); joinSourcePositions = 0; Page unprocessed = pageTail(currentPage, currentPosition + 1); addInput(unprocessed, spillInfoSnapshot); } else { Page remaining = pageTail(currentPage, currentPosition); restoreProbe(remaining, currentJoinPosition, currentProbePositionProducedRow, joinSourcePositions, spillInfoSnapshot); } } }