Search in sources :

Example 21 with StandbyServerSync

use of org.apache.jackrabbit.oak.segment.standby.server.StandbyServerSync in project jackrabbit-oak by apache.

the class StandbyTestIT method testSyncLoop.

/**
 * OAK-2430
 */
@Test
public void testSyncLoop() throws Exception {
    final int blobSize = 25 * 1024;
    final int dataNodes = 5000;
    FileStore primary = serverFileStore.fileStore();
    FileStore secondary = clientFileStore.fileStore();
    NodeStore store = SegmentNodeStoreBuilders.builder(primary).build();
    try (StandbyServerSync serverSync = new StandbyServerSync(serverPort.getPort(), primary, MB);
        StandbyClientSync clientSync = new StandbyClientSync(getServerHost(), serverPort.getPort(), secondary, false, getClientTimeout(), false, folder.newFolder())) {
        serverSync.start();
        byte[] data = addTestContent(store, "server", blobSize, dataNodes);
        primary.flush();
        for (int i = 0; i < 5; i++) {
            String cp = store.checkpoint(Long.MAX_VALUE);
            primary.flush();
            clientSync.run();
            assertEquals(primary.getHead(), secondary.getHead());
            assertTrue(store.release(cp));
            clientSync.cleanup();
            assertTrue(secondary.getStats().getApproximateSize() > blobSize);
        }
        assertTrue(primary.getStats().getApproximateSize() > blobSize);
        assertTrue(secondary.getStats().getApproximateSize() > blobSize);
        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];
        ByteStreams.readFully(b.getNewStream(), testData);
        assertArrayEquals(data, testData);
    }
}
Also used : TemporaryFileStore(org.apache.jackrabbit.oak.segment.test.TemporaryFileStore) 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) StandbyClientSync(org.apache.jackrabbit.oak.segment.standby.client.StandbyClientSync) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) Test(org.junit.Test)

Example 22 with StandbyServerSync

use of org.apache.jackrabbit.oak.segment.standby.server.StandbyServerSync in project jackrabbit-oak by apache.

the class StandbyTestIT method testSync.

@Test
public void testSync() throws Exception {
    int blobSize = 5 * MB;
    FileStore primary = serverFileStore.fileStore();
    FileStore secondary = clientFileStore.fileStore();
    NodeStore store = SegmentNodeStoreBuilders.builder(primary).build();
    try (StandbyServerSync serverSync = new StandbyServerSync(serverPort.getPort(), primary, MB);
        StandbyClientSync clientSync = new StandbyClientSync(getServerHost(), serverPort.getPort(), secondary, false, getClientTimeout(), false, folder.newFolder())) {
        serverSync.start();
        byte[] data = addTestContent(store, "server", blobSize, 150);
        primary.flush();
        clientSync.run();
        assertEquals(primary.getHead(), secondary.getHead());
        assertTrue(primary.getStats().getApproximateSize() > blobSize);
        assertTrue(secondary.getStats().getApproximateSize() > blobSize);
        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];
        ByteStreams.readFully(b.getNewStream(), testData);
        assertArrayEquals(data, testData);
    }
}
Also used : TemporaryFileStore(org.apache.jackrabbit.oak.segment.test.TemporaryFileStore) 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) StandbyClientSync(org.apache.jackrabbit.oak.segment.standby.client.StandbyClientSync) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) Test(org.junit.Test)

Example 23 with StandbyServerSync

use of org.apache.jackrabbit.oak.segment.standby.server.StandbyServerSync in project jackrabbit-oak by apache.

the class SegmentTarFixture method attachStandby.

/**
 * Attaches a standby instance located at index (n+i) in the cluster to the
 * primary located at index i
 *
 * @param i
 *            the primary index
 * @param n
 *            the number of primary instances in the cluster
 * @param statsProvider
 *            statistics provider for the file/blob store(s)
 * @param blobStore
 *            the blob store used by the primary (can be <code>null</code>)
 * @throws InvalidFileStoreVersionException
 *             if an incorrect oak-segment-tar version is used
 * @throws IOException
 *             if the file store manifest cannot be saved
 */
private void attachStandby(int i, int n, StatisticsProvider statsProvider, BlobStore blobStore) throws InvalidFileStoreVersionException, IOException {
    FileStoreBuilder builder = fileStoreBuilder(new File(parentPath, "standby-" + i));
    if (useBlobStore) {
        if (shareBlobStore) {
            builder.withBlobStore(blobStore);
        } else {
            blobStoreFixtures[n + i] = BlobStoreFixture.create(parentPath, true, dsCacheSize, statsProvider);
            builder.withBlobStore(blobStoreFixtures[n + i].setUp());
        }
    }
    SegmentGCOptions gcOptions = SegmentGCOptions.defaultGCOptions().setRetainedGenerations(1);
    stores[n + i] = builder.withGCOptions(gcOptions).withMaxFileSize(maxFileSize).withStatisticsProvider(statsProvider).withSegmentCacheSize(segmentCacheSize).withMemoryMapping(memoryMapping).withSnfeListener(IGNORE_SNFE).build();
    int port = 0;
    try (ServerSocket socket = new ServerSocket(0)) {
        port = socket.getLocalPort();
    }
    serverSyncs[i] = new StandbyServerSync(port, stores[i], 1 * MB, secure);
    clientSyncs[i] = new StandbyClientSync("127.0.0.1", port, stores[n + i], secure, DEFAULT_TIMEOUT, false, new File(StandardSystemProperty.JAVA_IO_TMPDIR.value()));
    if (!oneShotRun) {
        serverSyncs[i].start();
        clientSyncs[i].start();
        executors[i] = Executors.newScheduledThreadPool(1);
        executors[i].scheduleAtFixedRate(clientSyncs[i], 0, syncInterval, TimeUnit.SECONDS);
    }
}
Also used : SegmentGCOptions(org.apache.jackrabbit.oak.segment.compaction.SegmentGCOptions) FileStoreBuilder(org.apache.jackrabbit.oak.segment.file.FileStoreBuilder) StandbyServerSync(org.apache.jackrabbit.oak.segment.standby.server.StandbyServerSync) StandbyClientSync(org.apache.jackrabbit.oak.segment.standby.client.StandbyClientSync) ServerSocket(java.net.ServerSocket) File(java.io.File)

Aggregations

StandbyServerSync (org.apache.jackrabbit.oak.segment.standby.server.StandbyServerSync)23 StandbyClientSync (org.apache.jackrabbit.oak.segment.standby.client.StandbyClientSync)21 FileStore (org.apache.jackrabbit.oak.segment.file.FileStore)18 Test (org.junit.Test)16 NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)15 TemporaryFileStore (org.apache.jackrabbit.oak.segment.test.TemporaryFileStore)12 Blob (org.apache.jackrabbit.oak.api.Blob)6 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)6 ByteArrayInputStream (java.io.ByteArrayInputStream)4 File (java.io.File)4 InputStream (java.io.InputStream)4 MBeanServer (javax.management.MBeanServer)4 ObjectName (javax.management.ObjectName)4 NetworkErrorProxy (org.apache.jackrabbit.oak.segment.test.proxy.NetworkErrorProxy)2 Stopwatch (com.google.common.base.Stopwatch)1 ServerSocket (java.net.ServerSocket)1 SegmentGCOptions (org.apache.jackrabbit.oak.segment.compaction.SegmentGCOptions)1 FileStoreBuilder (org.apache.jackrabbit.oak.segment.file.FileStoreBuilder)1 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)1 Ignore (org.junit.Ignore)1