use of com.questdb.net.ha.config.ClientConfig 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));
}
use of com.questdb.net.ha.config.ClientConfig in project questdb by bluestreak01.
the class SslReplicationClientMain method main.
public static void main(String[] args) throws Exception {
JournalConfiguration configuration = new JournalConfigurationBuilder().build(args[0]);
Factory factory = new Factory(configuration, 1000, 1, 0);
final JournalClient client = new JournalClient(new ClientConfig() {
{
getSslConfig().setSecure(true);
try (InputStream is = this.getClass().getResourceAsStream("/keystore/singlekey.ks")) {
getSslConfig().setTrustStore(is, "changeit");
}
}
}, factory);
final Journal<Price> reader = factory.reader(Price.class, "price-copy");
reader.setSequentialAccess(true);
client.subscribe(Price.class, null, "price-copy", new JournalListener() {
@Override
public void onCommit() {
int count = 0;
long t = 0;
for (Price p : JournalIterators.incrementBufferedIterator(reader)) {
if (count == 0) {
t = p.getNanos();
}
count++;
}
System.out.println("took: " + (System.nanoTime() - t) + ", count=" + count);
}
@Override
public void onEvent(int event) {
System.out.println("There was an error");
}
});
client.start();
System.out.println("Client started");
}
use of com.questdb.net.ha.config.ClientConfig in project questdb by bluestreak01.
the class ClientRecoveryTest method testClientWriterRelease.
@Test
public void testClientWriterRelease() throws Exception {
final CountDownLatch serverError = new CountDownLatch(1);
JournalClient client = new JournalClient(new ClientConfig("localhost"), getFactory(), null, evt -> {
if (evt == JournalClientEvents.EVT_TERMINATED) {
serverError.countDown();
}
});
client.subscribe(Quote.class);
client.start();
Assert.assertTrue(serverError.await(5, TimeUnit.SECONDS));
Assert.assertFalse(client.isRunning());
// should be able to get writer after client failure.
try (JournalWriter<Quote> w = getFactory().writer(Quote.class)) {
Assert.assertNotNull(w);
}
}
use of com.questdb.net.ha.config.ClientConfig 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());
}
}
}
use of com.questdb.net.ha.config.ClientConfig 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();
}
}
Aggregations