Search in sources :

Example 21 with JournalException

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

the class CachingWriterFactory method canClose.

@Override
public boolean canClose(Journal journal) {
    String name = journal.getName();
    Entry e = entries.get(name);
    long thread = Thread.currentThread().getId();
    if (e != null) {
        if (e.owner != -1) {
            if (e.writer.isCommitOnClose()) {
                try {
                    e.writer.commit();
                } catch (JournalException ex) {
                    notifyListener(thread, name, FactoryEventListener.EV_COMMIT_EX);
                    throw new JournalRuntimeException(ex);
                }
            }
            LOG.info().$("Writer '").$(name).$(" is back in pool").$();
            e.lastReleaseTime = System.currentTimeMillis();
            if (closed || e.writer.isInError()) {
                LOG.info().$("Closing writer '").$(name).$('\'').$();
                e.writer.setCloseInterceptor(null);
                e.writer = null;
                entries.remove(name);
                notifyListener(thread, name, FactoryEventListener.EV_OUT_OF_POOL_CLOSE);
                return true;
            }
            e.owner = -1L;
            notifyListener(thread, name, FactoryEventListener.EV_RETURN);
        } else {
            LOG.error().$("Writer '").$(name).$("' is not allocated ").$(e.owner).$();
            notifyListener(thread, name, FactoryEventListener.EV_UNEXPECTED_CLOSE);
        }
    } else {
        LOG.error().$("Writer '").$(name).$("' is not managed by this pool").$();
        journal.setCloseInterceptor(null);
        notifyListener(thread, name, FactoryEventListener.EV_NOT_IN_POOL);
        return true;
    }
    return false;
}
Also used : JournalException(com.questdb.std.ex.JournalException) JournalRuntimeException(com.questdb.common.JournalRuntimeException)

Example 22 with JournalException

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

the class CachingWriterFactory method createWriter.

@SuppressWarnings("unchecked")
private <T> JournalWriter<T> createWriter(long thread, String name, Entry e, JournalMetadata<T> metadata) throws JournalException {
    try {
        JournalMetadata<T> mo = getConfiguration().readMetadata(metadata.getName());
        if (mo != null && !mo.isCompatible(metadata, false)) {
            throw new JournalMetadataException(mo, metadata);
        }
        if (closed) {
            throw FactoryClosedException.INSTANCE;
        }
        JournalWriter<T> w = new JournalWriter<>(metadata, new File(getConfiguration().getJournalBase(), name));
        w.setCloseInterceptor(this);
        LOG.info().$("Writer '").$(name).$("' is allocated by thread ").$(e.owner).$();
        e.writer = w;
        notifyListener(thread, name, FactoryEventListener.EV_CREATE);
        return w;
    } catch (JournalException ex) {
        LOG.error().$("Failed to allocate writer '").$(name).$("' in thread ").$(e.owner).$(": ").$(ex).$();
        e.ex = ex;
        notifyListener(thread, name, FactoryEventListener.EV_CREATE_EX);
        throw ex;
    }
}
Also used : JournalWriter(com.questdb.store.JournalWriter) JournalException(com.questdb.std.ex.JournalException) File(java.io.File)

Example 23 with JournalException

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

the class ResultSet method compare.

private static <T> int compare(Journal<T> journal, int[] columns, long rightRowID, long leftRowID) throws JournalException {
    int result = 0;
    long leftLocalRowID = Rows.toLocalRowID(leftRowID);
    long rightLocalRowID = Rows.toLocalRowID(rightRowID);
    Partition<T> leftPart = journal.getPartition(Rows.toPartitionIndex(leftRowID), true);
    Partition<T> rightPart = journal.getPartition(Rows.toPartitionIndex(rightRowID), true);
    for (int column : columns) {
        ColumnMetadata meta = journal.getMetadata().getColumnQuick(column);
        String leftStr;
        String rightStr;
        switch(meta.type) {
            case ColumnType.STRING:
                leftStr = leftPart.getStr(leftLocalRowID, column);
                rightStr = rightPart.getStr(rightLocalRowID, column);
                if (leftStr == null && rightStr == null) {
                    result = 0;
                } else if (leftStr == null) {
                    result = 1;
                } else if (rightStr == null) {
                    result = -1;
                } else {
                    result = rightStr.compareTo(leftStr);
                }
                break;
            default:
                switch(meta.type) {
                    case ColumnType.INT:
                        result = compare(rightPart.getInt(rightLocalRowID, column), leftPart.getInt(leftLocalRowID, column));
                        break;
                    case ColumnType.LONG:
                    case ColumnType.DATE:
                        result = compare(rightPart.getLong(rightLocalRowID, column), leftPart.getLong(leftLocalRowID, column));
                        break;
                    case ColumnType.DOUBLE:
                        result = compare(rightPart.getDouble(rightLocalRowID, column), leftPart.getDouble(leftLocalRowID, column));
                        break;
                    case ColumnType.FLOAT:
                        result = compare(rightPart.getFloat(rightLocalRowID, column), leftPart.getFloat(leftLocalRowID, column));
                        break;
                    case ColumnType.SYMBOL:
                        int leftSymIndex = leftPart.getInt(leftLocalRowID, column);
                        int rightSymIndex = rightPart.getInt(rightLocalRowID, column);
                        if (leftSymIndex == SymbolTable.VALUE_IS_NULL && rightSymIndex == SymbolTable.VALUE_IS_NULL) {
                            result = 0;
                        } else if (leftSymIndex == SymbolTable.VALUE_IS_NULL) {
                            result = 1;
                        } else if (rightSymIndex == SymbolTable.VALUE_IS_NULL) {
                            result = -1;
                        } else {
                            leftStr = meta.symbolTable.value(leftSymIndex);
                            rightStr = meta.symbolTable.value(rightSymIndex);
                            if (leftStr == null || rightStr == null) {
                                throw new JournalException("Corrupt column [%s] !", meta);
                            }
                            result = rightStr.compareTo(leftStr);
                        }
                        break;
                    default:
                        throw new JournalException("Unsupported type: " + meta.type);
                }
        }
        if (result != 0) {
            break;
        }
    }
    return result;
}
Also used : ColumnMetadata(com.questdb.store.factory.configuration.ColumnMetadata) JournalException(com.questdb.std.ex.JournalException)

Example 24 with JournalException

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

the class JournalIteratorImpl method next.

@Override
public T next() {
    try {
        T result = journal.read(Rows.toRowID(currentPartitionID, currentRowID));
        if (currentRowID < currentUpperBound) {
            currentRowID++;
        } else {
            currentIndex++;
            updateVariables();
        }
        return result;
    } catch (JournalException e) {
        throw new JournalRuntimeException("Error in iterator [%s]", e, this);
    }
}
Also used : JournalException(com.questdb.std.ex.JournalException) JournalRuntimeException(com.questdb.common.JournalRuntimeException)

Example 25 with JournalException

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

the class QueryAllImpl method createRanges.

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

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