use of com.questdb.std.ex.JournalException in project questdb by bluestreak01.
the class CachingWriterFactoryTest method testLockUnlock.
@Test
public void testLockUnlock() throws Exception {
final JournalMetadata<?> x = new JournalStructure("x").$date("ts").$().build();
final JournalMetadata<?> y = new JournalStructure("y").$date("ts").$().build();
JournalWriter wx = wf.writer(x);
Assert.assertNotNull(wx);
Assert.assertTrue(wx.isOpen());
JournalWriter wy = wf.writer(y);
Assert.assertNotNull(wy);
Assert.assertTrue(wy.isOpen());
try {
// check that lock is successful
wf.lock(x.getName());
// check that writer x is closed and writer y is open (lock must not spill out to other writers)
Assert.assertFalse(wx.isOpen());
Assert.assertTrue(wy.isOpen());
// check that when name is locked writers are not created
try {
wf.writer(x);
} catch (JournalLockedException ignored) {
}
final CountDownLatch done = new CountDownLatch(1);
final AtomicBoolean result = new AtomicBoolean();
// have new thread try to allocated this writers
new Thread(() -> {
try (JournalWriter ignored = wf.writer(x)) {
result.set(false);
} catch (WriterBusyException ignored) {
result.set(true);
} catch (JournalException e) {
e.printStackTrace();
result.set(false);
}
done.countDown();
}).start();
Assert.assertTrue(done.await(1, TimeUnit.SECONDS));
Assert.assertTrue(result.get());
wf.unlock(x.getName());
wx = wf.writer(x);
Assert.assertNotNull(wx);
Assert.assertTrue(wx.isOpen());
try {
// unlocking writer that has not been locked must produce exception
// and not affect open writer
wf.unlock(wx.getName());
Assert.fail();
} catch (IllegalStateException ignored) {
}
Assert.assertTrue(wx.isOpen());
} finally {
wx.close();
wy.close();
}
}
use of com.questdb.std.ex.JournalException in project questdb by bluestreak01.
the class CachingWriterFactoryTest method testNewLock.
@Test
public void testNewLock() throws Exception {
final JournalMetadata<?> m = new JournalStructure("x").$date("ts").$().build();
wf.lock("x");
try {
wf.writer(m);
Assert.fail();
} catch (JournalException ignored) {
}
wf.unlock("x");
}
use of com.questdb.std.ex.JournalException in project questdb by bluestreak01.
the class QueryModel method collectJournalMetadata.
public RecordMetadata collectJournalMetadata(Factory factory) throws ParserException {
if (journalMetadata != null) {
return journalMetadata;
}
ExprNode readerNode = getJournalName();
if (readerNode.type != ExprNode.LITERAL && readerNode.type != ExprNode.CONSTANT) {
throw QueryError.$(readerNode.position, "Journal name must be either literal or string constant");
}
String reader = stripMarker(Chars.stripQuotes(readerNode.token));
SystemViewFactory systemViewFactory = SysFactories.getFactory(reader);
if (systemViewFactory != null) {
return systemViewFactory.getMetadata();
}
int status = factory.getConfiguration().exists(reader);
if (status == JournalConfiguration.DOES_NOT_EXIST) {
throw QueryError.$(readerNode.position, "Journal does not exist");
}
if (status == JournalConfiguration.EXISTS_FOREIGN) {
throw QueryError.$(readerNode.position, "Journal directory is of unknown format");
}
try {
return journalMetadata = factory.getConfiguration().readMetadata(reader);
} catch (JournalException e) {
throw QueryError.$(readerNode.position, e.getMessage());
}
}
use of com.questdb.std.ex.JournalException in project questdb by bluestreak01.
the class JournalPartitionSource method next.
@Override
public PartitionSlice next() {
try {
slice.partition = journal.getPartition(partitionIndex++, open);
slice.lo = 0;
slice.calcHi = true;
return slice;
} catch (JournalException e) {
throw new JournalRuntimeException(e);
}
}
use of com.questdb.std.ex.JournalException in project questdb by bluestreak01.
the class KvIndexIntLambdaHeadRowSource method prepareCursor.
@Override
public RowCursor prepareCursor(PartitionSlice slice) {
try {
Partition partition = rec.partition = slice.partition.open();
KVIndex index = partition.getIndexForColumn(columnIndex);
FixedColumn col = partition.fixCol(columnIndex);
long lo = slice.lo - 1;
long hi = slice.calcHi ? partition.size() : slice.hi + 1;
rows.clear();
for (int i = 0, n = keys.size(); i < n; i++) {
IndexCursor c = index.cursor(keys.get(i) & buckets);
while (c.hasNext()) {
long r = rec.rowid = c.next();
if (r > lo && r < hi && col.getInt(r) == keys.get(i) && (filter == null || filter.getBool(rec))) {
rows.add(r);
break;
}
}
}
rows.sort();
cursor = 0;
return this;
} catch (JournalException e) {
throw new JournalRuntimeException(e);
}
}
Aggregations