Author: frm Date: Fri Jan 18 13:59:34 2019 New Revision: 1851619 URL: http://svn.apache.org/viewvc?rev=1851619&view=rev Log: OAK-6749 - Don't trigger a binary download request for in-memory Blob IDs
Modified: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/standby/client/RemoteBlobProcessor.java jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/standby/client/RemoteBlobProcessorTest.java Modified: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/standby/client/RemoteBlobProcessor.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/standby/client/RemoteBlobProcessor.java?rev=1851619&r1=1851618&r2=1851619&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/standby/client/RemoteBlobProcessor.java (original) +++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/standby/client/RemoteBlobProcessor.java Fri Jan 18 13:59:34 2019 @@ -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 @@ class RemoteBlobProcessor implements Blo } 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 { Modified: jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/standby/client/RemoteBlobProcessorTest.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/standby/client/RemoteBlobProcessorTest.java?rev=1851619&r1=1851618&r2=1851619&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/standby/client/RemoteBlobProcessorTest.java (original) +++ jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/standby/client/RemoteBlobProcessorTest.java Fri Jan 18 13:59:34 2019 @@ -33,7 +33,6 @@ import org.apache.jackrabbit.oak.spi.com 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 @@ public class RemoteBlobProcessorTest { * downloaded. */ @Test - @Ignore("OAK-6749") public void inMemoryBinaryShouldNotBeDownloaded() throws Exception { SegmentNodeStore store = SegmentNodeStoreBuilders.builder(fileStore.fileStore()).build();