Search in sources :

Example 71 with FileStore

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

the class Compact method run.

public int run() {
    System.out.printf("Compacting %s with %s\n", path, fileAccessMode.description);
    System.out.printf("    before\n");
    Set<File> beforeFiles = listFiles(path);
    printFiles(System.out, beforeFiles);
    System.out.printf("    size %s\n", printableSize(sizeOfDirectory(path)));
    System.out.printf("    -> compacting\n");
    Stopwatch watch = Stopwatch.createStarted();
    try (FileStore store = newFileStore()) {
        if (!store.compactFull()) {
            System.out.printf("Compaction cancelled after %s.\n", printableStopwatch(watch));
            return 1;
        }
        System.out.printf("    -> cleaning up\n");
        store.cleanup();
        JournalFile journal = new LocalJournalFile(path, "journal.log");
        String head;
        try (JournalReader journalReader = new JournalReader(journal)) {
            head = String.format("%s root %s\n", journalReader.next().getRevision(), System.currentTimeMillis());
        }
        try (JournalFileWriter journalWriter = journal.openJournalWriter()) {
            System.out.printf("    -> writing new %s: %s\n", journal.getName(), head);
            journalWriter.truncate();
            journalWriter.writeLine(head);
        }
    } catch (Exception e) {
        watch.stop();
        e.printStackTrace(System.err);
        System.out.printf("Compaction failed after %s.\n", printableStopwatch(watch));
        return 1;
    }
    watch.stop();
    System.out.printf("    after\n");
    Set<File> afterFiles = listFiles(path);
    printFiles(System.out, afterFiles);
    System.out.printf("    size %s\n", printableSize(sizeOfDirectory(path)));
    System.out.printf("    removed files %s\n", fileNames(difference(beforeFiles, afterFiles)));
    System.out.printf("    added files %s\n", fileNames(difference(afterFiles, beforeFiles)));
    System.out.printf("Compaction succeeded in %s.\n", printableStopwatch(watch));
    return 0;
}
Also used : FileStore(org.apache.jackrabbit.oak.segment.file.FileStore) JournalFileWriter(org.apache.jackrabbit.oak.segment.spi.persistence.JournalFileWriter) LocalJournalFile(org.apache.jackrabbit.oak.segment.file.tar.LocalJournalFile) JournalFile(org.apache.jackrabbit.oak.segment.spi.persistence.JournalFile) Stopwatch(com.google.common.base.Stopwatch) LocalJournalFile(org.apache.jackrabbit.oak.segment.file.tar.LocalJournalFile) LocalJournalFile(org.apache.jackrabbit.oak.segment.file.tar.LocalJournalFile) JournalFile(org.apache.jackrabbit.oak.segment.spi.persistence.JournalFile) File(java.io.File) InvalidFileStoreVersionException(org.apache.jackrabbit.oak.segment.file.InvalidFileStoreVersionException) IOException(java.io.IOException) JournalReader(org.apache.jackrabbit.oak.segment.file.JournalReader)

Example 72 with FileStore

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

the class CheckRepositoryTestBase method addInvalidRevision.

protected void addInvalidRevision() throws InvalidFileStoreVersionException, IOException, CommitFailedException {
    FileStore fileStore = FileStoreBuilder.fileStoreBuilder(temporaryFolder.getRoot()).withMaxFileSize(256).withSegmentCacheSize(64).build();
    SegmentNodeStore nodeStore = SegmentNodeStoreBuilders.builder(fileStore).build();
    NodeBuilder builder = nodeStore.getRoot().builder();
    // add a new child "z"
    addChildWithBlobProperties(nodeStore, builder, "z", 5);
    // add a new property value to existing child "a"
    addChildWithBlobProperties(nodeStore, builder, "a", 1);
    NodeState after = nodeStore.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    // get record number to corrupt (NODE record for "z")
    SegmentNodeState child = (SegmentNodeState) after.getChildNode("z");
    RecordId zRecordId = child.getRecordId();
    // get record number to corrupt (NODE record for "a")
    child = (SegmentNodeState) after.getChildNode("a");
    RecordId aRecordId = child.getRecordId();
    fileStore.close();
    corruptRecord(zRecordId, "data00001a.tar");
    corruptRecord(aRecordId, "data00001a.tar");
}
Also used : FileStore(org.apache.jackrabbit.oak.segment.file.FileStore) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) SegmentNodeState(org.apache.jackrabbit.oak.segment.SegmentNodeState) RecordId(org.apache.jackrabbit.oak.segment.RecordId) SegmentNodeStore(org.apache.jackrabbit.oak.segment.SegmentNodeStore) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) SegmentNodeState(org.apache.jackrabbit.oak.segment.SegmentNodeState)

Example 73 with FileStore

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

the class CheckRepositoryTestBase method addValidRevision.

protected void addValidRevision() throws InvalidFileStoreVersionException, IOException, CommitFailedException {
    FileStore fileStore = FileStoreBuilder.fileStoreBuilder(temporaryFolder.getRoot()).withMaxFileSize(256).withSegmentCacheSize(64).build();
    SegmentNodeStore nodeStore = SegmentNodeStoreBuilders.builder(fileStore).build();
    NodeBuilder builder = nodeStore.getRoot().builder();
    addChildWithBlobProperties(nodeStore, builder, "a", 1);
    addChildWithBlobProperties(nodeStore, builder, "b", 2);
    addChildWithBlobProperties(nodeStore, builder, "c", 3);
    addChildWithProperties(nodeStore, builder, "d", 4);
    addChildWithProperties(nodeStore, builder, "e", 5);
    addChildWithProperties(nodeStore, builder, "f", 6);
    nodeStore.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    // add checkpoints
    String cp1 = nodeStore.checkpoint(10_000);
    String cp2 = nodeStore.checkpoint(10_000);
    checkpoints.add(cp1);
    checkpoints.add(cp2);
    fileStore.close();
}
Also used : FileStore(org.apache.jackrabbit.oak.segment.file.FileStore) SegmentNodeStore(org.apache.jackrabbit.oak.segment.SegmentNodeStore) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder)

Example 74 with FileStore

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

the class BrokenNetworkIT method useProxy.

private void useProxy(boolean ssl, int skipPosition, int skipBytes, int flipPosition, boolean intermediateChange) throws Exception {
    FileStore serverStore = serverFileStore.fileStore();
    FileStore clientStore = clientFileStore1.fileStore();
    NodeStore store = SegmentNodeStoreBuilders.builder(serverStore).build();
    addTestContent(store, "server");
    serverStore.flush();
    try (StandbyServerSync serverSync = new StandbyServerSync(serverPort.getPort(), serverStore, MB, ssl)) {
        serverSync.start();
        File spoolFolder = folder.newFolder();
        try (NetworkErrorProxy ignored = new NetworkErrorProxy(proxyPort.getPort(), getServerHost(), serverPort.getPort(), flipPosition, skipPosition, skipBytes);
            StandbyClientSync clientSync = new StandbyClientSync(getServerHost(), proxyPort.getPort(), clientStore, ssl, getClientTimeout(), false, spoolFolder)) {
            clientSync.run();
        }
        assertFalse("stores are equal", serverStore.getHead().equals(clientStore.getHead()));
        if (intermediateChange) {
            addTestContent(store, "server2");
            serverStore.flush();
        }
        try (StandbyClientSync clientSync = new StandbyClientSync(getServerHost(), serverPort.getPort(), clientStore, ssl, getClientTimeout(), false, spoolFolder)) {
            clientSync.run();
        }
    }
    assertEquals("stores are not equal", serverStore.getHead(), clientStore.getHead());
}
Also used : TemporaryFileStore(org.apache.jackrabbit.oak.segment.test.TemporaryFileStore) FileStore(org.apache.jackrabbit.oak.segment.file.FileStore) NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) StandbyServerSync(org.apache.jackrabbit.oak.segment.standby.server.StandbyServerSync) StandbyClientSync(org.apache.jackrabbit.oak.segment.standby.client.StandbyClientSync) File(java.io.File) NetworkErrorProxy(org.apache.jackrabbit.oak.segment.test.proxy.NetworkErrorProxy)

Example 75 with FileStore

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

the class BrokenNetworkIT method testProxy.

@Test
public void testProxy() throws Exception {
    FileStore serverStore = serverFileStore.fileStore();
    FileStore clientStore = clientFileStore1.fileStore();
    NodeStore store = SegmentNodeStoreBuilders.builder(serverStore).build();
    addTestContent(store, "server");
    serverStore.flush();
    try (StandbyServerSync serverSync = new StandbyServerSync(serverPort.getPort(), serverStore, MB, false);
        StandbyClientSync clientSync = new StandbyClientSync(getServerHost(), serverPort.getPort(), clientStore, false, getClientTimeout(), false, folder.newFolder())) {
        serverSync.start();
        clientSync.run();
    }
    assertEquals(serverStore.getHead(), clientStore.getHead());
}
Also used : TemporaryFileStore(org.apache.jackrabbit.oak.segment.test.TemporaryFileStore) FileStore(org.apache.jackrabbit.oak.segment.file.FileStore) NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) StandbyServerSync(org.apache.jackrabbit.oak.segment.standby.server.StandbyServerSync) StandbyClientSync(org.apache.jackrabbit.oak.segment.standby.client.StandbyClientSync) Test(org.junit.Test)

Aggregations

FileStore (org.apache.jackrabbit.oak.segment.file.FileStore)106 Test (org.junit.Test)70 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)41 File (java.io.File)25 NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)25 StandbyClientSync (org.apache.jackrabbit.oak.segment.standby.client.StandbyClientSync)18 StandbyServerSync (org.apache.jackrabbit.oak.segment.standby.server.StandbyServerSync)18 IOException (java.io.IOException)17 SegmentNodeStore (org.apache.jackrabbit.oak.segment.SegmentNodeStore)15 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)13 SegmentGCOptions (org.apache.jackrabbit.oak.segment.compaction.SegmentGCOptions)13 InvalidFileStoreVersionException (org.apache.jackrabbit.oak.segment.file.InvalidFileStoreVersionException)12 TemporaryFileStore (org.apache.jackrabbit.oak.segment.test.TemporaryFileStore)11 Blob (org.apache.jackrabbit.oak.api.Blob)10 DefaultStatisticsProvider (org.apache.jackrabbit.oak.stats.DefaultStatisticsProvider)10 ByteArrayInputStream (java.io.ByteArrayInputStream)9 FileStoreBuilder (org.apache.jackrabbit.oak.segment.file.FileStoreBuilder)9 Before (org.junit.Before)9 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)8 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)7