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);
}
}
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());
}
}
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);
}
}
}
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);
}
}
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);
}
}
Aggregations