Search in sources :

Example 1 with JournalRuntimeException

use of com.questdb.common.JournalRuntimeException in project questdb by bluestreak01.

the class ReconnectTest method testServerRestart.

@Test
@Ignore
public void testServerRestart() throws Exception {
    final int size = 10000;
    try (JournalWriter<Quote> remote = getFactory().writer(Quote.class, "remote", 2 * size)) {
        // start server #1
        JournalServer server = newServer();
        server.publish(remote);
        server.start();
        final CountDownLatch connectedLatch = new CountDownLatch(1);
        JournalClient client = new JournalClient(new ClientConfig("localhost") {

            {
                getReconnectPolicy().setLoginRetryCount(3);
                getReconnectPolicy().setRetryCount(5);
                getReconnectPolicy().setSleepBetweenRetriesMillis(TimeUnit.SECONDS.toMillis(1));
            }
        }, getFactory(), null, evt -> {
            if (evt == JournalClientEvents.EVT_CONNECTED) {
                connectedLatch.countDown();
            }
        });
        // subscribe client, waiting for complete set of data
        // when data arrives client triggers latch
        final CountDownLatch latch = new CountDownLatch(1);
        // create empty "local"
        getFactory().writer(Quote.class, "local").close();
        try (final Journal<Quote> local = getFactory().reader(Quote.class, "local")) {
            client.subscribe(Quote.class, "remote", "local", 2 * size, new JournalListener() {

                @Override
                public void onCommit() {
                    try {
                        if (local.refresh() && local.size() == 2 * size) {
                            latch.countDown();
                        }
                    } catch (JournalException e) {
                        throw new JournalRuntimeException(e);
                    }
                }

                @Override
                public void onEvent(int event) {
                }
            });
            client.start();
            Assert.assertTrue(connectedLatch.await(5, TimeUnit.SECONDS));
            // generate first batch
            TestUtils.generateQuoteData(remote, size, System.currentTimeMillis(), 1);
            remote.commit();
            // stop server
            server.halt();
            // start server #2
            server = newServer();
            server.publish(remote);
            server.start();
            // generate second batch
            TestUtils.generateQuoteData(remote, size, System.currentTimeMillis() + 2 * size, 1);
            remote.commit();
            // wait for client to get full set
            latch.await();
            // stop client and server
            client.halt();
            server.halt();
            // assert client state
            TestUtils.assertDataEquals(remote, local);
        }
    }
}
Also used : Quote(com.questdb.model.Quote) JournalException(com.questdb.std.ex.JournalException) JournalListener(com.questdb.store.JournalListener) JournalRuntimeException(com.questdb.common.JournalRuntimeException) CountDownLatch(java.util.concurrent.CountDownLatch) ClientConfig(com.questdb.net.ha.config.ClientConfig) Ignore(org.junit.Ignore) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 2 with JournalRuntimeException

use of com.questdb.common.JournalRuntimeException in project questdb by bluestreak01.

the class HttpServer method halt.

public void halt() {
    if (running) {
        running = false;
        try {
            startComplete.await();
            for (int i = 0; i < workers.size(); i++) {
                workers.getQuick(i).halt();
            }
            haltLatch.await();
            dispatcher.close();
        } catch (Exception e) {
            throw new JournalRuntimeException(e);
        }
        for (int i = 0; i < ioQueue.getCapacity(); i++) {
            Event<IOContext> ev = ioQueue.get(i);
            if (ev != null && ev.context != null) {
                ev.context = Misc.free(ev.context);
            }
        }
    }
}
Also used : JournalRuntimeException(com.questdb.common.JournalRuntimeException) JournalRuntimeException(com.questdb.common.JournalRuntimeException)

Example 3 with JournalRuntimeException

use of com.questdb.common.JournalRuntimeException in project questdb by bluestreak01.

the class PlainTextStoringParser method onMetadata.

@Override
public void onMetadata(ObjList<ImportedColumnMetadata> metadata, boolean header) {
    if (writer == null) {
        this.metadata = metadata;
        this.header = header;
        try {
            switch(factory.getConfiguration().exists(name)) {
                case DOES_NOT_EXIST:
                    writer = factory.writer(createStructure());
                    break;
                case EXISTS:
                    if (overwrite) {
                        factory.delete(name);
                        writer = factory.writer(createStructure());
                    } else {
                        writer = mapColumnsAndOpenWriter();
                    }
                    break;
                default:
                    throw ImportNameException.INSTANCE;
            }
            writer.setSequentialAccess(true);
            _size = writer.size();
            errors.seed(writer.getMetadata().getColumnCount(), 0);
        } catch (JournalException e) {
            throw new JournalRuntimeException(e);
        }
    }
}
Also used : JournalException(com.questdb.std.ex.JournalException) JournalRuntimeException(com.questdb.common.JournalRuntimeException)

Example 4 with JournalRuntimeException

use of com.questdb.common.JournalRuntimeException in project questdb by bluestreak01.

the class PlainTextStoringParser method onFields.

@Override
public void onFields(int line, ObjList<DirectByteCharSequence> values, int hi) {
    boolean append = true;
    try {
        JournalEntryWriter w = writer.entryWriter();
        for (int i = 0; i < hi; i++) {
            if (values.getQuick(i).length() == 0) {
                continue;
            }
            try {
                DirectByteCharSequence charField;
                ImportedColumnMetadata m = metadata.getQuick(i);
                switch(m.importedColumnType) {
                    case ColumnType.STRING:
                        utf8Sink.clear();
                        charField = values.getQuick(i);
                        Chars.utf8Decode(charField.getLo(), charField.getHi(), utf8Sink);
                        w.putStr(i, (DirectBytes) utf8Sink);
                        break;
                    case ColumnType.DOUBLE:
                        w.putDouble(i, Numbers.parseDouble(values.getQuick(i)));
                        break;
                    case ColumnType.INT:
                        w.putInt(i, Numbers.parseInt(values.getQuick(i)));
                        break;
                    case ColumnType.FLOAT:
                        w.putFloat(i, Numbers.parseFloat(values.getQuick(i)));
                        break;
                    case ColumnType.DATE:
                        if (m.dateFormat != null && m.dateLocale != null) {
                            w.putDate(i, m.dateFormat.parse(values.getQuick(i), m.dateLocale));
                        } else {
                            throw NumericException.INSTANCE;
                        }
                        break;
                    case ColumnType.SYMBOL:
                        utf8Sink.clear();
                        charField = values.getQuick(i);
                        Chars.utf8Decode(charField.getLo(), charField.getHi(), utf8Sink);
                        w.putSym(i, utf8Sink);
                        break;
                    case ColumnType.LONG:
                        w.putLong(i, Numbers.parseLong(values.getQuick(i)));
                        break;
                    case ColumnType.BOOLEAN:
                        w.putBool(i, Chars.equalsIgnoreCase(values.getQuick(i), "true"));
                        break;
                    default:
                        break;
                }
            } catch (Exception e) {
                switch(atomicity) {
                    case ATOMICITY_STRICT:
                        LOG.info().$("Error at (").$(line).$(',').$(i).$(')').$();
                        throw new JournalRuntimeException("Error on line: " + line + ", col: " + i);
                    default:
                        errors.increment(i);
                        LOG.debug().$("Error at (").$(line).$(',').$(i).$(") as ").$(metadata.getQuick(i).importedColumnType).$(": ").$(e.getMessage()).$();
                        append = false;
                }
                break;
            }
        }
        if (append) {
            w.append();
        }
    } catch (JournalException e) {
        throw new JournalRuntimeException(e);
    }
}
Also used : ImportedColumnMetadata(com.questdb.parser.ImportedColumnMetadata) JournalException(com.questdb.std.ex.JournalException) DirectByteCharSequence(com.questdb.std.str.DirectByteCharSequence) JournalRuntimeException(com.questdb.common.JournalRuntimeException) JournalEntryWriter(com.questdb.store.JournalEntryWriter) ImportColumnCountException(com.questdb.ex.ImportColumnCountException) JournalException(com.questdb.std.ex.JournalException) NumericException(com.questdb.common.NumericException) JournalRuntimeException(com.questdb.common.JournalRuntimeException) ImportNameException(com.questdb.ex.ImportNameException)

Example 5 with JournalRuntimeException

use of com.questdb.common.JournalRuntimeException in project questdb by bluestreak01.

the class AbstractOnDemandSender method halt.

public void halt() {
    if (running) {
        while (!selecting) {
            Thread.yield();
        }
        selector.wakeup();
        running = false;
        try {
            latch.await();
        } catch (InterruptedException e) {
            throw new JournalRuntimeException(e);
        }
    }
}
Also used : JournalRuntimeException(com.questdb.common.JournalRuntimeException)

Aggregations

JournalRuntimeException (com.questdb.common.JournalRuntimeException)41 JournalException (com.questdb.std.ex.JournalException)30 KVIndex (com.questdb.store.KVIndex)9 IOException (java.io.IOException)6 IndexCursor (com.questdb.store.IndexCursor)5 Partition (com.questdb.store.Partition)5 ObjList (com.questdb.std.ObjList)4 FixedColumn (com.questdb.store.FixedColumn)2 File (java.io.File)2 MappedByteBuffer (java.nio.MappedByteBuffer)2 BootstrapEnv (com.questdb.BootstrapEnv)1 ServerConfiguration (com.questdb.ServerConfiguration)1 NumericException (com.questdb.common.NumericException)1 ImportColumnCountException (com.questdb.ex.ImportColumnCountException)1 ImportNameException (com.questdb.ex.ImportNameException)1 IncompatibleJournalException (com.questdb.ex.IncompatibleJournalException)1 JournalIOException (com.questdb.ex.JournalIOException)1 Quote (com.questdb.model.Quote)1 ClientConfig (com.questdb.net.ha.config.ClientConfig)1 ImportedColumnMetadata (com.questdb.parser.ImportedColumnMetadata)1