use of com.questdb.std.ex.JournalException in project questdb by bluestreak01.
the class JournalTest method testInvalidColumnName.
@Test
public void testInvalidColumnName() {
File base = getFactory().getConfiguration().getJournalBase();
File dir = new File(base, "x");
Assert.assertFalse(dir.exists());
try {
getFactory().writer(new JournalStructure("x").$sym("x").index().$sym("y").index().$sym("z\0is\0bad").index().$());
Assert.fail();
} catch (JournalException ignore) {
}
getFactory().expire();
Assert.assertTrue(dir.exists());
Assert.assertTrue(Files.delete(dir));
}
use of com.questdb.std.ex.JournalException in project questdb by bluestreak01.
the class JournalTest method testOpenJournalWithWrongPartitionType.
@Test
public void testOpenJournalWithWrongPartitionType() throws Exception {
try (JournalWriter<Quote> w = getFactory().writer(new JournalKey<>(Quote.class, "quote", PartitionBy.NONE))) {
TestUtils.generateQuoteData(w, 1000);
}
try {
getFactory().writer(new JournalKey<>(Quote.class, "quote", PartitionBy.MONTH));
Assert.fail("Exception expected");
} catch (JournalException e) {
// expect exception
}
try (Factory f2 = new Factory(new JournalConfigurationBuilder() {
{
$(Quote.class).$sym("mode");
}
}.build(factoryContainer.getConfiguration().getJournalBase()))) {
f2.writer(new JournalKey<>(Quote.class, "quote"));
Assert.fail("Exception expected");
} catch (JournalException e) {
// expect exception
}
}
use of com.questdb.std.ex.JournalException in project questdb by bluestreak01.
the class QueryTest method testFindWithSearchSymbols.
@Test
public void testFindWithSearchSymbols() throws JournalException {
final long millis = System.currentTimeMillis();
Quote q1 = new Quote().setSym("S1").setEx("EX1").setTimestamp(millis);
Quote q2 = new Quote().setSym("S2").setEx("EX1").setTimestamp(millis);
Quote q3 = new Quote().setSym("S3").setEx("EX1").setTimestamp(millis);
Quote q4 = new Quote().setSym("S4").setEx("EX3").setTimestamp(millis);
w.append(q1, q2, q3, q4);
// Unfiltered
QueryAllBuilder<Quote> builder = q.all().withSymValues("ex", "EX1");
Assert.assertEquals(3, builder.asResultSet().size());
// Filtered
builder.filter("sym", q1.getSym()).filter("sym", q2.getSym());
Assert.assertEquals(2, builder.asResultSet().size());
// Non-existent
builder.resetFilter();
try {
builder.filter("sym", "S7");
Assert.fail("Expect exception here");
} catch (Exception e) {
// ok
}
// Filtered - 2 existing and 1 from a different exchange
builder.resetFilter();
builder.filter("sym", q1.getSym()).filter("sym", q2.getSym()).filter("sym", q4.getSym());
Assert.assertEquals(2, builder.asResultSet().size());
}
use of com.questdb.std.ex.JournalException in project questdb by bluestreak01.
the class CachingReaderFactoryTest method testLockBusyReader.
@Test
public void testLockBusyReader() throws Exception {
final int readerCount = 5;
int threadCount = 2;
final int iterations = 10000;
// create journals to read
final JournalMetadata<?>[] meta = new JournalMetadata[readerCount];
for (int i = 0; i < readerCount; i++) {
final JournalMetadata<?> m = new JournalStructure("x" + i).$date("ts").$().build();
((WriterFactory) getFactory()).writer(m).close();
meta[i] = m;
}
try {
try (final CachingReaderFactory rf = new CachingReaderFactory(factoryContainer.getConfiguration(), 1000, 2)) {
final CyclicBarrier barrier = new CyclicBarrier(threadCount);
final CountDownLatch halt = new CountDownLatch(threadCount);
final AtomicInteger errors = new AtomicInteger();
final LongList lockTimes = new LongList();
final LongList workerTimes = new LongList();
new Thread(() -> {
Rnd rnd = new Rnd();
try {
barrier.await();
String name = null;
for (int i = 0; i < iterations; i++) {
if (name == null) {
name = meta[rnd.nextPositiveInt() % readerCount].getName();
}
while (true) {
try {
rf.lock(name);
lockTimes.add(System.currentTimeMillis());
LockSupport.parkNanos(100L);
rf.unlock(name);
name = null;
break;
} catch (JournalException e) {
if (!(e instanceof RetryLockException)) {
e.printStackTrace();
errors.incrementAndGet();
break;
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
errors.incrementAndGet();
}
halt.countDown();
}).start();
new Thread(() -> {
Rnd rnd = new Rnd();
workerTimes.add(System.currentTimeMillis());
for (int i = 0; i < iterations; i++) {
JournalMetadata<?> metadata = meta[rnd.nextPositiveInt() % readerCount];
try (Journal<?> ignored = rf.reader(metadata)) {
if (metadata == meta[readerCount - 1] && barrier.getNumberWaiting() > 0) {
barrier.await();
}
LockSupport.parkNanos(10L);
} catch (JournalLockedException ignored) {
} catch (Exception e) {
e.printStackTrace();
errors.incrementAndGet();
}
}
workerTimes.add(System.currentTimeMillis());
halt.countDown();
}).start();
halt.await();
Assert.assertEquals(0, errors.get());
// check that there are lock times between worker times
int count = 0;
// ensure that we have worker times
Assert.assertEquals(2, workerTimes.size());
long lo = workerTimes.get(0);
long hi = workerTimes.get(1);
Assert.assertTrue(lockTimes.size() > 0);
for (int i = 0, n = lockTimes.size(); i < n; i++) {
long t = lockTimes.getQuick(i);
if (t > lo && t < hi) {
count++;
}
}
Assert.assertTrue(count > 0);
}
} catch (Throwable e) {
e.printStackTrace();
}
}
use of com.questdb.std.ex.JournalException in project questdb by bluestreak01.
the class Journal method configureColumns.
private void configureColumns() throws JournalException {
int columnCount = getMetadata().getColumnCount();
try {
for (int i = 0; i < columnCount; i++) {
ColumnMetadata meta = metadata.getColumnQuick(i);
if (meta.type == ColumnType.SYMBOL && meta.sameAs == null) {
int tabIndex = symbolTables.size();
int tabSize = tx.symbolTableSizes.length > tabIndex ? tx.symbolTableSizes[tabIndex] : 0;
long indexTxAddress = tx.symbolTableIndexPointers.length > tabIndex ? tx.symbolTableIndexPointers[tabIndex] : 0;
MMappedSymbolTable tab = new MMappedSymbolTable(meta.distinctCountHint, meta.avgSize, getMetadata().getTxCountHint(), location, meta.name, getMode(), tabSize, indexTxAddress, meta.noCache, sequentialAccess);
symbolTables.add(tab);
symbolTableMap.put(meta.name, tab);
meta.symbolTable = tab;
}
}
} catch (JournalException e) {
closeSymbolTables();
throw e;
}
}
Aggregations