Search in sources :

Example 11 with JournalWriter

use of com.questdb.store.JournalWriter in project questdb by bluestreak01.

the class CachingWriterFactory method createWriter.

@SuppressWarnings("unchecked")
private <T> JournalWriter<T> createWriter(long thread, String name, Entry e, JournalMetadata<T> metadata) throws JournalException {
    try {
        JournalMetadata<T> mo = getConfiguration().readMetadata(metadata.getName());
        if (mo != null && !mo.isCompatible(metadata, false)) {
            throw new JournalMetadataException(mo, metadata);
        }
        if (closed) {
            throw FactoryClosedException.INSTANCE;
        }
        JournalWriter<T> w = new JournalWriter<>(metadata, new File(getConfiguration().getJournalBase(), name));
        w.setCloseInterceptor(this);
        LOG.info().$("Writer '").$(name).$("' is allocated by thread ").$(e.owner).$();
        e.writer = w;
        notifyListener(thread, name, FactoryEventListener.EV_CREATE);
        return w;
    } catch (JournalException ex) {
        LOG.error().$("Failed to allocate writer '").$(name).$("' in thread ").$(e.owner).$(": ").$(ex).$();
        e.ex = ex;
        notifyListener(thread, name, FactoryEventListener.EV_CREATE_EX);
        throw ex;
    }
}
Also used : JournalWriter(com.questdb.store.JournalWriter) JournalException(com.questdb.std.ex.JournalException) File(java.io.File)

Example 12 with JournalWriter

use of com.questdb.store.JournalWriter in project questdb by bluestreak01.

the class CachingWriterFactory method closeWriter.

private void closeWriter(long thread, Entry e, short ev, short evex, int reason) {
    JournalWriter w = e.writer;
    if (w != null) {
        String name = e.writer.getName();
        w.setCloseInterceptor(null);
        try {
            w.close();
            e.writer = null;
            LOG.info().$("Closed writer '").$(name).$('\'').$(PoolConstants.closeReasonText(reason)).$();
            notifyListener(thread, name, ev);
        } catch (Throwable e1) {
            notifyListener(thread, name, evex);
            LOG.error().$("Cannot close writer '").$(w.getName()).$("': ").$(e1.getMessage()).$();
        }
    }
}
Also used : JournalWriter(com.questdb.store.JournalWriter)

Example 13 with JournalWriter

use of com.questdb.store.JournalWriter in project questdb by bluestreak01.

the class GenericAppendPerfTest method testAppend.

@Test
public void testAppend() throws Exception {
    try (JournalWriter wg = getFactory().writer(new JournalStructure("qq") {

        {
            $sym("sym").index().buckets(20);
            $double("bid");
            $double("ask");
            $int("bidSize");
            $int("askSize");
            $sym("ex").buckets(1);
            $sym("mode").buckets(1);
            recordCountHint(TEST_DATA_SIZE);
        }
    })) {
        long t = System.nanoTime();
        TestUtils.generateQuoteDataGeneric(wg, TEST_DATA_SIZE, DateFormatUtils.parseDateTime("2013-10-05T10:00:00.000Z"), 1000);
        wg.commit();
        long result = System.nanoTime() - t;
        LOG.info().$("generic append (1M): ").$(TimeUnit.NANOSECONDS.toMillis(result) / 2).$("ms").$();
    }
}
Also used : JournalWriter(com.questdb.store.JournalWriter) JournalStructure(com.questdb.store.factory.configuration.JournalStructure) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 14 with JournalWriter

use of com.questdb.store.JournalWriter in project questdb by bluestreak01.

the class GenericBinaryTest method testOutputOutput.

@Test
public void testOutputOutput() throws Exception {
    try (JournalWriter writer = getGenericWriter()) {
        List<byte[]> expected = getBytes();
        writeOutputStream(writer, expected);
        assertEquals(expected, readOutputStream());
    }
}
Also used : JournalWriter(com.questdb.store.JournalWriter) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 15 with JournalWriter

use of com.questdb.store.JournalWriter in project questdb by bluestreak01.

the class GenericInteropTest method testObjectGenericObjectWriteSequence.

@Test
public void testObjectGenericObjectWriteSequence() throws Exception {
    JournalWriter<Data> writer = getFactory().writer(new JournalMetadataBuilder<Data>(Data.class, "test") {

        {
            $date("created");
            $sym("sym").index();
            $int("id").index();
            $str("rateId").index();
        }
    });
    Data d = new Data();
    d.sym = "GBPUSD";
    d.created = 30000;
    d.bid = 0.65;
    d.ask = 0.66;
    d.bidSize = 1000;
    d.askSize = 1100;
    d.id = 1;
    d.status = "OK";
    d.user = "system";
    d.rateId = "GBPUSD:GLOBAL";
    d.active = true;
    d.nullable = null;
    d.ticks = 12345678;
    d.modulo = 425;
    writer.append(d);
    writer.commit();
    writer.close();
    try (JournalWriter writer2 = makeGenericWriter()) {
        JournalEntryWriter w = writer2.entryWriter();
        w.putSym(0, "EURUSD");
        w.putDate(1, 19999);
        w.putDouble(2, 1.24);
        w.putDouble(3, 1.25);
        w.putInt(4, 10000);
        w.putInt(5, 12000);
        w.putInt(6, 2);
        w.putStr(7, "OK");
        w.putStr(8, "system");
        w.putStr(9, "EURUSD:GLOBAL");
        w.putBool(10, true);
        w.putNull(11);
        w.putLong(12, 1234567);
        w.putShort(13, (short) 11000);
        w.append();
        writer2.commit();
    }
    writer = getFactory().writer(Data.class, "test");
    d.sym = "HKDUSD";
    d.created = 40000;
    d.bid = 2.88;
    d.ask = 2.89;
    d.bidSize = 1000;
    d.askSize = 1100;
    d.id = 3;
    d.status = "OK";
    d.user = "system";
    d.rateId = "HKDUSD:GLOBAL";
    d.active = true;
    d.nullable = null;
    d.ticks = 989931;
    d.modulo = 398;
    writer.append(d);
    writer.commit();
    try (Journal<Data> reader = getFactory().reader(Data.class, "test")) {
        String expected = "Data{sym='GBPUSD', created=30000, bid=0.65, ask=0.66, bidSize=1000, askSize=1100, id=1, status='OK', user='system', rateId='GBPUSD:GLOBAL', active=true, nullable='null', ticks=12345678, modulo=425}\n" + "Data{sym='EURUSD', created=19999, bid=1.24, ask=1.25, bidSize=10000, askSize=12000, id=2, status='OK', user='system', rateId='EURUSD:GLOBAL', active=true, nullable='null', ticks=1234567, modulo=11000}\n" + "Data{sym='HKDUSD', created=40000, bid=2.88, ask=2.89, bidSize=1000, askSize=1100, id=3, status='OK', user='system', rateId='HKDUSD:GLOBAL', active=true, nullable='null', ticks=989931, modulo=398}\n";
        StringBuilder builder = new StringBuilder();
        for (Data data : JournalIterators.bufferedIterator(reader)) {
            builder.append(data).append('\n');
        }
        TestUtils.assertEquals(expected, builder);
    }
    writer.close();
}
Also used : JournalWriter(com.questdb.store.JournalWriter) JournalEntryWriter(com.questdb.store.JournalEntryWriter) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Aggregations

JournalWriter (com.questdb.store.JournalWriter)93 JournalStructure (com.questdb.store.factory.configuration.JournalStructure)60 JournalEntryWriter (com.questdb.store.JournalEntryWriter)59 AbstractTest (com.questdb.test.tools.AbstractTest)54 Test (org.junit.Test)52 Rnd (com.questdb.std.Rnd)42 BeforeClass (org.junit.BeforeClass)12 CountDownLatch (java.util.concurrent.CountDownLatch)9 RecordCursor (com.questdb.common.RecordCursor)6 JournalException (com.questdb.std.ex.JournalException)6 Record (com.questdb.common.Record)5 RecordSource (com.questdb.ql.RecordSource)5 Factory (com.questdb.store.factory.Factory)5 BootstrapEnv (com.questdb.BootstrapEnv)4 ServerConfiguration (com.questdb.ServerConfiguration)4 JournalLockedException (com.questdb.ex.JournalLockedException)4 ClientConfig (com.questdb.net.ha.config.ClientConfig)4 ServerConfig (com.questdb.net.ha.config.ServerConfig)4 ServerNode (com.questdb.net.ha.config.ServerNode)4 StringSink (com.questdb.std.str.StringSink)4