Index: oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/standby/client/RemoteBlobProcessor.java =================================================================== --- oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/standby/client/RemoteBlobProcessor.java (revision 1851611) +++ oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/standby/client/RemoteBlobProcessor.java (working copy) @@ -19,6 +19,8 @@ package org.apache.jackrabbit.oak.segment.standby.client; +import static org.apache.jackrabbit.oak.commons.IOUtils.closeQuietly; + import java.io.IOException; import java.io.InputStream; @@ -59,7 +61,59 @@ } private boolean shouldFetchBinary(SegmentBlob blob) { - return blob.isExternal() && blob.getReference() == null && blob.getBlobId() != null; + + // Shortcut: If the Blob ID is null, this is an inline binary and we + // don't have to fetch it. + + String blobId = blob.getBlobId(); + + if (blobId == null) { + return false; + } + + // Shortcut: If the Blob Store is able to retrieve a non-null reference + // to the Blob, we can be sure that the Blob is already stored locally. + // We don't have to download it. + + String reference; + + try { + reference = blob.getReference(); + } catch (Exception e) { + reference = null; + } + + if (reference != null) { + return false; + } + + // Worst case: A null reference to the Blob might just mean that the + // Blob Store doesn't support references. The Blob might still be stored + // locally. We have to retrieve an InputStream for the Blob, and + // perform a tentative read in order to overcome a possible lazy + // implementation of the returned InputStream. + + InputStream data; + + try { + data = blobStore.getInputStream(blobId); + } catch (Exception e) { + return true; + } + + if (data == null) { + return true; + } + + try { + data.read(); + } catch (Exception e) { + return true; + } finally { + closeQuietly(data); + } + + return false; } private void fetchAndStoreBlob(String blobId) throws InterruptedException { Index: oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/standby/client/RemoteBlobProcessorTest.java =================================================================== --- oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/standby/client/RemoteBlobProcessorTest.java (revision 1851611) +++ oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/standby/client/RemoteBlobProcessorTest.java (working copy) @@ -33,7 +33,6 @@ import org.apache.jackrabbit.oak.spi.commit.EmptyHook; import org.apache.jackrabbit.oak.spi.state.NodeBuilder; import org.junit.Assert; -import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.junit.rules.RuleChain; @@ -85,7 +84,6 @@ * downloaded. */ @Test - @Ignore("OAK-6749") public void inMemoryBinaryShouldNotBeDownloaded() throws Exception { SegmentNodeStore store = SegmentNodeStoreBuilders.builder(fileStore.fileStore()).build();