use of com.questdb.std.time.Interval in project questdb by bluestreak01.
the class JournalWriter method switchAppendPartition.
private void switchAppendPartition(long timestamp) throws JournalException {
boolean computeTimestampLo = appendPartition == null;
appendPartition = getAppendPartition(timestamp);
Interval interval = appendPartition.getInterval();
if (interval == null) {
appendTimestampHi = Long.MAX_VALUE;
} else {
appendTimestampHi = interval.getHi();
}
if (computeTimestampLo) {
FixedColumn column = appendPartition.getTimestampColumn();
long sz;
if ((sz = column.size()) > 0) {
appendTimestampLo = column.getLong(sz - 1);
}
} else {
appendTimestampLo = appendPartition.getInterval().getLo();
}
}
use of com.questdb.std.time.Interval in project questdb by bluestreak01.
the class JournalWriter method getAppendPartition.
public Partition<T> getAppendPartition(long timestamp) throws JournalException {
int sz = partitions.size();
if (sz > 0) {
Partition<T> par = partitions.getQuick(sz - 1);
Interval interval = par.getInterval();
if (interval == null || interval.contains(timestamp)) {
return par.open().access();
} else if (interval.isBefore(timestamp)) {
return createPartition(new Interval(timestamp, getMetadata().getPartitionBy()), sz);
} else {
throw new JournalException("%s cannot be appended to %s", Dates.toString(timestamp), this);
}
} else {
return createPartition(new Interval(timestamp, getMetadata().getPartitionBy()), 0);
}
}
use of com.questdb.std.time.Interval in project questdb by bluestreak01.
the class PerformanceTest method testAllBySymbolValueOverInterval.
@Test
public void testAllBySymbolValueOverInterval() throws JournalException, NumericException {
try (JournalWriter<Quote> w = getFactory().writer(Quote.class, null, TEST_DATA_SIZE)) {
TestUtils.generateQuoteData(w, TEST_DATA_SIZE, DateFormatUtils.parseDateTime("2013-10-05T10:00:00.000Z"), 1000);
w.commit();
}
try (Journal<Quote> journal = getFactory().reader(Quote.class)) {
int count = 1000;
Interval interval = new Interval(DateFormatUtils.parseDateTime("2013-10-15T10:00:00.000Z"), DateFormatUtils.parseDateTime("2013-10-05T10:00:00.000Z"));
long t = 0;
QueryAllBuilder<Quote> builder = journal.query().all().withKeys("LLOY.L").slice(interval);
for (int i = -1000; i < count; i++) {
if (i == 0) {
t = System.nanoTime();
}
builder.asResultSet();
}
LOG.info().$("journal.query().all().withKeys(\"LLOY.L\").slice(interval) (query only) latency: ").$((System.nanoTime() - t) / count / 1000).$("μs").$();
}
}
use of com.questdb.std.time.Interval in project questdb by bluestreak01.
the class JournalRecoveryTest method testLagRecovery.
@Test
public void testLagRecovery() throws Exception {
try (JournalWriter<Quote> origin = getFactory().writer(Quote.class, "origin")) {
TestUtils.generateQuoteData(origin, 100000, new Interval("2013-01-01T00:00:00.000Z", "2013-05-30T12:55:00.000Z"));
try (Journal<Quote> r = getFactory().reader(Quote.class, "origin")) {
Assert.assertEquals(100000, r.size());
}
long ts;
try (JournalWriter<Quote> w = getFactory().writer(Quote.class)) {
w.disableCommitOnClose();
w.append(origin.query().all().asResultSet().subset(0, 15000));
w.mergeAppend(origin.query().all().asResultSet().subset(15000, 17000));
w.commit();
ts = w.getMaxTimestamp();
w.mergeAppend(origin.query().all().asResultSet().subset(16000, 27000));
w.mergeAppend(origin.query().all().asResultSet().subset(23000, 37000));
Assert.assertTrue(ts < w.getMaxTimestamp());
Assert.assertEquals(37672, w.size());
}
// make sure journal is closed in pool
getFactory().lock(Quote.class.getName());
getFactory().unlock(Quote.class.getName());
try (Journal<Quote> w = getFactory().reader(Quote.class)) {
Assert.assertEquals(ts, w.getMaxTimestamp());
Assert.assertEquals(17000, w.size());
}
try (JournalWriter<Quote> w = getFactory().writer(Quote.class)) {
Assert.assertEquals(ts, w.getMaxTimestamp());
Assert.assertEquals(17000, w.size());
}
}
}
use of com.questdb.std.time.Interval in project questdb by bluestreak01.
the class JournalRecoveryTest method testRecovery.
@Test
public void testRecovery() throws Exception {
long ts;
try (JournalWriter<Quote> w = getFactory().writer(Quote.class)) {
w.disableCommitOnClose();
Assert.assertFalse(w.isCommitOnClose());
TestUtils.generateQuoteData(w, 10000, new Interval("2013-01-01T00:00:00.000Z", "2013-02-28T12:55:00.000Z"));
ts = w.getMaxTimestamp();
TestUtils.generateQuoteData(w, 10000, new Interval("2013-03-01T00:00:00.000Z", "2013-05-30T12:55:00.000Z"), false);
Assert.assertTrue(w.getMaxTimestamp() > ts);
}
// make sure journal is closed in pool
getFactory().lock(Quote.class.getName());
getFactory().unlock(Quote.class.getName());
try (Journal<Quote> w = getFactory().reader(Quote.class)) {
Assert.assertEquals(ts, w.getMaxTimestamp());
Assert.assertEquals(10000, w.size());
}
try (JournalWriter<Quote> w = getFactory().writer(Quote.class)) {
w.disableCommitOnClose();
Assert.assertEquals(ts, w.getMaxTimestamp());
Assert.assertEquals(10000, w.size());
}
}
Aggregations