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