use of com.questdb.std.ex.JournalException in project questdb by bluestreak01.
the class JournalConcurrentIterator method getRunnable.
private Runnable getRunnable() {
return new Runnable() {
boolean hasNext = true;
private int currentIndex = 0;
private long currentRowID;
private long currentUpperBound;
private int currentPartitionID;
@Override
public void run() {
updateVariables();
while (true) {
try {
long cursor = pubSeq.nextBully();
Holder<T> holder = buffer.get(cursor);
boolean hadNext = hasNext;
if (hadNext) {
journal.read(Rows.toRowID(currentPartitionID, currentRowID), holder.object);
if (currentRowID < currentUpperBound) {
currentRowID++;
} else {
currentIndex++;
updateVariables();
}
}
holder.hasNext = hadNext;
pubSeq.done(cursor);
if (!hadNext) {
break;
}
} catch (JournalException e) {
throw new JournalRuntimeException("Error in iterator [%s]", e, this);
}
}
}
private void updateVariables() {
if (currentIndex < ranges.size()) {
JournalIteratorRange w = ranges.getQuick(currentIndex);
currentRowID = w.lo;
currentUpperBound = w.hi;
currentPartitionID = w.partitionID;
} else {
hasNext = false;
}
}
};
}
use of com.questdb.std.ex.JournalException in project questdb by bluestreak01.
the class QueryAllImpl method incrementBufferedIterator.
@Override
public JournalPeekingIterator<T> incrementBufferedIterator() {
try {
long lo = journal.getMaxRowID();
journal.refresh();
return new JournalBufferedIterator<>(journal, createRanges(journal.incrementRowID(lo)));
} catch (JournalException e) {
throw new JournalRuntimeException(e);
}
}
use of com.questdb.std.ex.JournalException in project questdb by bluestreak01.
the class QueryHeadBuilderImpl method asResultSet.
public UnorderedResultSet<T> asResultSet() throws JournalException {
final int minPartitionIndex;
final long minLocalRowID;
if (minRowID == -1L) {
minPartitionIndex = 0;
minLocalRowID = -1L;
} else {
minPartitionIndex = Rows.toPartitionIndex(minRowID);
minLocalRowID = Rows.toLocalRowID(minRowID);
}
zone1Keys.clear(symbolKeys.size());
zone2Keys.clear(symbolKeys.size());
zone1Keys.addAll(symbolKeys);
// noinspection ConstantConditions
return journal.iteratePartitionsDesc(new UnorderedResultSetBuilder<T>(interval) {
private final KVIndex[] filterKVIndexes = new KVIndex[filterSymbolKeys.size()];
private final LongList[] filterSymbolRows = new LongList[filterSymbolKeys.size()];
private IntList keys = zone1Keys;
private IntList remainingKeys = zone2Keys;
@Override
public Accept accept(Partition<T> partition) throws JournalException {
super.accept(partition);
return keys.size() == 0 || partition.getPartitionIndex() < minPartitionIndex ? Accept.BREAK : Accept.CONTINUE;
}
@Override
public void read(long lo, long hi) throws JournalException {
KVIndex index = partition.getIndexForColumn(symbolColumnIndex);
boolean filterOk = true;
for (int i = 0; i < filterSymbols.size(); i++) {
filterKVIndexes[i] = partition.getIndexForColumn(filterSymbols.getQuick(i));
int filterKey = filterSymbolKeys.getQuick(i);
if (filterKVIndexes[i].contains(filterKey)) {
filterSymbolRows[i].ensureCapacity(filterKVIndexes[i].getValueCount(filterKey));
filterKVIndexes[i].getValues(filterKey, filterSymbolRows[i]);
} else {
filterOk = false;
break;
}
}
if (filterOk) {
for (int k = 0; k < keys.size(); k++) {
int key = keys.getQuick(k);
boolean found = false;
IndexCursor cursor = index.cursor(key);
NEXT_KEY: while (cursor.hasNext()) {
long localRowID = cursor.next();
if (localRowID <= hi && localRowID >= lo && (partition.getPartitionIndex() > minPartitionIndex || localRowID > minLocalRowID)) {
boolean matches = true;
for (int i = 0; i < filterSymbolRows.length; i++) {
if (filterSymbolRows[i].binarySearch(localRowID) < 0) {
matches = false;
if (strict) {
found = true;
break NEXT_KEY;
} else {
break;
}
}
}
if (matches) {
result.add(Rows.toRowID(partition.getPartitionIndex(), localRowID));
found = true;
break;
}
} else if (localRowID < lo || (partition.getPartitionIndex() <= minPartitionIndex && localRowID <= minLocalRowID)) {
// localRowID is only going to get lower, so fail fast
found = true;
break;
}
}
if (!found) {
remainingKeys.add(key);
}
}
IntList temp = keys;
keys = remainingKeys;
remainingKeys = temp;
remainingKeys.clear();
}
}
{
for (int i = 0; i < filterSymbolRows.length; i++) {
filterSymbolRows[i] = new LongList();
}
}
});
}
use of com.questdb.std.ex.JournalException in project questdb by bluestreak01.
the class GenericInteropTest method testInvalidColumnName.
@Test
public void testInvalidColumnName() throws Exception {
File location = null;
try (JournalWriter w = getFactory().writer(new JournalStructure("test") {
{
$int("id").index();
$str("status?\0x");
}
})) {
location = w.getLocation();
w.entryWriter();
} catch (JournalException ignore) {
// ignore
}
Assert.assertNotNull(location);
Files.deleteOrException(location);
try (JournalWriter w = getFactory().writer(new JournalStructure("test") {
{
$int("id").index();
$str("status");
}
})) {
w.entryWriter();
}
}
use of com.questdb.std.ex.JournalException in project questdb by bluestreak01.
the class JournalTest method testReindex.
@Test
public void testReindex() throws JournalException, NumericException {
File path;
try (JournalWriter<Quote> w = getFactory().writer(Quote.class)) {
TestData.appendQuoteData1(w);
path = w.getLocation();
}
getFactory().lock(Quote.class.getName());
try {
Files.deleteOrException(new File(path, "2013-02/sym.r"));
Files.deleteOrException(new File(path, "2013-02/sym.k"));
} finally {
getFactory().unlock(Quote.class.getName());
}
try (Journal<Quote> journal = getFactory().reader(Quote.class)) {
try {
journal.query().head().withKeys().asResultSet().read();
Assert.fail("Expected exception here");
} catch (JournalException e) {
// do nothing
}
try (JournalWriter<Quote> w = getFactory().writer(Quote.class)) {
w.rebuildIndexes();
}
Assert.assertEquals(3, journal.query().head().withKeys().asResultSet().read().length);
}
}
Aggregations