Search in sources :

Example 26 with JournalException

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

the class QueryAllImpl method createRanges.

private ObjList<JournalIteratorRange> createRanges() {
    final int partitionCount = journal.getPartitionCount();
    ObjList<JournalIteratorRange> ranges = new ObjList<>(partitionCount);
    try {
        for (int i = 0; i < partitionCount; i++) {
            Partition<T> p = journal.getPartition(i, true);
            long size = p.size();
            if (size > 0) {
                ranges.add(new JournalIteratorRange(p.getPartitionIndex(), 0, size - 1));
            }
        }
    } catch (JournalException e) {
        throw new JournalRuntimeException(e);
    }
    return ranges;
}
Also used : ObjList(com.questdb.std.ObjList) JournalException(com.questdb.std.ex.JournalException) JournalRuntimeException(com.questdb.common.JournalRuntimeException)

Example 27 with JournalException

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

the class QueryAllImpl method incrementIterator.

@Override
public JournalPeekingIterator<T> incrementIterator() {
    try {
        long lo = journal.getMaxRowID();
        journal.refresh();
        return new JournalIteratorImpl<>(journal, createRanges(journal.incrementRowID(lo)));
    } catch (JournalException e) {
        throw new JournalRuntimeException(e);
    }
}
Also used : JournalException(com.questdb.std.ex.JournalException) JournalRuntimeException(com.questdb.common.JournalRuntimeException)

Example 28 with JournalException

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

the class ExportManager method export.

public static void export(RecordSource from, ReaderFactory factory, File to, char delimiter) throws JournalException, IOException {
    if (to.isDirectory()) {
        throw new JournalException(to + "cannot be a directory");
    }
    try (FileSink sink = new FileSink(to)) {
        RecordSourcePrinter printer = new RecordSourcePrinter(sink, delimiter);
        printer.print(from, factory, true);
    }
}
Also used : JournalException(com.questdb.std.ex.JournalException) RecordSourcePrinter(com.questdb.ql.RecordSourcePrinter) FileSink(com.questdb.std.str.FileSink)

Example 29 with JournalException

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

the class RenameJournalTest method testJournalAlreadyOpenButIdle.

@Test
@SuppressWarnings("unchecked")
public void testJournalAlreadyOpenButIdle() throws Exception {
    createX();
    Factory factory = getFactory();
    assertJournal(factory, "x");
    sink.clear();
    compiler.execute(factory, "rename table x to y");
    assertJournal(factory, "y");
    // make sure caching readerFactory doesn't return old journal
    try {
        factory.reader(new JournalKey("x"));
        Assert.fail();
    } catch (JournalException e) {
        Assert.assertEquals("Journal does not exist", e.getMessage());
    }
    // make sure compile doesn't pick up old journal
    try {
        compiler.compile(factory, "x");
        Assert.fail("still exists");
    } catch (ParserException e) {
        Assert.assertEquals(0, QueryError.getPosition());
        TestUtils.assertEquals("Journal does not exist", QueryError.getMessage());
    }
    sink.clear();
    createX();
    assertJournal(factory, "x");
}
Also used : ParserException(com.questdb.ex.ParserException) JournalException(com.questdb.std.ex.JournalException) Factory(com.questdb.store.factory.Factory) JournalKey(com.questdb.store.JournalKey) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 30 with JournalException

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

the class JournalTest method testSingleWriterModel.

@Test
public void testSingleWriterModel() throws Exception {
    try (JournalWriter<Quote> writer = getFactory().writer(Quote.class)) {
        Assert.assertTrue(writer != null);
        final CountDownLatch finished = new CountDownLatch(1);
        final AtomicInteger errors = new AtomicInteger();
        new Thread(() -> {
            try {
                getFactory().writer(Quote.class);
                errors.incrementAndGet();
            } catch (JournalException e) {
            // ignore
            }
            finished.countDown();
        }).start();
        Assert.assertTrue(finished.await(1, TimeUnit.SECONDS));
        Assert.assertEquals(0, errors.get());
        // check if we can open a reader
        try (Journal<Quote> r = getFactory().reader(Quote.class)) {
            Assert.assertTrue(r != null);
        }
        // check if we can open writer in alt location
        try (JournalWriter w = getFactory().writer(Quote.class, "test-Quote")) {
            Assert.assertTrue(w != null);
        }
    }
}
Also used : Quote(com.questdb.model.Quote) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) JournalException(com.questdb.std.ex.JournalException) CountDownLatch(java.util.concurrent.CountDownLatch) 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