Search in sources :

Example 11 with JournalException

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

the class JournalIterators method incrementIterator.

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

Example 12 with JournalException

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

the class JournalWriter method close.

@Override
public final void close() {
    if (open) {
        if (closeInterceptor != null && !closeInterceptor.canClose(this)) {
            return;
        }
        try {
            if (isCommitOnClose()) {
                commit();
            }
            if (partitionCleaner != null) {
                purgeTempPartitions();
                partitionCleaner.halt();
                partitionCleaner = null;
            }
            super.close();
            if (writeLock != null) {
                LockManager.release(writeLock);
                writeLock = null;
            }
            Misc.free(discardSink);
            Misc.free(discardTxtRaf);
        } catch (JournalException e) {
            throw new JournalRuntimeException(e);
        }
    }
}
Also used : IncompatibleJournalException(com.questdb.ex.IncompatibleJournalException) JournalException(com.questdb.std.ex.JournalException) JournalRuntimeException(com.questdb.common.JournalRuntimeException)

Example 13 with JournalException

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

the class JournalWriter method getAppendPartition.

public Partition<T> getAppendPartition(long timestamp) throws JournalException {
    int sz = partitions.size();
    if (sz > 0) {
        Partition<T> par = partitions.getQuick(sz - 1);
        Interval interval = par.getInterval();
        if (interval == null || interval.contains(timestamp)) {
            return par.open().access();
        } else if (interval.isBefore(timestamp)) {
            return createPartition(new Interval(timestamp, getMetadata().getPartitionBy()), sz);
        } else {
            throw new JournalException("%s cannot be appended to %s", Dates.toString(timestamp), this);
        }
    } else {
        return createPartition(new Interval(timestamp, getMetadata().getPartitionBy()), 0);
    }
}
Also used : IncompatibleJournalException(com.questdb.ex.IncompatibleJournalException) JournalException(com.questdb.std.ex.JournalException) Interval(com.questdb.std.time.Interval)

Example 14 with JournalException

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

the class JournalWriter method configure.

@Override
protected void configure() throws JournalException {
    writeLock = LockManager.lockExclusive(getLocation().getAbsolutePath());
    if (writeLock == null || !writeLock.isValid()) {
        close();
        LOG.error().$("Cannot obtain lock on ").$(getLocation().getAbsolutePath()).$();
        throw JournalWriterAlreadyOpenException.INSTANCE;
    }
    try {
        if (txLog.isEmpty()) {
            commit(Tx.TX_NORMAL, 0L, 0L);
        }
        txLog.head(tx);
        File meta = new File(getLocation(), JournalConfiguration.FILE_NAME);
        if (!meta.exists()) {
            try (UnstructuredFile hb = new UnstructuredFile(meta, 12, JournalMode.APPEND)) {
                getMetadata().write(hb);
            }
        }
        super.configure();
        beginTx();
        rollback();
        rollbackPartitionDirs();
        if (tx.journalMaxRowID > 0 && getPartitionCount() <= Rows.toPartitionIndex(tx.journalMaxRowID)) {
            beginTx();
            commit();
        }
        if (getMetadata().getLag() != -1) {
            this.partitionCleaner = new PartitionCleaner(this, getLocation().getName());
            this.partitionCleaner.start();
        }
    } catch (JournalException e) {
        close();
        throw e;
    }
}
Also used : IncompatibleJournalException(com.questdb.ex.IncompatibleJournalException) JournalException(com.questdb.std.ex.JournalException) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File)

Example 15 with JournalException

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

the class MemoryFile method compact.

public void compact() throws JournalException {
    close();
    try {
        openInternal("rw");
        try {
            long newSize = getAppendOffset() + DATA_OFFSET;
            offsetBuffer = ByteBuffers.release(offsetBuffer);
            LOG.debug().$("Compacting ").$(this).$(" to ").$(newSize).$(" bytes").$();
            channel.truncate(newSize).close();
        } catch (IOException e) {
            throw new JournalException("Could not compact %s to %d bytes", e, getFullFileName(), getAppendOffset());
        } finally {
            close();
        }
    } finally {
        open();
    }
}
Also used : JournalException(com.questdb.std.ex.JournalException) JournalIOException(com.questdb.ex.JournalIOException)

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