Search in sources :

Example 16 with InvalidFileStoreVersionException

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

the class IOTracerTest method collectBreadthFirstTrace.

@Test
public void collectBreadthFirstTrace() throws IOException, InvalidFileStoreVersionException {
    try (StringWriter out = new StringWriter()) {
        Function<IOMonitor, FileStore> factory = this::createFileStore;
        IOTracer ioTracer = newIOTracer(factory, out, BreadthFirstTrace.CONTEXT_SPEC);
        ioTracer.collectTrace(new BreadthFirstTrace(2, "/", ioTracer::setContext));
        try (BufferedReader reader = new BufferedReader(new StringReader(out.toString()))) {
            Optional<String> header = reader.lines().findFirst();
            List<String[]> entries = reader.lines().map(line -> line.split(",")).collect(toList());
            assertTrue(header.isPresent());
            assertEquals("timestamp,file,segmentId,length,elapsed,depth,count", header.get());
            long now = currentTimeMillis();
            assertTrue("The timestamps of all entries must be in the past", entries.stream().map(// ts
            row -> parseLong(row[0])).allMatch(ts -> ts <= now));
            assertEquals("Expected depths 0, 1 and 2", ImmutableSet.of(0, 1, 2), entries.stream().map(// depth
            row -> parseInt(row[5])).distinct().collect(toSet()));
            assertEquals("Expected max 10 nodes", Optional.of(true), entries.stream().map(// count
            row -> parseInt(row[6])).max(Comparator.naturalOrder()).map(max -> max <= 10));
        }
    }
}
Also used : IOMonitor(org.apache.jackrabbit.oak.segment.spi.monitor.IOMonitor) IOMonitorAdapter(org.apache.jackrabbit.oak.segment.spi.monitor.IOMonitorAdapter) System.currentTimeMillis(java.lang.System.currentTimeMillis) FileStoreBuilder.fileStoreBuilder(org.apache.jackrabbit.oak.segment.file.FileStoreBuilder.fileStoreBuilder) Function(java.util.function.Function) SegmentNodeBuilder(org.apache.jackrabbit.oak.segment.SegmentNodeBuilder) IOTracer.newIOTracer(org.apache.jackrabbit.oak.segment.tool.iotrace.IOTracer.newIOTracer) FileStore(org.apache.jackrabbit.oak.segment.file.FileStore) Nonnull(javax.annotation.Nonnull) Collectors.toSet(java.util.stream.Collectors.toSet) Before(org.junit.Before) SegmentNodeState(org.apache.jackrabbit.oak.segment.SegmentNodeState) InvalidFileStoreVersionException(org.apache.jackrabbit.oak.segment.file.InvalidFileStoreVersionException) ImmutableSet(com.google.common.collect.ImmutableSet) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) StringWriter(java.io.StringWriter) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) Integer.parseInt(java.lang.Integer.parseInt) File(java.io.File) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) Rule(org.junit.Rule) StringReader(java.io.StringReader) Optional(java.util.Optional) BufferedReader(java.io.BufferedReader) Long.parseLong(java.lang.Long.parseLong) Comparator(java.util.Comparator) Assert.assertEquals(org.junit.Assert.assertEquals) TemporaryFolder(org.junit.rules.TemporaryFolder) FileStore(org.apache.jackrabbit.oak.segment.file.FileStore) StringWriter(java.io.StringWriter) BufferedReader(java.io.BufferedReader) StringReader(java.io.StringReader) IOMonitor(org.apache.jackrabbit.oak.segment.spi.monitor.IOMonitor) IOTracer.newIOTracer(org.apache.jackrabbit.oak.segment.tool.iotrace.IOTracer.newIOTracer) Test(org.junit.Test)

Example 17 with InvalidFileStoreVersionException

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

the class IncludeExcludeSidegradeTest method doUpgradeRepository.

@Override
protected void doUpgradeRepository(File source, NodeStore target) throws RepositoryException, IOException {
    FileStore fileStore;
    try {
        fileStore = fileStoreBuilder(source).build();
    } catch (InvalidFileStoreVersionException e) {
        throw new IllegalStateException(e);
    }
    SegmentNodeStore segmentNodeStore = SegmentNodeStoreBuilders.builder(fileStore).build();
    try {
        final RepositorySidegrade sidegrade = new RepositorySidegrade(segmentNodeStore, target);
        sidegrade.setIncludes("/content/foo/en", "/content/assets/foo", "/content/other");
        sidegrade.setExcludes("/content/assets/foo/2013", "/content/assets/foo/2012", "/content/assets/foo/2011", "/content/assets/foo/2010");
        sidegrade.copy();
    } finally {
        fileStore.close();
    }
}
Also used : FileStore(org.apache.jackrabbit.oak.segment.file.FileStore) InvalidFileStoreVersionException(org.apache.jackrabbit.oak.segment.file.InvalidFileStoreVersionException) SegmentNodeStore(org.apache.jackrabbit.oak.segment.SegmentNodeStore)

Example 18 with InvalidFileStoreVersionException

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

the class SegmentTarFactory method create.

@Override
public NodeStore create(BlobStore blobStore, Closer closer) throws IOException {
    final FileStoreBuilder builder = fileStoreBuilder(new File(dir, "segmentstore"));
    if (blobStore != null) {
        builder.withBlobStore(blobStore);
    }
    builder.withMaxFileSize(256);
    if (disableMmap) {
        builder.withMemoryMapping(false);
    } else {
        builder.withDefaultMemoryMapping();
    }
    try {
        if (readOnly) {
            final ReadOnlyFileStore fs;
            fs = builder.buildReadOnly();
            closer.register(asCloseable(fs));
            return SegmentNodeStoreBuilders.builder(fs).build();
        } else {
            final FileStore fs;
            fs = builder.build();
            closer.register(asCloseable(fs));
            return new NodeStoreWithFileStore(SegmentNodeStoreBuilders.builder(fs).build(), fs);
        }
    } catch (InvalidFileStoreVersionException e) {
        throw new IllegalStateException(e);
    }
}
Also used : ReadOnlyFileStore(org.apache.jackrabbit.oak.segment.file.ReadOnlyFileStore) FileStore(org.apache.jackrabbit.oak.segment.file.FileStore) FileStoreBuilder(org.apache.jackrabbit.oak.segment.file.FileStoreBuilder) InvalidFileStoreVersionException(org.apache.jackrabbit.oak.segment.file.InvalidFileStoreVersionException) ReadOnlyFileStore(org.apache.jackrabbit.oak.segment.file.ReadOnlyFileStore) File(java.io.File)

Example 19 with InvalidFileStoreVersionException

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

the class NodeStoreFixtureProvider method create.

public static NodeStoreFixture create(Options options, boolean readOnly) throws Exception {
    CommonOptions commonOpts = options.getOptionBean(CommonOptions.class);
    Closer closer = Closer.create();
    Whiteboard wb = new ClosingWhiteboard(options.getWhiteboard(), closer);
    BlobStoreFixture blobFixture = BlobStoreFixtureProvider.create(options);
    BlobStore blobStore = null;
    if (blobFixture != null) {
        blobStore = blobFixture.getBlobStore();
        closer.register(blobFixture);
    }
    StatisticsProvider statisticsProvider = createStatsProvider(options, wb, closer);
    wb.register(StatisticsProvider.class, statisticsProvider, emptyMap());
    NodeStore store;
    if (commonOpts.isMemory()) {
        store = new MemoryNodeStore();
    } else if (commonOpts.isMongo() || commonOpts.isRDB()) {
        DocumentNodeStore dns = DocumentFixtureProvider.configureDocumentMk(options, blobStore, wb, closer, readOnly);
        store = dns;
        if (blobStore == null) {
            blobStore = dns.getBlobStore();
        }
    } else if (commonOpts.isOldSegment()) {
        store = SegmentFixtureProvider.create(options, blobStore, wb, closer, readOnly);
    } else {
        try {
            store = SegmentTarFixtureProvider.configureSegment(options, blobStore, wb, closer, readOnly);
        } catch (InvalidFileStoreVersionException e) {
            if (oldSegmentStore(options)) {
                store = SegmentFixtureProvider.create(options, blobStore, wb, closer, readOnly);
            } else {
                throw e;
            }
        }
    }
    return new SimpleNodeStoreFixture(store, blobStore, wb, closer);
}
Also used : Closer(com.google.common.io.Closer) DocumentNodeStore(org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore) NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) InvalidFileStoreVersionException(org.apache.jackrabbit.oak.segment.file.InvalidFileStoreVersionException) DocumentNodeStore(org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore) MetricStatisticsProvider(org.apache.jackrabbit.oak.plugins.metric.MetricStatisticsProvider) StatisticsProvider(org.apache.jackrabbit.oak.stats.StatisticsProvider) Whiteboard(org.apache.jackrabbit.oak.spi.whiteboard.Whiteboard) BlobStore(org.apache.jackrabbit.oak.spi.blob.BlobStore)

Aggregations

InvalidFileStoreVersionException (org.apache.jackrabbit.oak.segment.file.InvalidFileStoreVersionException)19 IOException (java.io.IOException)13 File (java.io.File)11 FileStore (org.apache.jackrabbit.oak.segment.file.FileStore)11 FileStoreBuilder (org.apache.jackrabbit.oak.segment.file.FileStoreBuilder)9 FileStoreBuilder.fileStoreBuilder (org.apache.jackrabbit.oak.segment.file.FileStoreBuilder.fileStoreBuilder)5 IOMonitorAdapter (org.apache.jackrabbit.oak.segment.spi.monitor.IOMonitorAdapter)5 NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)5 Function (java.util.function.Function)4 Nonnull (javax.annotation.Nonnull)4 HashMap (java.util.HashMap)3 List (java.util.List)3 IOMonitor (org.apache.jackrabbit.oak.segment.spi.monitor.IOMonitor)3 IOTracer.newIOTracer (org.apache.jackrabbit.oak.segment.tool.iotrace.IOTracer.newIOTracer)3 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)3 Before (org.junit.Before)3 Test (org.junit.Test)3 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)2 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)2 Supplier (com.google.common.base.Supplier)2