Search in sources :

Example 16 with JournalException

use of com.questdb.std.ex.JournalException in project questdb by bluestreak01.

the class Partition method updateIndexes.

public void updateIndexes(long oldSize, long newSize) {
    if (oldSize < newSize) {
        try {
            for (int n = 0, k = indexProxies.size(); n < k; n++) {
                SymbolIndexProxy<T> proxy = indexProxies.getQuick(n);
                KVIndex index = proxy.getIndex();
                FixedColumn col = fixCol(proxy.getColumnIndex());
                for (long i = oldSize; i < newSize; i++) {
                    index.add(col.getInt(i), i);
                }
                index.commit();
            }
        } catch (JournalException e) {
            throw new JournalRuntimeException(e);
        }
    }
}
Also used : JournalException(com.questdb.std.ex.JournalException) JournalRuntimeException(com.questdb.common.JournalRuntimeException)

Example 17 with JournalException

use of com.questdb.std.ex.JournalException in project questdb by bluestreak01.

the class Partition method open0.

private void open0() throws JournalException {
    columns = new AbstractColumn[journal.getMetadata().getColumnCount()];
    try {
        for (int i = 0; i < columns.length; i++) {
            switch(Unsafe.arrayGet(columnMetadata, i).type) {
                case ColumnType.STRING:
                case ColumnType.BINARY:
                    Unsafe.arrayPut(columns, i, new VariableColumn(new MemoryFile(new File(partitionDir, Unsafe.arrayGet(columnMetadata, i).name + ".d"), Unsafe.arrayGet(columnMetadata, i).bitHint, journal.getMode(), sequentialAccess), new MemoryFile(new File(partitionDir, Unsafe.arrayGet(columnMetadata, i).name + ".i"), Unsafe.arrayGet(columnMetadata, i).indexBitHint, journal.getMode(), sequentialAccess)));
                    break;
                default:
                    Unsafe.arrayPut(columns, i, new FixedColumn(new MemoryFile(new File(partitionDir, Unsafe.arrayGet(columnMetadata, i).name + ".d"), Unsafe.arrayGet(columnMetadata, i).bitHint, journal.getMode(), sequentialAccess), Unsafe.arrayGet(columnMetadata, i).size));
                    break;
            }
        }
    } catch (JournalException e) {
        closePartiallyOpenColumns();
        throw e;
    }
    int tsIndex = journal.getMetadata().getTimestampIndex();
    if (tsIndex > -1) {
        timestampColumn = fixCol(tsIndex);
    }
}
Also used : JournalException(com.questdb.std.ex.JournalException) File(java.io.File)

Example 18 with JournalException

use of com.questdb.std.ex.JournalException in project questdb by bluestreak01.

the class SymbolIndexProxy method openIndex.

private KVIndex openIndex() throws JournalException {
    JournalMetadata<T> meta = partition.getJournal().getMetadata();
    ColumnMetadata columnMetadata = meta.getColumnQuick(columnIndex);
    if (!columnMetadata.indexed) {
        throw new JournalException("There is no index for column: %s", columnMetadata.name);
    }
    return new KVIndex(new File(partition.getPartitionDir(), columnMetadata.name), columnMetadata.distinctCountHint, meta.getRecordHint(), meta.getTxCountHint(), partition.getJournal().getMode(), txAddress, sequentialAccess);
}
Also used : ColumnMetadata(com.questdb.store.factory.configuration.ColumnMetadata) JournalException(com.questdb.std.ex.JournalException) File(java.io.File)

Example 19 with JournalException

use of com.questdb.std.ex.JournalException 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 20 with JournalException

use of com.questdb.std.ex.JournalException in project questdb by bluestreak01.

the class IntegrationTest method testBadSubscriptionOnTheFlyFollowedByReconnect.

@Test
public void testBadSubscriptionOnTheFlyFollowedByReconnect() throws Exception {
    try (final JournalWriter<Quote> origin = getFactory().writer(Quote.class, "origin")) {
        final int batchSize = 1000;
        final int batchCount = 100;
        server.publish(origin);
        server.start();
        try {
            final CountDownLatch terminated = new CountDownLatch(1);
            JournalClient client = new JournalClient(new ClientConfig("localhost"), getFactory(), null, evt -> {
                if (evt == JournalClientEvents.EVT_TERMINATED) {
                    terminated.countDown();
                }
            });
            client.start();
            final AtomicInteger commits = new AtomicInteger();
            final AtomicInteger errors = new AtomicInteger();
            final CountDownLatch localSubscribed = new CountDownLatch(1);
            final CountDownLatch dataReceived = new CountDownLatch(1);
            try {
                // create empty journal
                getFactory().writer(Quote.class, "local").close();
                try (final Journal local = getFactory().reader("local")) {
                    client.subscribe(Quote.class, "origin", "local", new JournalListener() {

                        @Override
                        public void onCommit() {
                            commits.incrementAndGet();
                            try {
                                local.refresh();
                                if (local.size() == batchCount * batchSize) {
                                    dataReceived.countDown();
                                }
                            } catch (JournalException e) {
                                e.printStackTrace();
                                errors.incrementAndGet();
                            }
                        }

                        @Override
                        public void onEvent(int event) {
                            switch(event) {
                                case JournalEvents.EVT_JNL_SUBSCRIBED:
                                    localSubscribed.countDown();
                                    break;
                                default:
                                    errors.incrementAndGet();
                                    break;
                            }
                        }
                    });
                    final CountDownLatch published = new CountDownLatch(1);
                    final CyclicBarrier barrier = new CyclicBarrier(2);
                    final AtomicInteger publisherErrors = new AtomicInteger();
                    new Thread(() -> {
                        try {
                            barrier.await();
                            long timestamp = DateFormatUtils.parseDateTime("2013-09-04T10:00:00.000Z");
                            long increment = 1000L;
                            for (int i = 0; i < batchCount; i++) {
                                TestUtils.generateQuoteData(origin, batchSize, timestamp, increment);
                                timestamp += increment * (batchSize);
                                origin.commit();
                            }
                        } catch (Throwable e) {
                            e.printStackTrace();
                            publisherErrors.incrementAndGet();
                        }
                        published.countDown();
                    }).start();
                    Assert.assertTrue(localSubscribed.await(10, TimeUnit.SECONDS));
                    barrier.await();
                    // after publishing stream is setup we attempt to subscribe bad journal
                    // todo: this part breaks server, fix server and continue
                    // readerFactory.writer(new JournalConfigurationBuilder().$("x").$int("x").$()).close();
                    // 
                    // client.subscribe(Quote.class, "origin", "x", new JournalListener() {
                    // @Override
                    // public void onCommit() {
                    // 
                    // }
                    // 
                    // @Override
                    // public void onEvent(int event) {
                    // System.out.println("bad event: " + event);
                    // }
                    // });
                    Assert.assertTrue(published.await(60, TimeUnit.SECONDS));
                    Assert.assertTrue(dataReceived.await(60, TimeUnit.SECONDS));
                    Assert.assertEquals(0, publisherErrors.get());
                    Assert.assertEquals(0, errors.get());
                    Assert.assertTrue(commits.get() > 0);
                    local.refresh();
                    Assert.assertEquals(batchSize * batchCount, local.size());
                }
            } catch (Throwable e) {
                e.printStackTrace();
                Assert.fail();
            } finally {
                client.halt();
            }
            Assert.assertTrue(terminated.await(5, TimeUnit.SECONDS));
        } finally {
            server.halt();
        }
    }
// Assert.fail();
}
Also used : JournalException(com.questdb.std.ex.JournalException) CountDownLatch(java.util.concurrent.CountDownLatch) CyclicBarrier(java.util.concurrent.CyclicBarrier) Quote(com.questdb.model.Quote) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ClientConfig(com.questdb.net.ha.config.ClientConfig) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Aggregations

JournalException (com.questdb.std.ex.JournalException)63 JournalRuntimeException (com.questdb.common.JournalRuntimeException)29 AbstractTest (com.questdb.test.tools.AbstractTest)14 Test (org.junit.Test)13 KVIndex (com.questdb.store.KVIndex)12 Partition (com.questdb.store.Partition)9 Quote (com.questdb.model.Quote)8 IndexCursor (com.questdb.store.IndexCursor)8 File (java.io.File)8 CountDownLatch (java.util.concurrent.CountDownLatch)7 IncompatibleJournalException (com.questdb.ex.IncompatibleJournalException)5 JournalStructure (com.questdb.store.factory.configuration.JournalStructure)5 ObjList (com.questdb.std.ObjList)4 JournalWriter (com.questdb.store.JournalWriter)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 ClientConfig (com.questdb.net.ha.config.ClientConfig)3 FixedColumn (com.questdb.store.FixedColumn)3 Factory (com.questdb.store.factory.Factory)3 ColumnMetadata (com.questdb.store.factory.configuration.ColumnMetadata)3 JournalLockedException (com.questdb.ex.JournalLockedException)2