Search in sources :

Example 1 with ServerNode

use of com.questdb.net.ha.config.ServerNode in project questdb by bluestreak01.

the class ServerNodeTest method testHostAndPort.

@Test
public void testHostAndPort() {
    ServerNode node = new ServerNode(0, "github.questdb.org:8080");
    Assert.assertEquals("github.questdb.org", node.getHostname());
    Assert.assertEquals(8080, node.getPort());
}
Also used : ServerNode(com.questdb.net.ha.config.ServerNode) Test(org.junit.Test)

Example 2 with ServerNode

use of com.questdb.net.ha.config.ServerNode in project questdb by bluestreak01.

the class ServerNodeTest method testIPv6AndPort.

@Test
public void testIPv6AndPort() {
    ServerNode node = new ServerNode(0, "[fe80::5fc:43c:eef0:5b8e%3]:7090");
    Assert.assertEquals("fe80::5fc:43c:eef0:5b8e%3", node.getHostname());
    Assert.assertEquals(7090, node.getPort());
}
Also used : ServerNode(com.questdb.net.ha.config.ServerNode) Test(org.junit.Test)

Example 3 with ServerNode

use of com.questdb.net.ha.config.ServerNode in project questdb by bluestreak01.

the class ClusteredProducerMain method main.

public static void main(String[] args) throws JournalException, IOException, JournalNetworkException, NumericException {
    final String pathToDatabase = args[0];
    final int instance = Numbers.parseInt(args[1]);
    final JournalConfiguration configuration = new JournalConfigurationBuilder() {

        {
            $(Price.class).$ts();
        }
    }.build(pathToDatabase);
    final Factory factory = new Factory(configuration, 1000, 1, 0);
    final JournalWriter<Price> writer = factory.writer(new JournalKey<>(Price.class, null, PartitionBy.DEFAULT, 1000000000));
    final WorkerController wc = new WorkerController(writer);
    final ClusterController cc = new ClusterController(new ServerConfig() {

        {
            addNode(new ServerNode(1, "127.0.0.1:7080"));
            addNode(new ServerNode(2, "127.0.0.1:7090"));
        }
    }, new ClientConfig(), factory, instance, new ArrayList<JournalWriter>() {

        {
            add(writer);
        }
    }, wc);
    cc.start();
    Runtime.getRuntime().addShutdownHook(new Thread(cc::halt));
}
Also used : JournalWriter(com.questdb.store.JournalWriter) Factory(com.questdb.store.factory.Factory) JournalConfigurationBuilder(com.questdb.store.factory.configuration.JournalConfigurationBuilder) ServerConfig(com.questdb.net.ha.config.ServerConfig) JournalConfiguration(com.questdb.store.factory.configuration.JournalConfiguration) ClusterController(com.questdb.net.ha.ClusterController) Price(org.questdb.examples.support.Price) ServerNode(com.questdb.net.ha.config.ServerNode) ClientConfig(com.questdb.net.ha.config.ClientConfig)

Example 4 with ServerNode

use of com.questdb.net.ha.config.ServerNode in project questdb by bluestreak01.

the class ClusterControllerTest method testBusyFailOver.

@Test
@Ignore
public void testBusyFailOver() throws Exception {
    try (JournalWriter<Quote> writer1 = getFactory().writer(Quote.class)) {
        try (final JournalWriter<Quote> writer2 = tf.getFactory().writer(Quote.class)) {
            final CountDownLatch active1 = new CountDownLatch(1);
            final CountDownLatch active2 = new CountDownLatch(1);
            final CountDownLatch standby2 = new CountDownLatch(1);
            final AtomicLong expected = new AtomicLong();
            final AtomicLong actual = new AtomicLong();
            ClusterController controller1 = new ClusterController(new ServerConfig() {

                {
                    addNode(new ServerNode(0, "localhost:7080"));
                    addNode(new ServerNode(1, "localhost:7090"));
                    setEnableMultiCast(false);
                    setHeartbeatFrequency(50);
                }
            }, new ClientConfig() {

                {
                    setEnableMultiCast(false);
                }
            }, getFactory(), 0, new ArrayList<JournalWriter>() {

                {
                    add(writer1);
                }
            }, new ClusterStatusListener() {

                @Override
                public void goActive() {
                    try {
                        TestUtils.generateQuoteData(writer1, 100000);
                        TestUtils.generateQuoteData(writer1, 100000, writer1.getMaxTimestamp());
                        writer1.commit();
                        TestUtils.generateQuoteData(writer1, 100000, writer1.getMaxTimestamp());
                        writer1.commit();
                        TestUtils.generateQuoteData(writer1, 100000, writer1.getMaxTimestamp());
                        writer1.commit();
                        TestUtils.generateQuoteData(writer1, 100000, writer1.getMaxTimestamp());
                        writer1.commit();
                        expected.set(writer1.size());
                        active1.countDown();
                    } catch (JournalException | NumericException e) {
                        e.printStackTrace();
                    }
                }

                @Override
                public void goPassive(ServerNode activeNode) {
                }

                @Override
                public void onShutdown() {
                }
            });
            ClusterController controller2 = new ClusterController(new ServerConfig() {

                {
                    addNode(new ServerNode(0, "localhost:7080"));
                    addNode(new ServerNode(1, "localhost:7090"));
                    setEnableMultiCast(false);
                    setHeartbeatFrequency(50);
                }
            }, new ClientConfig() {

                {
                    setEnableMultiCast(false);
                }
            }, tf.getFactory(), 1, new ArrayList<JournalWriter>() {

                {
                    add(writer2);
                }
            }, new ClusterStatusListener() {

                @Override
                public void goActive() {
                    try {
                        actual.set(writer2.size());
                        active2.countDown();
                    } catch (JournalException e) {
                        e.printStackTrace();
                    }
                }

                @Override
                public void goPassive(ServerNode activeNode) {
                    standby2.countDown();
                }

                @Override
                public void onShutdown() {
                }
            });
            controller1.start();
            Assert.assertTrue(active1.await(30, TimeUnit.SECONDS));
            Assert.assertEquals(0, active1.getCount());
            controller2.start();
            standby2.await(60, TimeUnit.SECONDS);
            Assert.assertEquals(0, standby2.getCount());
            controller1.halt();
            active2.await(10, TimeUnit.SECONDS);
            Assert.assertEquals(0, active2.getCount());
            controller2.halt();
            Assert.assertTrue(expected.get() > 0);
            Assert.assertEquals(expected.get(), actual.get());
        }
    }
}
Also used : JournalWriter(com.questdb.store.JournalWriter) JournalException(com.questdb.std.ex.JournalException) CountDownLatch(java.util.concurrent.CountDownLatch) Quote(com.questdb.model.Quote) ServerConfig(com.questdb.net.ha.config.ServerConfig) AtomicLong(java.util.concurrent.atomic.AtomicLong) ServerNode(com.questdb.net.ha.config.ServerNode) ClientConfig(com.questdb.net.ha.config.ClientConfig) AbstractTest(com.questdb.test.tools.AbstractTest)

Example 5 with ServerNode

use of com.questdb.net.ha.config.ServerNode in project questdb by bluestreak01.

the class DataLossTest method testDiscardFile.

@Test
@Ignore
public void testDiscardFile() throws Exception {
    // create master journal
    try (JournalWriter<Quote> master = getFactory().writer(Quote.class, "master")) {
        TestUtils.generateQuoteData(master, 300, master.getMaxTimestamp());
        master.commit();
        // publish master out
        JournalServer server = new JournalServer(new ServerConfig() {

            {
                addNode(new ServerNode(0, "localhost"));
                setEnableMultiCast(false);
                setHeartbeatFrequency(50);
            }
        }, getFactory());
        server.publish(master);
        server.start();
        final AtomicInteger counter = new AtomicInteger();
        final AtomicInteger doNotExpect = new AtomicInteger();
        // equalize slave
        JournalClient client = new JournalClient(new ClientConfig("localhost") {

            {
                setEnableMultiCast(false);
            }
        }, getFactory());
        client.subscribe(Quote.class, "master", "slave", new JournalListener() {

            @Override
            public void onCommit() {
                counter.incrementAndGet();
            }

            @Override
            public void onEvent(int event) {
            }
        });
        client.start();
        TestUtils.assertCounter(counter, 1, 10, TimeUnit.SECONDS);
        // stop client to be able to add to slave manually
        client.halt();
        System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
        // add more data to slave
        try (JournalWriter<Quote> slave = getFactory().writer(Quote.class, "slave")) {
            TestUtils.generateQuoteData(slave, 200, slave.getMaxTimestamp());
            slave.commit();
        }
        // synchronise slave again
        client = new JournalClient(new ClientConfig("localhost"), getFactory());
        client.subscribe(Quote.class, "master", "slave", new JournalListener() {

            @Override
            public void onCommit() {
                doNotExpect.incrementAndGet();
            }

            @Override
            public void onEvent(int event) {
                counter.incrementAndGet();
            }
        });
        client.start();
        TestUtils.assertCounter(counter, 2, 180, TimeUnit.SECONDS);
        client.halt();
        Assert.assertEquals(0, doNotExpect.get());
        try (JournalWriter w = getFactory().writer(Quote.class, "slave")) {
            Assert.assertNotNull(w);
        }
        server.halt();
    }
}
Also used : Quote(com.questdb.model.Quote) ServerConfig(com.questdb.net.ha.config.ServerConfig) JournalWriter(com.questdb.store.JournalWriter) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) JournalListener(com.questdb.store.JournalListener) ServerNode(com.questdb.net.ha.config.ServerNode) ClientConfig(com.questdb.net.ha.config.ClientConfig) Ignore(org.junit.Ignore) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Aggregations

ServerNode (com.questdb.net.ha.config.ServerNode)12 Test (org.junit.Test)9 ClientConfig (com.questdb.net.ha.config.ClientConfig)7 ServerConfig (com.questdb.net.ha.config.ServerConfig)7 AbstractTest (com.questdb.test.tools.AbstractTest)5 JournalWriter (com.questdb.store.JournalWriter)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 Quote (com.questdb.model.Quote)3 JournalListener (com.questdb.store.JournalListener)3 RecordSource (com.questdb.ql.RecordSource)2 RecordSourcePrinter (com.questdb.ql.RecordSourcePrinter)2 StringSink (com.questdb.std.str.StringSink)2 JournalKey (com.questdb.store.JournalKey)2 ClusterController (com.questdb.net.ha.ClusterController)1 AbstractOnDemandSender (com.questdb.net.ha.mcast.AbstractOnDemandSender)1 OnDemandAddressPoller (com.questdb.net.ha.mcast.OnDemandAddressPoller)1 OnDemandAddressSender (com.questdb.net.ha.mcast.OnDemandAddressSender)1 Rnd (com.questdb.std.Rnd)1 JournalException (com.questdb.std.ex.JournalException)1 JournalEntryWriter (com.questdb.store.JournalEntryWriter)1