Search in sources :

Example 1 with BlobStoreBlob

use of org.apache.jackrabbit.oak.plugins.blob.BlobStoreBlob in project jackrabbit-oak by apache.

the class BlobMigrator method migrateMultiProperty.

private PropertyState migrateMultiProperty(PropertyState propertyState) throws IOException {
    Iterable<Blob> oldBlobs = propertyState.getValue(Type.BINARIES);
    List<Blob> newBlobs = new ArrayList<Blob>();
    PropertyBuilder<Blob> builder = new PropertyBuilder<Blob>(Type.BINARY);
    builder.assignFrom(propertyState);
    boolean blobUpdated = false;
    for (Blob oldBlob : oldBlobs) {
        String blobId = getIdentity(oldBlob);
        if (blobStore.isMigrated(blobId)) {
            newBlobs.add(new BlobStoreBlob(blobStore, blobId));
        } else {
            String newBlobId = blobStore.writeBlob(oldBlob.getNewStream());
            Blob newBlob = new BlobStoreBlob(blobStore, newBlobId);
            newBlobs.add(newBlob);
            blobUpdated = true;
        }
    }
    if (blobUpdated) {
        builder.setValues(newBlobs);
        return builder.getPropertyState();
    } else {
        return null;
    }
}
Also used : BlobStoreBlob(org.apache.jackrabbit.oak.plugins.blob.BlobStoreBlob) Blob(org.apache.jackrabbit.oak.api.Blob) BlobStoreBlob(org.apache.jackrabbit.oak.plugins.blob.BlobStoreBlob) ArrayList(java.util.ArrayList) PropertyBuilder(org.apache.jackrabbit.oak.plugins.memory.PropertyBuilder)

Example 2 with BlobStoreBlob

use of org.apache.jackrabbit.oak.plugins.blob.BlobStoreBlob in project jackrabbit-oak by apache.

the class BlobMigrator method migrateProperty.

private PropertyState migrateProperty(PropertyState propertyState) throws IOException {
    Blob oldBlob = propertyState.getValue(Type.BINARY);
    String blobId = getIdentity(oldBlob);
    if (blobStore.isMigrated(blobId)) {
        return null;
    }
    String newBlobId = blobStore.writeBlob(oldBlob.getNewStream());
    Blob newBlob = new BlobStoreBlob(blobStore, newBlobId);
    PropertyBuilder<Blob> builder = new PropertyBuilder<Blob>(Type.BINARY);
    builder.assignFrom(propertyState);
    builder.setValue(newBlob);
    return builder.getPropertyState();
}
Also used : BlobStoreBlob(org.apache.jackrabbit.oak.plugins.blob.BlobStoreBlob) Blob(org.apache.jackrabbit.oak.api.Blob) BlobStoreBlob(org.apache.jackrabbit.oak.plugins.blob.BlobStoreBlob) PropertyBuilder(org.apache.jackrabbit.oak.plugins.memory.PropertyBuilder)

Example 3 with BlobStoreBlob

use of org.apache.jackrabbit.oak.plugins.blob.BlobStoreBlob in project jackrabbit-oak by apache.

the class BlobTest method testBlobSerialization.

@Test
public void testBlobSerialization() throws Exception {
    TestBlobStore blobStore = new TestBlobStore();
    DocumentMK mk = builderProvider.newBuilder().setBlobStore(blobStore).open();
    BlobSerializer blobSerializer = mk.getNodeStore().getBlobSerializer();
    Blob blob = new BlobStoreBlob(blobStore, "foo");
    assertEquals("foo", blobSerializer.serialize(blob));
    assertEquals(0, blobStore.writeCount);
    blob = new ArrayBasedBlob("foo".getBytes());
    blobSerializer.serialize(blob);
    assertEquals(1, blobStore.writeCount);
    byte[] bytes = "foo".getBytes();
    String blobId = blobStore.writeBlob(new ByteArrayInputStream(bytes));
    String reference = blobStore.getReference(blobId);
    blob = new ReferencedBlob("foo".getBytes(), reference);
    blobStore.writeCount = 0;
    blobSerializer.serialize(blob);
    // Using reference so no reference should be written
    assertEquals(0, blobStore.writeCount);
}
Also used : BlobStoreBlob(org.apache.jackrabbit.oak.plugins.blob.BlobStoreBlob) Blob(org.apache.jackrabbit.oak.api.Blob) ArrayBasedBlob(org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob) BlobStoreBlob(org.apache.jackrabbit.oak.plugins.blob.BlobStoreBlob) ByteArrayInputStream(java.io.ByteArrayInputStream) ArrayBasedBlob(org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob) BlobSerializer(org.apache.jackrabbit.oak.json.BlobSerializer) Test(org.junit.Test)

Example 4 with BlobStoreBlob

use of org.apache.jackrabbit.oak.plugins.blob.BlobStoreBlob in project jackrabbit-oak by apache.

the class DocumentBlobReferenceRetriever method collectReferences.

@Override
public void collectReferences(ReferenceCollector collector) {
    int referencesFound = 0;
    Iterator<ReferencedBlob> blobIterator = null;
    try {
        blobIterator = nodeStore.getReferencedBlobsIterator();
        while (blobIterator.hasNext()) {
            ReferencedBlob refBlob = blobIterator.next();
            Blob blob = refBlob.getBlob();
            referencesFound++;
            if (blob instanceof BlobStoreBlob) {
                collector.addReference(((BlobStoreBlob) blob).getBlobId(), refBlob.getId());
            } else {
                // TODO Should not rely on toString. Instead obtain
                // secure reference and convert that to blobId using
                // blobStore
                collector.addReference(blob.toString(), refBlob.getId());
            }
        }
    } finally {
        Utils.closeIfCloseable(blobIterator);
    }
    log.debug("Total blob references found (including chunk resolution) [{}]", referencesFound);
}
Also used : ReferencedBlob(org.apache.jackrabbit.oak.plugins.blob.ReferencedBlob) ReferencedBlob(org.apache.jackrabbit.oak.plugins.blob.ReferencedBlob) BlobStoreBlob(org.apache.jackrabbit.oak.plugins.blob.BlobStoreBlob) Blob(org.apache.jackrabbit.oak.api.Blob) BlobStoreBlob(org.apache.jackrabbit.oak.plugins.blob.BlobStoreBlob)

Example 5 with BlobStoreBlob

use of org.apache.jackrabbit.oak.plugins.blob.BlobStoreBlob in project jackrabbit-oak by apache.

the class OakDirectoryTestBase method dontMarkInlinedBlobsFromDataStoreAsDeleted.

// OAK-7066
@Test
public void dontMarkInlinedBlobsFromDataStoreAsDeleted() throws Exception {
    IndexDefinition def = new IndexDefinition(root, builder.getNodeState(), "/foo");
    final Set<String> deletedFiles = newHashSet();
    FileDataStore fds = new FileDataStore();
    fds.setMinRecordLength(48);
    fds.init(new File(tempFolder.getRoot(), "fdsRoot").getAbsolutePath());
    DataStoreBlobStore dsbs = new DataStoreBlobStore(fds);
    BlobFactory factory = in -> new BlobStoreBlob(dsbs, dsbs.writeBlob(in));
    OakDirectory dir = getOakDirectoryBuilder(builder, def).setReadOnly(false).with(factory).with(new ActiveDeletedBlobCollectorFactory.BlobDeletionCallback() {

        @Override
        public void deleted(String blobId, Iterable<String> ids) {
            deletedFiles.add(Iterables.getLast(ids));
        }

        @Override
        public void commitProgress(IndexProgress indexProgress) {
        }

        @Override
        public boolean isMarkingForActiveDeletionUnsafe() {
            return false;
        }
    }).build();
    writeFile(dir, "file1", 25);
    writeFile(dir, "file2", 50);
    dir.deleteFile("file1");
    dir.deleteFile("file2");
    dir.close();
    assertFalse("file1 must be reported as deleted", deletedFiles.contains("file1"));
    assertTrue("file2 must be reported as deleted", deletedFiles.contains("file2"));
}
Also used : JCR_DATA(org.apache.jackrabbit.JcrConstants.JCR_DATA) Arrays(java.util.Arrays) GarbageCollectableBlobStore(org.apache.jackrabbit.oak.spi.blob.GarbageCollectableBlobStore) BlobStoreBlob(org.apache.jackrabbit.oak.plugins.blob.BlobStoreBlob) AlreadyClosedException(org.apache.lucene.store.AlreadyClosedException) Random(java.util.Random) Assert.assertThat(org.junit.Assert.assertThat) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Directory(org.apache.lucene.store.Directory) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) UNIQUE_KEY_SIZE(org.apache.jackrabbit.oak.plugins.index.lucene.directory.OakDirectory.UNIQUE_KEY_SIZE) Assert.fail(org.junit.Assert.fail) FileDataStore(org.apache.jackrabbit.core.data.FileDataStore) IOContext(org.apache.lucene.store.IOContext) EmptyNodeState(org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState) PROP_BLOB_SIZE(org.apache.jackrabbit.oak.plugins.index.lucene.directory.OakDirectory.PROP_BLOB_SIZE) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Type(org.apache.jackrabbit.oak.api.Type) Set(java.util.Set) ONE_MB(org.apache.commons.io.FileUtils.ONE_MB) FileNotFoundException(java.io.FileNotFoundException) Sets(com.google.common.collect.Sets) SegmentNodeStore(org.apache.jackrabbit.oak.segment.SegmentNodeStore) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) Assert.assertFalse(org.junit.Assert.assertFalse) NullInputStream(org.apache.commons.io.input.NullInputStream) ArrayBasedBlob(org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob) Iterables(com.google.common.collect.Iterables) ByteArrayOutputStream(java.io.ByteArrayOutputStream) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ArrayList(java.util.ArrayList) LuceneIndexConstants(org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexConstants) SegmentNodeStoreBuilders(org.apache.jackrabbit.oak.segment.SegmentNodeStoreBuilders) FileStore(org.apache.jackrabbit.oak.segment.file.FileStore) ReadOnlyBuilder(org.apache.jackrabbit.oak.spi.state.ReadOnlyBuilder) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) DataStoreBlobStore(org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreBlobStore) SegmentTestConstants(org.apache.jackrabbit.oak.segment.SegmentTestConstants) PropertyStates(org.apache.jackrabbit.oak.plugins.memory.PropertyStates) IndexOutput(org.apache.lucene.store.IndexOutput) PROP_UNSAFE_FOR_ACTIVE_DELETION(org.apache.jackrabbit.oak.plugins.index.lucene.directory.OakDirectory.PROP_UNSAFE_FOR_ACTIVE_DELETION) INDEX_DATA_CHILD_NAME(org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexConstants.INDEX_DATA_CHILD_NAME) ONE_GB(org.apache.commons.io.FileUtils.ONE_GB) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) IndexInput(org.apache.lucene.store.IndexInput) Assert.assertTrue(org.junit.Assert.assertTrue) FileStoreBuilder(org.apache.jackrabbit.oak.segment.file.FileStoreBuilder) IOException(java.io.IOException) Test(org.junit.Test) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) File(java.io.File) InputStreamDataInput(org.apache.lucene.store.InputStreamDataInput) PROP_UNIQUE_KEY(org.apache.jackrabbit.oak.plugins.index.lucene.directory.OakDirectory.PROP_UNIQUE_KEY) IndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition) Assert.assertNull(org.junit.Assert.assertNull) Rule(org.junit.Rule) MemoryBlobStore(org.apache.jackrabbit.oak.spi.blob.MemoryBlobStore) Blob(org.apache.jackrabbit.oak.api.Blob) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) INITIAL_CONTENT(org.apache.jackrabbit.oak.InitialContent.INITIAL_CONTENT) Assert.assertEquals(org.junit.Assert.assertEquals) TemporaryFolder(org.junit.rules.TemporaryFolder) InputStream(java.io.InputStream) BlobStoreBlob(org.apache.jackrabbit.oak.plugins.blob.BlobStoreBlob) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) IndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition) FileDataStore(org.apache.jackrabbit.core.data.FileDataStore) File(java.io.File) DataStoreBlobStore(org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreBlobStore) Test(org.junit.Test)

Aggregations

BlobStoreBlob (org.apache.jackrabbit.oak.plugins.blob.BlobStoreBlob)8 Blob (org.apache.jackrabbit.oak.api.Blob)7 Test (org.junit.Test)5 ArrayBasedBlob (org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob)4 File (java.io.File)3 ArrayList (java.util.ArrayList)3 FileDataStore (org.apache.jackrabbit.core.data.FileDataStore)3 DataStoreBlobStore (org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreBlobStore)3 Iterables (com.google.common.collect.Iterables)2 Sets (com.google.common.collect.Sets)2 Sets.newHashSet (com.google.common.collect.Sets.newHashSet)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 Arrays (java.util.Arrays)2 List (java.util.List)2 Random (java.util.Random)2 Set (java.util.Set)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2