Search in sources :

Example 31 with JournalException

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

the class CachingWriterFactoryTest method testLockUnlock.

@Test
public void testLockUnlock() throws Exception {
    final JournalMetadata<?> x = new JournalStructure("x").$date("ts").$().build();
    final JournalMetadata<?> y = new JournalStructure("y").$date("ts").$().build();
    JournalWriter wx = wf.writer(x);
    Assert.assertNotNull(wx);
    Assert.assertTrue(wx.isOpen());
    JournalWriter wy = wf.writer(y);
    Assert.assertNotNull(wy);
    Assert.assertTrue(wy.isOpen());
    try {
        // check that lock is successful
        wf.lock(x.getName());
        // check that writer x is closed and writer y is open (lock must not spill out to other writers)
        Assert.assertFalse(wx.isOpen());
        Assert.assertTrue(wy.isOpen());
        // check that when name is locked writers are not created
        try {
            wf.writer(x);
        } catch (JournalLockedException ignored) {
        }
        final CountDownLatch done = new CountDownLatch(1);
        final AtomicBoolean result = new AtomicBoolean();
        // have new thread try to allocated this writers
        new Thread(() -> {
            try (JournalWriter ignored = wf.writer(x)) {
                result.set(false);
            } catch (WriterBusyException ignored) {
                result.set(true);
            } catch (JournalException e) {
                e.printStackTrace();
                result.set(false);
            }
            done.countDown();
        }).start();
        Assert.assertTrue(done.await(1, TimeUnit.SECONDS));
        Assert.assertTrue(result.get());
        wf.unlock(x.getName());
        wx = wf.writer(x);
        Assert.assertNotNull(wx);
        Assert.assertTrue(wx.isOpen());
        try {
            // unlocking writer that has not been locked must produce exception
            // and not affect open writer
            wf.unlock(wx.getName());
            Assert.fail();
        } catch (IllegalStateException ignored) {
        }
        Assert.assertTrue(wx.isOpen());
    } finally {
        wx.close();
        wy.close();
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) JournalWriter(com.questdb.store.JournalWriter) JournalLockedException(com.questdb.ex.JournalLockedException) JournalException(com.questdb.std.ex.JournalException) JournalStructure(com.questdb.store.factory.configuration.JournalStructure) WriterBusyException(com.questdb.ex.WriterBusyException) CountDownLatch(java.util.concurrent.CountDownLatch) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 32 with JournalException

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

the class CachingWriterFactoryTest method testNewLock.

@Test
public void testNewLock() throws Exception {
    final JournalMetadata<?> m = new JournalStructure("x").$date("ts").$().build();
    wf.lock("x");
    try {
        wf.writer(m);
        Assert.fail();
    } catch (JournalException ignored) {
    }
    wf.unlock("x");
}
Also used : JournalException(com.questdb.std.ex.JournalException) JournalStructure(com.questdb.store.factory.configuration.JournalStructure) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 33 with JournalException

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

the class QueryModel method collectJournalMetadata.

public RecordMetadata collectJournalMetadata(Factory factory) throws ParserException {
    if (journalMetadata != null) {
        return journalMetadata;
    }
    ExprNode readerNode = getJournalName();
    if (readerNode.type != ExprNode.LITERAL && readerNode.type != ExprNode.CONSTANT) {
        throw QueryError.$(readerNode.position, "Journal name must be either literal or string constant");
    }
    String reader = stripMarker(Chars.stripQuotes(readerNode.token));
    SystemViewFactory systemViewFactory = SysFactories.getFactory(reader);
    if (systemViewFactory != null) {
        return systemViewFactory.getMetadata();
    }
    int status = factory.getConfiguration().exists(reader);
    if (status == JournalConfiguration.DOES_NOT_EXIST) {
        throw QueryError.$(readerNode.position, "Journal does not exist");
    }
    if (status == JournalConfiguration.EXISTS_FOREIGN) {
        throw QueryError.$(readerNode.position, "Journal directory is of unknown format");
    }
    try {
        return journalMetadata = factory.getConfiguration().readMetadata(reader);
    } catch (JournalException e) {
        throw QueryError.$(readerNode.position, e.getMessage());
    }
}
Also used : JournalException(com.questdb.std.ex.JournalException) SystemViewFactory(com.questdb.ql.sys.SystemViewFactory)

Example 34 with JournalException

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

the class JournalPartitionSource method next.

@Override
public PartitionSlice next() {
    try {
        slice.partition = journal.getPartition(partitionIndex++, open);
        slice.lo = 0;
        slice.calcHi = true;
        return slice;
    } catch (JournalException e) {
        throw new JournalRuntimeException(e);
    }
}
Also used : JournalException(com.questdb.std.ex.JournalException) JournalRuntimeException(com.questdb.common.JournalRuntimeException)

Example 35 with JournalException

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

the class KvIndexIntLambdaHeadRowSource method prepareCursor.

@Override
public RowCursor prepareCursor(PartitionSlice slice) {
    try {
        Partition partition = rec.partition = slice.partition.open();
        KVIndex index = partition.getIndexForColumn(columnIndex);
        FixedColumn col = partition.fixCol(columnIndex);
        long lo = slice.lo - 1;
        long hi = slice.calcHi ? partition.size() : slice.hi + 1;
        rows.clear();
        for (int i = 0, n = keys.size(); i < n; i++) {
            IndexCursor c = index.cursor(keys.get(i) & buckets);
            while (c.hasNext()) {
                long r = rec.rowid = c.next();
                if (r > lo && r < hi && col.getInt(r) == keys.get(i) && (filter == null || filter.getBool(rec))) {
                    rows.add(r);
                    break;
                }
            }
        }
        rows.sort();
        cursor = 0;
        return this;
    } catch (JournalException e) {
        throw new JournalRuntimeException(e);
    }
}
Also used : Partition(com.questdb.store.Partition) JournalException(com.questdb.std.ex.JournalException) IndexCursor(com.questdb.store.IndexCursor) KVIndex(com.questdb.store.KVIndex) FixedColumn(com.questdb.store.FixedColumn)

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