Search in sources :

Example 11 with JournalRuntimeException

use of com.questdb.common.JournalRuntimeException in project questdb by bluestreak01.

the class Lock method release.

synchronized void release() {
    try {
        if (isValid()) {
            lock.release();
            lock = null;
        }
        if (file != null) {
            file.close();
            file = null;
        }
    } catch (IOException e) {
        throw new JournalRuntimeException(e);
    }
}
Also used : JournalRuntimeException(com.questdb.common.JournalRuntimeException) IOException(java.io.IOException)

Example 12 with JournalRuntimeException

use of com.questdb.common.JournalRuntimeException in project questdb by bluestreak01.

the class MemoryFile method mapBufferInternal.

private MappedByteBuffer mapBufferInternal(long offset, int size) {
    long actualOffset = offset + DATA_OFFSET;
    try {
        MappedByteBuffer buf;
        switch(journalMode) {
            case JournalMode.READ:
                // make sure size does not extend beyond actual file size, otherwise
                // java would assume we want to write and throw an exception
                long sz;
                if (actualOffset + ((long) size) > channel.size()) {
                    sz = channel.size() - actualOffset;
                } else {
                    sz = size;
                }
                assert sz > 0;
                buf = channel.map(FileChannel.MapMode.READ_ONLY, actualOffset, sz);
                break;
            default:
                buf = channel.map(FileChannel.MapMode.READ_WRITE, actualOffset, size);
                break;
        }
        buf.order(ByteOrder.LITTLE_ENDIAN);
        return buf;
    } catch (IOException e) {
        throw new JournalRuntimeException("Failed to memory map: %s", e, file.getAbsolutePath());
    }
}
Also used : MappedByteBuffer(java.nio.MappedByteBuffer) JournalRuntimeException(com.questdb.common.JournalRuntimeException) JournalIOException(com.questdb.ex.JournalIOException)

Example 13 with JournalRuntimeException

use of com.questdb.common.JournalRuntimeException in project questdb by bluestreak01.

the class Partition method updateIndexes.

public void updateIndexes(long oldSize, long newSize) {
    if (oldSize < newSize) {
        try {
            for (int n = 0, k = indexProxies.size(); n < k; n++) {
                SymbolIndexProxy<T> proxy = indexProxies.getQuick(n);
                KVIndex index = proxy.getIndex();
                FixedColumn col = fixCol(proxy.getColumnIndex());
                for (long i = oldSize; i < newSize; i++) {
                    index.add(col.getInt(i), i);
                }
                index.commit();
            }
        } catch (JournalException e) {
            throw new JournalRuntimeException(e);
        }
    }
}
Also used : JournalException(com.questdb.std.ex.JournalException) JournalRuntimeException(com.questdb.common.JournalRuntimeException)

Example 14 with JournalRuntimeException

use of com.questdb.common.JournalRuntimeException in project questdb by bluestreak01.

the class VariableColumn method getBin.

private void getBin(long localRowID, OutputStream s, int len) {
    initStreamBuf();
    // skip size
    long offset = getOffset(localRowID) + 4;
    int blockRemaining = 0;
    long blockAddress = 0;
    try {
        while (len > 0) {
            if (blockRemaining == 0) {
                blockAddress = mappedFile.addressOf(offset, 1);
                blockRemaining = mappedFile.pageRemaining(offset);
            }
            int l = len > blockRemaining ? blockRemaining : len;
            Unsafe.getUnsafe().copyMemory(null, blockAddress, streamBuf, Unsafe.BYTE_OFFSET, l);
            offset += l;
            blockRemaining -= l;
            len -= l;
            blockAddress += l;
            s.write(streamBuf, 0, l);
        }
    } catch (IOException e) {
        throw new JournalRuntimeException(e);
    }
}
Also used : JournalRuntimeException(com.questdb.common.JournalRuntimeException) IOException(java.io.IOException)

Example 15 with JournalRuntimeException

use of com.questdb.common.JournalRuntimeException in project questdb by bluestreak01.

the class VariableColumn method putBin.

public void putBin(InputStream s) {
    if (s == null) {
        putNull();
        return;
    }
    initStreamBuf();
    final long rowOffset = getOffset();
    long off = rowOffset + 4;
    int blockRemaining = 0;
    long blockAddress = 0;
    int bufRemaining;
    int sz = 0;
    try {
        while ((bufRemaining = s.read(streamBuf)) != -1) {
            sz += bufRemaining;
            long streamOffset = Unsafe.BYTE_OFFSET;
            while (bufRemaining > 0) {
                if (blockRemaining == 0) {
                    blockAddress = mappedFile.addressOf(off, 1);
                    blockRemaining = mappedFile.pageRemaining(off);
                }
                if (blockRemaining < 1) {
                    throw new JournalRuntimeException("Internal error. Unable to allocateOffset disk block");
                }
                int len = bufRemaining > blockRemaining ? blockRemaining : bufRemaining;
                Unsafe.getUnsafe().copyMemory(streamBuf, streamOffset, null, blockAddress, len);
                bufRemaining -= len;
                off += len;
                blockRemaining -= len;
                blockAddress += len;
                streamOffset += len;
            }
        }
        long a = mappedFile.addressOf(rowOffset, 4);
        Unsafe.getUnsafe().putInt(a, sz);
        commitAppend(rowOffset, sz + 4);
    } catch (IOException e) {
        throw new JournalRuntimeException(e);
    }
}
Also used : JournalRuntimeException(com.questdb.common.JournalRuntimeException) IOException(java.io.IOException)

Aggregations

JournalRuntimeException (com.questdb.common.JournalRuntimeException)41 JournalException (com.questdb.std.ex.JournalException)30 KVIndex (com.questdb.store.KVIndex)9 IOException (java.io.IOException)6 IndexCursor (com.questdb.store.IndexCursor)5 Partition (com.questdb.store.Partition)5 ObjList (com.questdb.std.ObjList)4 FixedColumn (com.questdb.store.FixedColumn)2 File (java.io.File)2 MappedByteBuffer (java.nio.MappedByteBuffer)2 BootstrapEnv (com.questdb.BootstrapEnv)1 ServerConfiguration (com.questdb.ServerConfiguration)1 NumericException (com.questdb.common.NumericException)1 ImportColumnCountException (com.questdb.ex.ImportColumnCountException)1 ImportNameException (com.questdb.ex.ImportNameException)1 IncompatibleJournalException (com.questdb.ex.IncompatibleJournalException)1 JournalIOException (com.questdb.ex.JournalIOException)1 Quote (com.questdb.model.Quote)1 ClientConfig (com.questdb.net.ha.config.ClientConfig)1 ImportedColumnMetadata (com.questdb.parser.ImportedColumnMetadata)1