Search in sources :

Example 46 with JournalException

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

the class JournalTest method testInvalidColumnName.

@Test
public void testInvalidColumnName() {
    File base = getFactory().getConfiguration().getJournalBase();
    File dir = new File(base, "x");
    Assert.assertFalse(dir.exists());
    try {
        getFactory().writer(new JournalStructure("x").$sym("x").index().$sym("y").index().$sym("z\0is\0bad").index().$());
        Assert.fail();
    } catch (JournalException ignore) {
    }
    getFactory().expire();
    Assert.assertTrue(dir.exists());
    Assert.assertTrue(Files.delete(dir));
}
Also used : JournalException(com.questdb.std.ex.JournalException) JournalStructure(com.questdb.store.factory.configuration.JournalStructure) File(java.io.File) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 47 with JournalException

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

the class JournalTest method testOpenJournalWithWrongPartitionType.

@Test
public void testOpenJournalWithWrongPartitionType() throws Exception {
    try (JournalWriter<Quote> w = getFactory().writer(new JournalKey<>(Quote.class, "quote", PartitionBy.NONE))) {
        TestUtils.generateQuoteData(w, 1000);
    }
    try {
        getFactory().writer(new JournalKey<>(Quote.class, "quote", PartitionBy.MONTH));
        Assert.fail("Exception expected");
    } catch (JournalException e) {
    // expect exception
    }
    try (Factory f2 = new Factory(new JournalConfigurationBuilder() {

        {
            $(Quote.class).$sym("mode");
        }
    }.build(factoryContainer.getConfiguration().getJournalBase()))) {
        f2.writer(new JournalKey<>(Quote.class, "quote"));
        Assert.fail("Exception expected");
    } catch (JournalException e) {
    // expect exception
    }
}
Also used : Quote(com.questdb.model.Quote) JournalException(com.questdb.std.ex.JournalException) Factory(com.questdb.store.factory.Factory) JournalConfigurationBuilder(com.questdb.store.factory.configuration.JournalConfigurationBuilder) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 48 with JournalException

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

the class QueryTest method testFindWithSearchSymbols.

@Test
public void testFindWithSearchSymbols() throws JournalException {
    final long millis = System.currentTimeMillis();
    Quote q1 = new Quote().setSym("S1").setEx("EX1").setTimestamp(millis);
    Quote q2 = new Quote().setSym("S2").setEx("EX1").setTimestamp(millis);
    Quote q3 = new Quote().setSym("S3").setEx("EX1").setTimestamp(millis);
    Quote q4 = new Quote().setSym("S4").setEx("EX3").setTimestamp(millis);
    w.append(q1, q2, q3, q4);
    // Unfiltered
    QueryAllBuilder<Quote> builder = q.all().withSymValues("ex", "EX1");
    Assert.assertEquals(3, builder.asResultSet().size());
    // Filtered
    builder.filter("sym", q1.getSym()).filter("sym", q2.getSym());
    Assert.assertEquals(2, builder.asResultSet().size());
    // Non-existent
    builder.resetFilter();
    try {
        builder.filter("sym", "S7");
        Assert.fail("Expect exception here");
    } catch (Exception e) {
    // ok
    }
    // Filtered - 2 existing and 1 from a different exchange
    builder.resetFilter();
    builder.filter("sym", q1.getSym()).filter("sym", q2.getSym()).filter("sym", q4.getSym());
    Assert.assertEquals(2, builder.asResultSet().size());
}
Also used : Quote(com.questdb.model.Quote) JournalException(com.questdb.std.ex.JournalException) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 49 with JournalException

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

the class CachingReaderFactoryTest method testLockBusyReader.

@Test
public void testLockBusyReader() throws Exception {
    final int readerCount = 5;
    int threadCount = 2;
    final int iterations = 10000;
    // create journals to read
    final JournalMetadata<?>[] meta = new JournalMetadata[readerCount];
    for (int i = 0; i < readerCount; i++) {
        final JournalMetadata<?> m = new JournalStructure("x" + i).$date("ts").$().build();
        ((WriterFactory) getFactory()).writer(m).close();
        meta[i] = m;
    }
    try {
        try (final CachingReaderFactory rf = new CachingReaderFactory(factoryContainer.getConfiguration(), 1000, 2)) {
            final CyclicBarrier barrier = new CyclicBarrier(threadCount);
            final CountDownLatch halt = new CountDownLatch(threadCount);
            final AtomicInteger errors = new AtomicInteger();
            final LongList lockTimes = new LongList();
            final LongList workerTimes = new LongList();
            new Thread(() -> {
                Rnd rnd = new Rnd();
                try {
                    barrier.await();
                    String name = null;
                    for (int i = 0; i < iterations; i++) {
                        if (name == null) {
                            name = meta[rnd.nextPositiveInt() % readerCount].getName();
                        }
                        while (true) {
                            try {
                                rf.lock(name);
                                lockTimes.add(System.currentTimeMillis());
                                LockSupport.parkNanos(100L);
                                rf.unlock(name);
                                name = null;
                                break;
                            } catch (JournalException e) {
                                if (!(e instanceof RetryLockException)) {
                                    e.printStackTrace();
                                    errors.incrementAndGet();
                                    break;
                                }
                            }
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    errors.incrementAndGet();
                }
                halt.countDown();
            }).start();
            new Thread(() -> {
                Rnd rnd = new Rnd();
                workerTimes.add(System.currentTimeMillis());
                for (int i = 0; i < iterations; i++) {
                    JournalMetadata<?> metadata = meta[rnd.nextPositiveInt() % readerCount];
                    try (Journal<?> ignored = rf.reader(metadata)) {
                        if (metadata == meta[readerCount - 1] && barrier.getNumberWaiting() > 0) {
                            barrier.await();
                        }
                        LockSupport.parkNanos(10L);
                    } catch (JournalLockedException ignored) {
                    } catch (Exception e) {
                        e.printStackTrace();
                        errors.incrementAndGet();
                    }
                }
                workerTimes.add(System.currentTimeMillis());
                halt.countDown();
            }).start();
            halt.await();
            Assert.assertEquals(0, errors.get());
            // check that there are lock times between worker times
            int count = 0;
            // ensure that we have worker times
            Assert.assertEquals(2, workerTimes.size());
            long lo = workerTimes.get(0);
            long hi = workerTimes.get(1);
            Assert.assertTrue(lockTimes.size() > 0);
            for (int i = 0, n = lockTimes.size(); i < n; i++) {
                long t = lockTimes.getQuick(i);
                if (t > lo && t < hi) {
                    count++;
                }
            }
            Assert.assertTrue(count > 0);
        }
    } catch (Throwable e) {
        e.printStackTrace();
    }
}
Also used : JournalLockedException(com.questdb.ex.JournalLockedException) JournalException(com.questdb.std.ex.JournalException) Rnd(com.questdb.std.Rnd) Journal(com.questdb.store.Journal) LongList(com.questdb.std.LongList) CountDownLatch(java.util.concurrent.CountDownLatch) JournalLockedException(com.questdb.ex.JournalLockedException) JournalException(com.questdb.std.ex.JournalException) FactoryFullException(com.questdb.ex.FactoryFullException) RetryLockException(com.questdb.ex.RetryLockException) CyclicBarrier(java.util.concurrent.CyclicBarrier) RetryLockException(com.questdb.ex.RetryLockException) JournalMetadata(com.questdb.store.factory.configuration.JournalMetadata) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) JournalStructure(com.questdb.store.factory.configuration.JournalStructure) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 50 with JournalException

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

the class Journal method configureColumns.

private void configureColumns() throws JournalException {
    int columnCount = getMetadata().getColumnCount();
    try {
        for (int i = 0; i < columnCount; i++) {
            ColumnMetadata meta = metadata.getColumnQuick(i);
            if (meta.type == ColumnType.SYMBOL && meta.sameAs == null) {
                int tabIndex = symbolTables.size();
                int tabSize = tx.symbolTableSizes.length > tabIndex ? tx.symbolTableSizes[tabIndex] : 0;
                long indexTxAddress = tx.symbolTableIndexPointers.length > tabIndex ? tx.symbolTableIndexPointers[tabIndex] : 0;
                MMappedSymbolTable tab = new MMappedSymbolTable(meta.distinctCountHint, meta.avgSize, getMetadata().getTxCountHint(), location, meta.name, getMode(), tabSize, indexTxAddress, meta.noCache, sequentialAccess);
                symbolTables.add(tab);
                symbolTableMap.put(meta.name, tab);
                meta.symbolTable = tab;
            }
        }
    } catch (JournalException e) {
        closeSymbolTables();
        throw e;
    }
}
Also used : ColumnMetadata(com.questdb.store.factory.configuration.ColumnMetadata) JournalException(com.questdb.std.ex.JournalException)

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