Search in sources :

Example 1 with PROP_UNSAFE_FOR_ACTIVE_DELETION

use of org.apache.jackrabbit.oak.plugins.index.lucene.directory.OakDirectory.PROP_UNSAFE_FOR_ACTIVE_DELETION in project jackrabbit-oak by apache.

the class OakDirectoryTestBase method blobsCreatedWhenActiveDeletionIsUnsafe.

// OAK-6950
@Test
public void blobsCreatedWhenActiveDeletionIsUnsafe() throws Exception {
    final int fileSize = 1;
    IndexDefinition def = new IndexDefinition(root, builder.getNodeState(), "/foo");
    BlobFactory factory = in -> {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        IOUtils.copy(in, out);
        byte[] data = out.toByteArray();
        return new ArrayBasedBlob(data);
    };
    final AtomicBoolean markingForceActiveDeletionUnsafe = new AtomicBoolean();
    OakDirectory dir = getOakDirectoryBuilder(builder, def).setReadOnly(false).with(factory).with(new ActiveDeletedBlobCollectorFactory.BlobDeletionCallback() {

        @Override
        public void deleted(String blobId, Iterable<String> ids) {
        }

        @Override
        public void commitProgress(IndexProgress indexProgress) {
        }

        @Override
        public boolean isMarkingForActiveDeletionUnsafe() {
            return markingForceActiveDeletionUnsafe.get();
        }
    }).build();
    // file1 created before marking was flagged as unsafe
    writeFile(dir, "file1", fileSize);
    markingForceActiveDeletionUnsafe.set(true);
    // file2 created after marking was flagged as unsafe
    writeFile(dir, "file2", fileSize);
    dir.close();
    NodeBuilder dataBuilder = builder.getChildNode(INDEX_DATA_CHILD_NAME);
    assertNull("file1 must not get flagged to be unsafe to be actively deleted", dataBuilder.getChildNode("file1").getProperty(PROP_UNSAFE_FOR_ACTIVE_DELETION));
    assertTrue("file2 must get flagged to be unsafe to be actively deleted", dataBuilder.getChildNode("file2").getProperty(PROP_UNSAFE_FOR_ACTIVE_DELETION).getValue(Type.BOOLEAN));
}
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) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition) ArrayBasedBlob(org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob) Test(org.junit.Test)

Aggregations

Iterables (com.google.common.collect.Iterables)1 Sets (com.google.common.collect.Sets)1 Sets.newHashSet (com.google.common.collect.Sets.newHashSet)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Random (java.util.Random)1 Set (java.util.Set)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 ONE_GB (org.apache.commons.io.FileUtils.ONE_GB)1 ONE_MB (org.apache.commons.io.FileUtils.ONE_MB)1 IOUtils (org.apache.commons.io.IOUtils)1 NullInputStream (org.apache.commons.io.input.NullInputStream)1 JCR_DATA (org.apache.jackrabbit.JcrConstants.JCR_DATA)1