use of com.questdb.store.Journal in project questdb by bluestreak01.
the class DDLTests method testCreateIndexedInt.
@Test
public void testCreateIndexedInt() throws Exception {
exec("create table x (a INT index buckets 25, b BYTE, t DATE, x SYMBOL) timestamp(t) partition by MONTH record hint 100");
// validate journal
try (Journal r = getFactory().reader("x")) {
Assert.assertNotNull(r);
JournalMetadata m = r.getMetadata();
Assert.assertEquals(4, m.getColumnCount());
Assert.assertEquals(ColumnType.INT, m.getColumn("a").getType());
Assert.assertTrue(m.getColumn("a").isIndexed());
// bucket is ceilPow2(value) - 1
Assert.assertEquals(31, m.getColumn("a").getBucketCount());
Assert.assertEquals(ColumnType.BYTE, m.getColumn("b").getType());
Assert.assertEquals(ColumnType.DATE, m.getColumn("t").getType());
Assert.assertEquals(ColumnType.SYMBOL, m.getColumn("x").getType());
Assert.assertEquals(2, m.getTimestampIndex());
Assert.assertEquals(PartitionBy.MONTH, m.getPartitionBy());
}
}
use of com.questdb.store.Journal in project questdb by bluestreak01.
the class FactoryEventLoggerTest method testThroughput.
@Test
@Ignore
public void testThroughput() throws Exception {
final FactoryEventLogger logger = new FactoryEventLogger(getFactory(), 1000, 1000, MicrosecondClockImpl.INSTANCE);
final int count = 1000;
final CountDownLatch done = new CountDownLatch(1);
final CyclicBarrier barrier = new CyclicBarrier(2);
final FactoryEventListener listener = getFactory().getEventListener();
new Thread(() -> {
try (Journal r = getFactory().reader("$mon_factory")) {
barrier.await();
int i = 0;
while (i < count) {
if (logger.run()) {
i++;
} else {
r.refresh();
if (r.size() == count) {
break;
}
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
done.countDown();
}
}).start();
barrier.await();
int i = 0;
while (i < count) {
if (listener.onEvent((byte) 1, 1, "test", (short) 1, (short) 0, (short) 5)) {
i++;
} else {
LockSupport.parkNanos(1);
}
}
done.await();
logger.close();
try (Journal r = getFactory().reader("$mon_factory")) {
System.out.println(r.size());
}
}
use of com.questdb.store.Journal in project questdb by bluestreak01.
the class CachingReaderFactoryTest method testLockUnlockMultiple.
@Test
public void testLockUnlockMultiple() throws Exception {
final JournalMetadata<?> m1 = new JournalStructure("x").$date("ts").$().build();
getFactory().writer(m1).close();
try (final CachingReaderFactory rf = new CachingReaderFactory(factoryContainer.getConfiguration(), 1000, 2)) {
Journal r1 = rf.reader(m1);
Journal r2 = rf.reader(m1);
r1.close();
try {
rf.lock(m1.getName());
} catch (RetryLockException e) {
e.printStackTrace();
}
r2.close();
rf.lock(m1.getName());
rf.unlock(m1.getName());
}
}
use of com.questdb.store.Journal in project questdb by bluestreak01.
the class CachingReaderFactoryTest method testCloseWithInactiveReader.
@Test
public void testCloseWithInactiveReader() throws Exception {
// create journal
final JournalMetadata<?> m = new JournalStructure("x").$date("ts").$().build();
((WriterFactory) getFactory()).writer(m).close();
try (final CachingReaderFactory rf = new CachingReaderFactory(factoryContainer.getConfiguration(), 1000, 2)) {
Journal reader = rf.reader(m);
Assert.assertNotNull(reader);
reader.close();
Assert.assertTrue(reader.isOpen());
rf.close();
Assert.assertFalse(reader.isOpen());
}
}
use of com.questdb.store.Journal 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();
}
}
Aggregations