Search in sources :

Example 41 with JournalException

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

the class JournalConcurrentIterator method getRunnable.

private Runnable getRunnable() {
    return new Runnable() {

        boolean hasNext = true;

        private int currentIndex = 0;

        private long currentRowID;

        private long currentUpperBound;

        private int currentPartitionID;

        @Override
        public void run() {
            updateVariables();
            while (true) {
                try {
                    long cursor = pubSeq.nextBully();
                    Holder<T> holder = buffer.get(cursor);
                    boolean hadNext = hasNext;
                    if (hadNext) {
                        journal.read(Rows.toRowID(currentPartitionID, currentRowID), holder.object);
                        if (currentRowID < currentUpperBound) {
                            currentRowID++;
                        } else {
                            currentIndex++;
                            updateVariables();
                        }
                    }
                    holder.hasNext = hadNext;
                    pubSeq.done(cursor);
                    if (!hadNext) {
                        break;
                    }
                } catch (JournalException e) {
                    throw new JournalRuntimeException("Error in iterator [%s]", e, this);
                }
            }
        }

        private void updateVariables() {
            if (currentIndex < ranges.size()) {
                JournalIteratorRange w = ranges.getQuick(currentIndex);
                currentRowID = w.lo;
                currentUpperBound = w.hi;
                currentPartitionID = w.partitionID;
            } else {
                hasNext = false;
            }
        }
    };
}
Also used : JournalException(com.questdb.std.ex.JournalException) JournalRuntimeException(com.questdb.common.JournalRuntimeException)

Example 42 with JournalException

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

the class QueryAllImpl method incrementBufferedIterator.

@Override
public JournalPeekingIterator<T> incrementBufferedIterator() {
    try {
        long lo = journal.getMaxRowID();
        journal.refresh();
        return new JournalBufferedIterator<>(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 43 with JournalException

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

the class QueryHeadBuilderImpl method asResultSet.

public UnorderedResultSet<T> asResultSet() throws JournalException {
    final int minPartitionIndex;
    final long minLocalRowID;
    if (minRowID == -1L) {
        minPartitionIndex = 0;
        minLocalRowID = -1L;
    } else {
        minPartitionIndex = Rows.toPartitionIndex(minRowID);
        minLocalRowID = Rows.toLocalRowID(minRowID);
    }
    zone1Keys.clear(symbolKeys.size());
    zone2Keys.clear(symbolKeys.size());
    zone1Keys.addAll(symbolKeys);
    // noinspection ConstantConditions
    return journal.iteratePartitionsDesc(new UnorderedResultSetBuilder<T>(interval) {

        private final KVIndex[] filterKVIndexes = new KVIndex[filterSymbolKeys.size()];

        private final LongList[] filterSymbolRows = new LongList[filterSymbolKeys.size()];

        private IntList keys = zone1Keys;

        private IntList remainingKeys = zone2Keys;

        @Override
        public Accept accept(Partition<T> partition) throws JournalException {
            super.accept(partition);
            return keys.size() == 0 || partition.getPartitionIndex() < minPartitionIndex ? Accept.BREAK : Accept.CONTINUE;
        }

        @Override
        public void read(long lo, long hi) throws JournalException {
            KVIndex index = partition.getIndexForColumn(symbolColumnIndex);
            boolean filterOk = true;
            for (int i = 0; i < filterSymbols.size(); i++) {
                filterKVIndexes[i] = partition.getIndexForColumn(filterSymbols.getQuick(i));
                int filterKey = filterSymbolKeys.getQuick(i);
                if (filterKVIndexes[i].contains(filterKey)) {
                    filterSymbolRows[i].ensureCapacity(filterKVIndexes[i].getValueCount(filterKey));
                    filterKVIndexes[i].getValues(filterKey, filterSymbolRows[i]);
                } else {
                    filterOk = false;
                    break;
                }
            }
            if (filterOk) {
                for (int k = 0; k < keys.size(); k++) {
                    int key = keys.getQuick(k);
                    boolean found = false;
                    IndexCursor cursor = index.cursor(key);
                    NEXT_KEY: while (cursor.hasNext()) {
                        long localRowID = cursor.next();
                        if (localRowID <= hi && localRowID >= lo && (partition.getPartitionIndex() > minPartitionIndex || localRowID > minLocalRowID)) {
                            boolean matches = true;
                            for (int i = 0; i < filterSymbolRows.length; i++) {
                                if (filterSymbolRows[i].binarySearch(localRowID) < 0) {
                                    matches = false;
                                    if (strict) {
                                        found = true;
                                        break NEXT_KEY;
                                    } else {
                                        break;
                                    }
                                }
                            }
                            if (matches) {
                                result.add(Rows.toRowID(partition.getPartitionIndex(), localRowID));
                                found = true;
                                break;
                            }
                        } else if (localRowID < lo || (partition.getPartitionIndex() <= minPartitionIndex && localRowID <= minLocalRowID)) {
                            // localRowID is only going to get lower, so fail fast
                            found = true;
                            break;
                        }
                    }
                    if (!found) {
                        remainingKeys.add(key);
                    }
                }
                IntList temp = keys;
                keys = remainingKeys;
                remainingKeys = temp;
                remainingKeys.clear();
            }
        }

        {
            for (int i = 0; i < filterSymbolRows.length; i++) {
                filterSymbolRows[i] = new LongList();
            }
        }
    });
}
Also used : JournalException(com.questdb.std.ex.JournalException) LongList(com.questdb.std.LongList) IntList(com.questdb.std.IntList)

Example 44 with JournalException

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

the class GenericInteropTest method testInvalidColumnName.

@Test
public void testInvalidColumnName() throws Exception {
    File location = null;
    try (JournalWriter w = getFactory().writer(new JournalStructure("test") {

        {
            $int("id").index();
            $str("status?\0x");
        }
    })) {
        location = w.getLocation();
        w.entryWriter();
    } catch (JournalException ignore) {
    // ignore
    }
    Assert.assertNotNull(location);
    Files.deleteOrException(location);
    try (JournalWriter w = getFactory().writer(new JournalStructure("test") {

        {
            $int("id").index();
            $str("status");
        }
    })) {
        w.entryWriter();
    }
}
Also used : JournalWriter(com.questdb.store.JournalWriter) 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 45 with JournalException

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

the class JournalTest method testReindex.

@Test
public void testReindex() throws JournalException, NumericException {
    File path;
    try (JournalWriter<Quote> w = getFactory().writer(Quote.class)) {
        TestData.appendQuoteData1(w);
        path = w.getLocation();
    }
    getFactory().lock(Quote.class.getName());
    try {
        Files.deleteOrException(new File(path, "2013-02/sym.r"));
        Files.deleteOrException(new File(path, "2013-02/sym.k"));
    } finally {
        getFactory().unlock(Quote.class.getName());
    }
    try (Journal<Quote> journal = getFactory().reader(Quote.class)) {
        try {
            journal.query().head().withKeys().asResultSet().read();
            Assert.fail("Expected exception here");
        } catch (JournalException e) {
        // do nothing
        }
        try (JournalWriter<Quote> w = getFactory().writer(Quote.class)) {
            w.rebuildIndexes();
        }
        Assert.assertEquals(3, journal.query().head().withKeys().asResultSet().read().length);
    }
}
Also used : Quote(com.questdb.model.Quote) JournalException(com.questdb.std.ex.JournalException) File(java.io.File) 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