Search in sources :

Example 21 with StandbyClientSync

use of org.apache.jackrabbit.oak.segment.standby.client.StandbyClientSync in project jackrabbit-oak by apache.

the class MBeanIT method testClientEmptyConfigNoServer.

@Test
public void testClientEmptyConfigNoServer() throws Exception {
    MBeanServer jmxServer = ManagementFactory.getPlatformMBeanServer();
    ObjectName status = new ObjectName(StandbyStatusMBean.JMX_NAME + ",id=*");
    try (StandbyClientSync clientSync = new StandbyClientSync(getServerHost(), serverPort.getPort(), clientFileStore.fileStore(), false, getClientTimeout(), false, folder.newFolder())) {
        clientSync.start();
        clientSync.run();
        Set<ObjectName> instances = jmxServer.queryNames(status, null);
        assertEquals(1, instances.size());
        status = instances.toArray(new ObjectName[0])[0];
        assertEquals(new ObjectName(clientSync.getMBeanName()), status);
        assertTrue(jmxServer.isRegistered(status));
        String m = jmxServer.getAttribute(status, "Mode").toString();
        if (!m.startsWith("client: ")) {
            fail("unexpected mode " + m);
        }
        assertEquals("1", jmxServer.getAttribute(status, "FailedRequests").toString());
        assertEquals("-1", jmxServer.getAttribute(status, "SecondsSinceLastSuccess").toString());
        assertEquals(StandbyStatusMBean.STATUS_RUNNING, jmxServer.getAttribute(status, "Status"));
        assertEquals(true, jmxServer.getAttribute(status, "Running"));
        jmxServer.invoke(status, "stop", null, null);
        assertEquals(false, jmxServer.getAttribute(status, "Running"));
        assertEquals(StandbyStatusMBean.STATUS_STOPPED, jmxServer.getAttribute(status, "Status"));
        jmxServer.invoke(status, "start", null, null);
        assertEquals(true, jmxServer.getAttribute(status, "Running"));
        assertEquals(StandbyStatusMBean.STATUS_RUNNING, jmxServer.getAttribute(status, "Status"));
    }
    assertTrue(!jmxServer.isRegistered(status));
}
Also used : StandbyClientSync(org.apache.jackrabbit.oak.segment.standby.client.StandbyClientSync) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 22 with StandbyClientSync

use of org.apache.jackrabbit.oak.segment.standby.client.StandbyClientSync 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 23 with StandbyClientSync

use of org.apache.jackrabbit.oak.segment.standby.client.StandbyClientSync 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 24 with StandbyClientSync

use of org.apache.jackrabbit.oak.segment.standby.client.StandbyClientSync 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

StandbyClientSync (org.apache.jackrabbit.oak.segment.standby.client.StandbyClientSync)24 StandbyServerSync (org.apache.jackrabbit.oak.segment.standby.server.StandbyServerSync)21 FileStore (org.apache.jackrabbit.oak.segment.file.FileStore)18 Test (org.junit.Test)17 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 File (java.io.File)5 MBeanServer (javax.management.MBeanServer)5 ObjectName (javax.management.ObjectName)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 InputStream (java.io.InputStream)4 NetworkErrorProxy (org.apache.jackrabbit.oak.segment.test.proxy.NetworkErrorProxy)2 Stopwatch (com.google.common.base.Stopwatch)1 ServerSocket (java.net.ServerSocket)1 Hashtable (java.util.Hashtable)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