Search in sources :

Example 86 with FileStore

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

the class DefaultStandbyHeadReaderTest method shouldWaitForFlushAndReturnHeadSegmentId.

@Test
public void shouldWaitForFlushAndReturnHeadSegmentId() throws Exception {
    try (FileStore store = newFileStore()) {
        DefaultStandbyHeadReader reader = new DefaultStandbyHeadReader(store, 10_000L);
        assertNotNull(reader.readHeadRecordId());
        assertEquals(store.getRevisions().getPersistedHead().toString(), reader.readHeadRecordId());
    }
}
Also used : FileStore(org.apache.jackrabbit.oak.segment.file.FileStore) Test(org.junit.Test)

Example 87 with FileStore

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

the class OakDirectoryTestBase method largeFile.

@Test
public void largeFile() throws Exception {
    FileStore store = FileStoreBuilder.fileStoreBuilder(tempFolder.getRoot()).withMemoryMapping(false).withBlobStore(getBlackHoleBlobStore()).build();
    SegmentNodeStore nodeStore = SegmentNodeStoreBuilders.builder(store).build();
    IndexDefinition defn = new IndexDefinition(INITIAL_CONTENT, EmptyNodeState.EMPTY_NODE, "/foo");
    Directory directory = getOakDirectoryBuilder(nodeStore.getRoot().builder(), defn).setReadOnly(false).build();
    long expectedSize = ONE_GB * 2 + ONE_MB;
    String fileName = "test";
    writeFile(directory, fileName, expectedSize);
    assertEquals(expectedSize, directory.fileLength(fileName));
    IndexInput input = directory.openInput(fileName, IOContext.DEFAULT);
    readInputToEnd(expectedSize, input);
    store.close();
}
Also used : FileStore(org.apache.jackrabbit.oak.segment.file.FileStore) IndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition) IndexInput(org.apache.lucene.store.IndexInput) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) SegmentNodeStore(org.apache.jackrabbit.oak.segment.SegmentNodeStore) Directory(org.apache.lucene.store.Directory) Test(org.junit.Test)

Example 88 with FileStore

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

the class DataStoreCheckTest method setup.

@Before
public void setup() throws Exception {
    if (S3DataStoreUtils.isS3Configured()) {
        Properties props = S3DataStoreUtils.getS3Config();
        props.setProperty("cacheSize", "0");
        container = props.getProperty(S3Constants.S3_BUCKET);
        DataStore ds = S3DataStoreUtils.getS3DataStore(S3DataStoreUtils.getFixtures().get(0), props, temporaryFolder.newFolder().getAbsolutePath());
        setupDataStore = new DataStoreBlobStore(ds);
        cfgFilePath = createTempConfig(temporaryFolder.newFile(), props);
        dsOption = "s3ds";
    } else if (AzureDataStoreUtils.isAzureConfigured()) {
        Properties props = AzureDataStoreUtils.getAzureConfig();
        props.setProperty("cacheSize", "0");
        container = props.getProperty(AzureConstants.AZURE_BLOB_CONTAINER_NAME);
        DataStore ds = AzureDataStoreUtils.getAzureDataStore(props, temporaryFolder.newFolder().getAbsolutePath());
        setupDataStore = new DataStoreBlobStore(ds);
        cfgFilePath = createTempConfig(temporaryFolder.newFile(), props);
        dsOption = "azureblobds";
    } else {
        OakFileDataStore delegate = new OakFileDataStore();
        dsPath = temporaryFolder.newFolder().getAbsolutePath();
        delegate.setPath(dsPath);
        delegate.init(null);
        setupDataStore = new DataStoreBlobStore(delegate);
        File cfgFile = temporaryFolder.newFile();
        Properties props = new Properties();
        props.put("path", dsPath);
        props.put("minRecordLength", new Long(4096));
        cfgFilePath = createTempConfig(cfgFile, props);
        dsOption = "fds";
    }
    File storeFile = temporaryFolder.newFolder();
    storePath = storeFile.getAbsolutePath();
    FileStore fileStore = FileStoreBuilder.fileStoreBuilder(storeFile).withBlobStore(setupDataStore).withMaxFileSize(256).withSegmentCacheSize(64).build();
    NodeStore store = SegmentNodeStoreBuilders.builder(fileStore).build();
    /* Create nodes with blobs stored in DS*/
    NodeBuilder a = store.getRoot().builder();
    int numBlobs = 10;
    blobsAdded = Sets.newHashSet();
    blobsAddedWithNodes = Maps.newHashMap();
    for (int i = 0; i < numBlobs; i++) {
        SegmentBlob b = (SegmentBlob) store.createBlob(randomStream(i, 18342));
        Iterator<String> idIter = setupDataStore.resolveChunks(b.getBlobId());
        while (idIter.hasNext()) {
            String chunk = idIter.next();
            blobsAdded.add(chunk);
            blobsAddedWithNodes.put(chunk, "/c" + i + "/x");
        }
        a.child("c" + i).setProperty("x", b);
    }
    store.merge(a, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    log.info("Created blobs : {}", blobsAdded);
    fileStore.close();
}
Also used : OakFileDataStore(org.apache.jackrabbit.oak.plugins.blob.datastore.OakFileDataStore) SegmentBlob(org.apache.jackrabbit.oak.segment.SegmentBlob) Properties(java.util.Properties) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) FileStore(org.apache.jackrabbit.oak.segment.file.FileStore) NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) DataStore(org.apache.jackrabbit.core.data.DataStore) OakFileDataStore(org.apache.jackrabbit.oak.plugins.blob.datastore.OakFileDataStore) File(java.io.File) DataStoreBlobStore(org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreBlobStore) Before(org.junit.Before)

Example 89 with FileStore

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

the class DataStoreTestBase method useProxy.

private void useProxy(int skipPosition, int skipBytes, int flipPosition, boolean intermediateChange) throws Exception {
    int blobSize = 5 * MB;
    FileStore primary = getPrimary();
    FileStore secondary = getSecondary();
    NodeStore store = SegmentNodeStoreBuilders.builder(primary).build();
    byte[] data = addTestContent(store, "server", blobSize);
    primary.flush();
    try (StandbyServerSync serverSync = new StandbyServerSync(serverPort.getPort(), primary, MB)) {
        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(), secondary, false, getClientTimeout(), false, spoolFolder)) {
            clientSync.run();
        }
        if (storesShouldBeDifferent()) {
            assertFalse("stores are equal", primary.getHead().equals(secondary.getHead()));
        }
        if (intermediateChange) {
            blobSize = 2 * MB;
            data = addTestContent(store, "server", blobSize);
            primary.flush();
        }
        try (StandbyClientSync clientSync = new StandbyClientSync(getServerHost(), serverPort.getPort(), secondary, false, getClientTimeout(), false, spoolFolder)) {
            clientSync.run();
        }
    }
    assertEquals(primary.getHead(), secondary.getHead());
    assertTrue(primary.getStats().getApproximateSize() < MB);
    assertTrue(secondary.getStats().getApproximateSize() < MB);
    PropertyState ps = secondary.getHead().getChildNode("root").getChildNode("server").getProperty("testBlob");
    assertNotNull(ps);
    assertEquals(Type.BINARY.tag(), ps.getType().tag());
    Blob b = ps.getValue(Type.BINARY);
    assertEquals(blobSize, b.length());
    byte[] testData = new byte[blobSize];
    try (InputStream blobInputStream = b.getNewStream()) {
        ByteStreams.readFully(blobInputStream, testData);
        assertArrayEquals(data, testData);
    }
}
Also used : FileStore(org.apache.jackrabbit.oak.segment.file.FileStore) Blob(org.apache.jackrabbit.oak.api.Blob) NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) StandbyServerSync(org.apache.jackrabbit.oak.segment.standby.server.StandbyServerSync) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) StandbyClientSync(org.apache.jackrabbit.oak.segment.standby.client.StandbyClientSync) File(java.io.File) NetworkErrorProxy(org.apache.jackrabbit.oak.segment.test.proxy.NetworkErrorProxy) PropertyState(org.apache.jackrabbit.oak.api.PropertyState)

Example 90 with FileStore

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

the class DataStoreTestBase method testResilientSync.

@Test
public void testResilientSync() throws Exception {
    final int blobSize = 5 * MB;
    FileStore primary = getPrimary();
    FileStore secondary = getSecondary();
    NodeStore store = SegmentNodeStoreBuilders.builder(primary).build();
    byte[] data = addTestContent(store, "server", blobSize);
    File spoolFolder = folder.newFolder();
    // run 1: unsuccessful
    try (StandbyServerSync serverSync = new StandbyServerSync(serverPort.getPort(), primary, MB);
        StandbyClientSync cl = new StandbyClientSync(getServerHost(), serverPort.getPort(), secondary, false, 4_000, false, spoolFolder)) {
        serverSync.start();
        // no persisted head on primary
        // sync shouldn't be successful, but shouldn't throw exception either,
        // timeout too low for TarMK flush thread to kick-in
        cl.run();
        assertNotEquals(primary.getHead(), secondary.getHead());
    }
    // run 2: successful
    try (StandbyServerSync serverSync = new StandbyServerSync(serverPort.getPort(), primary, MB);
        StandbyClientSync cl = new StandbyClientSync(getServerHost(), serverPort.getPort(), secondary, false, 4_000, false, spoolFolder)) {
        serverSync.start();
        // this time persisted head will be available on primary
        // waited at least 4s + 4s > 5s (TarMK flush thread run frequency)
        cl.run();
        assertEquals(primary.getHead(), secondary.getHead());
    }
    assertTrue(primary.getStats().getApproximateSize() < MB);
    assertTrue(secondary.getStats().getApproximateSize() < MB);
    PropertyState ps = secondary.getHead().getChildNode("root").getChildNode("server").getProperty("testBlob");
    assertNotNull(ps);
    assertEquals(Type.BINARY.tag(), ps.getType().tag());
    Blob b = ps.getValue(Type.BINARY);
    assertEquals(blobSize, b.length());
    byte[] testData = new byte[blobSize];
    try (InputStream blobInputStream = b.getNewStream()) {
        ByteStreams.readFully(blobInputStream, testData);
        assertArrayEquals(data, testData);
    }
}
Also used : FileStore(org.apache.jackrabbit.oak.segment.file.FileStore) Blob(org.apache.jackrabbit.oak.api.Blob) NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) StandbyServerSync(org.apache.jackrabbit.oak.segment.standby.server.StandbyServerSync) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) StandbyClientSync(org.apache.jackrabbit.oak.segment.standby.client.StandbyClientSync) File(java.io.File) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) 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