Search in sources :

Example 1 with SegmentWriter

use of org.apache.jackrabbit.oak.segment.SegmentWriter in project jackrabbit-oak by apache.

the class FileStoreIT method segmentOverflow.

// See OAK-2049
@Test
public void segmentOverflow() throws Exception {
    for (int n = 1; n < 255; n++) {
        // 255 = ListRecord.LEVEL_SIZE
        FileStore store = fileStoreBuilder(getFileStoreFolder()).withMaxFileSize(1).withMemoryMapping(false).build();
        SegmentWriter writer = store.getWriter();
        // adding 15 strings with 16516 bytes each
        for (int k = 0; k < 15; k++) {
            // 16516 = (Segment.MEDIUM_LIMIT - 1 + 2 + 3)
            // 1 byte per char, 2 byte to store the length and 3 bytes for the
            // alignment to the integer boundary
            writer.writeString(Strings.repeat("abcdefghijklmno".substring(k, k + 1), SegmentTestConstants.MEDIUM_LIMIT - 1));
        }
        // adding 14280 bytes. 1 byte per char, and 2 bytes to store the length
        RecordId x = writer.writeString(Strings.repeat("x", 14278));
        // writer.length == 262052
        // Adding 765 bytes (255 recordIds)
        // This should cause the current segment to flush
        List<RecordId> list = Collections.nCopies(n, x);
        writer.writeList(list);
        writer.flush();
        // Don't close the store in a finally clause as if a failure happens
        // this will also fail an cover up the earlier exception
        store.close();
    }
}
Also used : RecordId(org.apache.jackrabbit.oak.segment.RecordId) SegmentWriter(org.apache.jackrabbit.oak.segment.SegmentWriter) Test(org.junit.Test)

Example 2 with SegmentWriter

use of org.apache.jackrabbit.oak.segment.SegmentWriter in project jackrabbit-oak by apache.

the class FileStoreBackupImpl method backup.

@Override
public void backup(@Nonnull SegmentReader reader, @Nonnull Revisions revisions, @Nonnull File destination) throws IOException, InvalidFileStoreVersionException {
    Stopwatch watch = Stopwatch.createStarted();
    SegmentGCOptions gcOptions = SegmentGCOptions.defaultGCOptions().setOffline();
    FileStoreBuilder builder = fileStoreBuilder(destination).withStrictVersionCheck(true).withDefaultMemoryMapping();
    if (USE_FAKE_BLOBSTORE) {
        builder.withBlobStore(new BasicReadOnlyBlobStore());
    }
    builder.withGCOptions(gcOptions);
    FileStore backup = builder.build();
    SegmentNodeState current = reader.readHeadState(revisions);
    try {
        GCGeneration gen = current.getRecordId().getSegmentId().getGcGeneration();
        SegmentBufferWriter bufferWriter = new SegmentBufferWriter(backup.getSegmentIdProvider(), backup.getReader(), "b", gen);
        SegmentWriter writer = new DefaultSegmentWriter(backup, backup.getReader(), backup.getSegmentIdProvider(), backup.getBlobStore(), new WriterCacheManager.Default(), bufferWriter);
        Compactor compactor = new Compactor(backup.getReader(), writer, backup.getBlobStore(), Suppliers.ofInstance(false), GCNodeWriteMonitor.EMPTY);
        SegmentNodeState head = backup.getHead();
        SegmentNodeState after = compactor.compact(head, current, head);
        writer.flush();
        if (after != null) {
            backup.getRevisions().setHead(head.getRecordId(), after.getRecordId());
        }
    } finally {
        backup.close();
    }
    backup = fileStoreBuilder(destination).withDefaultMemoryMapping().withGCOptions(gcOptions).withStrictVersionCheck(true).build();
    try {
        cleanup(backup);
    } finally {
        backup.close();
    }
    watch.stop();
    log.info("Backup finished in {}.", watch);
}
Also used : SegmentGCOptions(org.apache.jackrabbit.oak.segment.compaction.SegmentGCOptions) SegmentBufferWriter(org.apache.jackrabbit.oak.segment.SegmentBufferWriter) Stopwatch(com.google.common.base.Stopwatch) SegmentNodeState(org.apache.jackrabbit.oak.segment.SegmentNodeState) DefaultSegmentWriter(org.apache.jackrabbit.oak.segment.DefaultSegmentWriter) BasicReadOnlyBlobStore(org.apache.jackrabbit.oak.segment.file.tooling.BasicReadOnlyBlobStore) FileStore(org.apache.jackrabbit.oak.segment.file.FileStore) Compactor(org.apache.jackrabbit.oak.segment.Compactor) FileStoreBuilder(org.apache.jackrabbit.oak.segment.file.FileStoreBuilder) WriterCacheManager(org.apache.jackrabbit.oak.segment.WriterCacheManager) SegmentWriter(org.apache.jackrabbit.oak.segment.SegmentWriter) DefaultSegmentWriter(org.apache.jackrabbit.oak.segment.DefaultSegmentWriter) GCGeneration(org.apache.jackrabbit.oak.segment.file.tar.GCGeneration)

Example 3 with SegmentWriter

use of org.apache.jackrabbit.oak.segment.SegmentWriter in project jackrabbit-oak by apache.

the class DefaultStandbyReferenceReaderTest method shouldReturnEmptyReferences.

@Test
public void shouldReturnEmptyReferences() throws Exception {
    try (FileStore store = newFileStore()) {
        SegmentWriter writer = defaultSegmentWriterBuilder("test").build(store);
        RecordId id = writer.writeNode(EmptyNodeState.EMPTY_NODE);
        writer.flush();
        DefaultStandbyReferencesReader reader = new DefaultStandbyReferencesReader(store);
        Iterable<String> references = reader.readReferences(id.getSegmentId().asUUID().toString());
        assertFalse(references.iterator().hasNext());
    }
}
Also used : FileStore(org.apache.jackrabbit.oak.segment.file.FileStore) RecordId(org.apache.jackrabbit.oak.segment.RecordId) SegmentWriter(org.apache.jackrabbit.oak.segment.SegmentWriter) Test(org.junit.Test)

Example 4 with SegmentWriter

use of org.apache.jackrabbit.oak.segment.SegmentWriter in project jackrabbit-oak by apache.

the class FileStoreRestoreImpl method restore.

@Override
public void restore(File source, File destination) throws IOException, InvalidFileStoreVersionException {
    if (!validFileStore(source)) {
        throw new IOException("Folder " + source + " is not a valid FileStore directory");
    }
    ReadOnlyFileStore restore = fileStoreBuilder(source).buildReadOnly();
    Stopwatch watch = Stopwatch.createStarted();
    FileStore store = fileStoreBuilder(destination).withStrictVersionCheck(true).build();
    SegmentNodeState current = store.getHead();
    try {
        SegmentNodeState head = restore.getHead();
        GCGeneration gen = head.getRecordId().getSegmentId().getGcGeneration();
        SegmentBufferWriter bufferWriter = new SegmentBufferWriter(store.getSegmentIdProvider(), store.getReader(), "r", gen);
        SegmentWriter writer = new DefaultSegmentWriter(store, store.getReader(), store.getSegmentIdProvider(), store.getBlobStore(), new WriterCacheManager.Default(), bufferWriter);
        SegmentGCOptions gcOptions = defaultGCOptions().setOffline();
        Compactor compactor = new Compactor(store.getReader(), writer, store.getBlobStore(), Suppliers.ofInstance(false), GCNodeWriteMonitor.EMPTY);
        SegmentNodeState after = compactor.compact(current, head, current);
        writer.flush();
        store.getRevisions().setHead(current.getRecordId(), after.getRecordId());
    } finally {
        restore.close();
        store.close();
    }
    watch.stop();
    log.info("Restore finished in {}.", watch);
}
Also used : SegmentGCOptions(org.apache.jackrabbit.oak.segment.compaction.SegmentGCOptions) ReadOnlyFileStore(org.apache.jackrabbit.oak.segment.file.ReadOnlyFileStore) SegmentBufferWriter(org.apache.jackrabbit.oak.segment.SegmentBufferWriter) Stopwatch(com.google.common.base.Stopwatch) IOException(java.io.IOException) SegmentNodeState(org.apache.jackrabbit.oak.segment.SegmentNodeState) DefaultSegmentWriter(org.apache.jackrabbit.oak.segment.DefaultSegmentWriter) ReadOnlyFileStore(org.apache.jackrabbit.oak.segment.file.ReadOnlyFileStore) FileStore(org.apache.jackrabbit.oak.segment.file.FileStore) Compactor(org.apache.jackrabbit.oak.segment.Compactor) WriterCacheManager(org.apache.jackrabbit.oak.segment.WriterCacheManager) SegmentWriter(org.apache.jackrabbit.oak.segment.SegmentWriter) DefaultSegmentWriter(org.apache.jackrabbit.oak.segment.DefaultSegmentWriter) GCGeneration(org.apache.jackrabbit.oak.segment.file.tar.GCGeneration)

Example 5 with SegmentWriter

use of org.apache.jackrabbit.oak.segment.SegmentWriter in project jackrabbit-oak by apache.

the class DefaultStandbyReferenceReaderTest method shouldReturnReferences.

@Test
public void shouldReturnReferences() throws Exception {
    try (FileStore store = newFileStore()) {
        SegmentWriter writer = defaultSegmentWriterBuilder("test").build(store);
        RecordId a = writer.writeNode(EmptyNodeState.EMPTY_NODE);
        writer.flush();
        NodeBuilder builder = EmptyNodeState.EMPTY_NODE.builder();
        builder.setChildNode("reference", store.getReader().readNode(a));
        RecordId b = writer.writeNode(builder.getNodeState());
        writer.flush();
        DefaultStandbyReferencesReader reader = new DefaultStandbyReferencesReader(store);
        Iterator<String> i = reader.readReferences(b.getSegmentId().asUUID().toString()).iterator();
        assertTrue(i.hasNext());
        assertEquals(a.getSegmentId().asUUID().toString(), i.next());
        assertFalse(i.hasNext());
    }
}
Also used : FileStore(org.apache.jackrabbit.oak.segment.file.FileStore) RecordId(org.apache.jackrabbit.oak.segment.RecordId) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) SegmentWriter(org.apache.jackrabbit.oak.segment.SegmentWriter) Test(org.junit.Test)

Aggregations

SegmentWriter (org.apache.jackrabbit.oak.segment.SegmentWriter)6 FileStore (org.apache.jackrabbit.oak.segment.file.FileStore)4 RecordId (org.apache.jackrabbit.oak.segment.RecordId)3 SegmentNodeState (org.apache.jackrabbit.oak.segment.SegmentNodeState)3 Test (org.junit.Test)3 Stopwatch (com.google.common.base.Stopwatch)2 IOException (java.io.IOException)2 Compactor (org.apache.jackrabbit.oak.segment.Compactor)2 DefaultSegmentWriter (org.apache.jackrabbit.oak.segment.DefaultSegmentWriter)2 SegmentBufferWriter (org.apache.jackrabbit.oak.segment.SegmentBufferWriter)2 WriterCacheManager (org.apache.jackrabbit.oak.segment.WriterCacheManager)2 SegmentGCOptions (org.apache.jackrabbit.oak.segment.compaction.SegmentGCOptions)2 GCGeneration (org.apache.jackrabbit.oak.segment.file.tar.GCGeneration)2 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)2 Supplier (com.google.common.base.Supplier)1 Nonnull (javax.annotation.Nonnull)1 FileStoreBuilder (org.apache.jackrabbit.oak.segment.file.FileStoreBuilder)1 ReadOnlyFileStore (org.apache.jackrabbit.oak.segment.file.ReadOnlyFileStore)1 BasicReadOnlyBlobStore (org.apache.jackrabbit.oak.segment.file.tooling.BasicReadOnlyBlobStore)1