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