Search in sources :

Example 6 with JournalNetworkException

use of com.questdb.std.ex.JournalNetworkException in project questdb by bluestreak01.

the class JournalDeltaConsumer method doRead.

@Override
@SuppressWarnings("unchecked")
protected void doRead(ReadableByteChannel channel) throws JournalNetworkException {
    try {
        reset();
        journalServerStateConsumer.read(channel);
        this.state = journalServerStateConsumer.getValue();
        if (state.getTxn() == -1) {
            journal.notifyListener(JournalEvents.EVT_JNL_TRANSACTION_REFUSED);
            throw new IncompatibleJournalException("Server refused txn for %s", journal.getLocation());
        }
        if (state.getTxn() < journal.getTxn()) {
            journal.rollback(state.getTxn(), state.getTxPin());
            return;
        }
        journal.beginTx();
        createPartitions(state);
        if (state.isSymbolTables()) {
            journalSymbolTableConsumer.read(channel);
        }
        for (int i = 0, k = state.getNonLagPartitionCount(); i < k; i++) {
            JournalServerState.PartitionMetadata meta = state.getMeta(i);
            if (meta.getEmpty() == 0) {
                PartitionDeltaConsumer partitionDeltaConsumer = getPartitionDeltaConsumer(meta.getPartitionIndex());
                partitionDeltaConsumer.read(channel);
            }
        }
        if (state.getLagPartitionName() == null && journal.hasIrregularPartition()) {
            // delete lag partition
            journal.removeIrregularPartition();
        } else if (state.getLagPartitionName() != null) {
            if (lagPartitionDeltaConsumer == null || !journal.hasIrregularPartition() || !state.getLagPartitionName().equals(journal.getIrregularPartition().getName())) {
                Partition temp = journal.createTempPartition(state.getLagPartitionName());
                lagPartitionDeltaConsumer = new PartitionDeltaConsumer(temp.open());
                journal.setIrregularPartition(temp);
            }
            lagPartitionDeltaConsumer.read(channel);
        }
    } catch (JournalException e) {
        throw new JournalNetworkException(e);
    }
}
Also used : Partition(com.questdb.store.Partition) JournalException(com.questdb.std.ex.JournalException) IncompatibleJournalException(com.questdb.ex.IncompatibleJournalException) JournalNetworkException(com.questdb.std.ex.JournalNetworkException) JournalServerState(com.questdb.net.ha.model.JournalServerState) IncompatibleJournalException(com.questdb.ex.IncompatibleJournalException)

Example 7 with JournalNetworkException

use of com.questdb.std.ex.JournalNetworkException in project questdb by bluestreak01.

the class NetworkConfig method findExternalNic.

NetworkInterface findExternalNic() throws JournalNetworkException {
    if (defaultInterface != null) {
        return defaultInterface;
    }
    try {
        Enumeration<NetworkInterface> ifs = NetworkInterface.getNetworkInterfaces();
        int index = Integer.MAX_VALUE;
        while (ifs.hasMoreElements()) {
            NetworkInterface q = ifs.nextElement();
            if (!q.isLoopback() && q.isUp() && q.getIndex() < index) {
                defaultInterface = q;
                index = q.getIndex();
            }
        }
        if (defaultInterface == null) {
            throw new JournalNetworkException("Could not find multicast-capable network interfaces");
        }
        return defaultInterface;
    } catch (SocketException e) {
        throw new JournalNetworkException(e);
    }
}
Also used : JournalNetworkException(com.questdb.std.ex.JournalNetworkException)

Example 8 with JournalNetworkException

use of com.questdb.std.ex.JournalNetworkException in project questdb by bluestreak01.

the class NetworkConfig method openDatagramChannel.

DatagramChannelWrapper openDatagramChannel(NetworkInterface ifn) throws JournalNetworkException {
    InetAddress address = getMultiCastAddress();
    if (address == null) {
        address = getDefaultMultiCastAddress(ifn);
    }
    ProtocolFamily family = NetworkConfig.isInet6(address) ? StandardProtocolFamily.INET6 : StandardProtocolFamily.INET;
    try {
        DatagramChannel dc = DatagramChannel.open(family).setOption(StandardSocketOptions.SO_REUSEADDR, Boolean.TRUE).setOption(StandardSocketOptions.IP_MULTICAST_IF, ifn).bind(new InetSocketAddress(getMultiCastPort()));
        dc.join(address, ifn);
        return new DatagramChannelWrapper(dc, new InetSocketAddress(address, getMultiCastPort()));
    } catch (IOException e) {
        throw new JournalNetworkException(e);
    }
}
Also used : JournalNetworkException(com.questdb.std.ex.JournalNetworkException) DatagramChannel(java.nio.channels.DatagramChannel) IOException(java.io.IOException)

Example 9 with JournalNetworkException

use of com.questdb.std.ex.JournalNetworkException in project questdb by bluestreak01.

the class ServerConfig method openServerSocketChannel.

public ServerSocketChannel openServerSocketChannel(int instance) throws JournalNetworkException {
    InetSocketAddress address = null;
    try {
        address = getSocketAddress(instance);
        ServerSocketChannel channel = ServerSocketChannel.open().bind(address).setOption(StandardSocketOptions.SO_RCVBUF, getSoRcvBuf());
        LOG.info().$("Server is now listening on ").$(address).$();
        return channel;
    } catch (IOException e) {
        throw new JournalNetworkException("Cannot open server socket [" + address + ']', e);
    }
}
Also used : JournalNetworkException(com.questdb.std.ex.JournalNetworkException) IOException(java.io.IOException) ServerSocketChannel(java.nio.channels.ServerSocketChannel)

Example 10 with JournalNetworkException

use of com.questdb.std.ex.JournalNetworkException in project questdb by bluestreak01.

the class AbstractOnDemandPoller method poll.

public T poll(int retryCount, long timeout, TimeUnit timeUnit) throws JournalNetworkException {
    try (DatagramChannelWrapper dcw = networkConfig.openDatagramChannel()) {
        DatagramChannel dc = dcw.getChannel();
        LOG.info().$("Polling on").$(dcw.getGroup()).$(" [").$(dc.getOption(StandardSocketOptions.IP_MULTICAST_IF).getName()).$(']').$();
        Selector selector = Selector.open();
        dc.configureBlocking(false);
        dc.register(selector, SelectionKey.OP_READ);
        // print out each datagram that we receive
        ByteBuffer buf = ByteBuffer.allocateDirect(4096);
        try {
            int count = retryCount;
            InetSocketAddress sa = null;
            while (count > 0 && (sa = poll0(dc, dcw.getGroup(), selector, buf, timeUnit.toMillis(timeout))) == null) {
                buf.clear();
                count--;
            }
            if (count == 0) {
                throw new JournalNetworkException("Cannot find QuestDB servers on network");
            }
            return transform(buf, sa);
        } finally {
            ByteBuffers.release(buf);
        }
    } catch (IOException e) {
        throw new JournalNetworkException(e);
    }
}
Also used : DatagramChannelWrapper(com.questdb.net.ha.config.DatagramChannelWrapper) InetSocketAddress(java.net.InetSocketAddress) JournalNetworkException(com.questdb.std.ex.JournalNetworkException) DatagramChannel(java.nio.channels.DatagramChannel) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer) Selector(java.nio.channels.Selector)

Aggregations

JournalNetworkException (com.questdb.std.ex.JournalNetworkException)11 IOException (java.io.IOException)7 IncompatibleJournalException (com.questdb.ex.IncompatibleJournalException)2 JournalDeltaConsumer (com.questdb.net.ha.comsumer.JournalDeltaConsumer)2 IndexedJournalKey (com.questdb.net.ha.model.IndexedJournalKey)2 JournalException (com.questdb.std.ex.JournalException)2 DatagramChannel (java.nio.channels.DatagramChannel)2 SecureSocketChannel (com.questdb.net.SecureSocketChannel)1 SslConfig (com.questdb.net.SslConfig)1 StatsCollectingReadableByteChannel (com.questdb.net.StatsCollectingReadableByteChannel)1 HugeBufferConsumer (com.questdb.net.ha.comsumer.HugeBufferConsumer)1 DatagramChannelWrapper (com.questdb.net.ha.config.DatagramChannelWrapper)1 IndexedJournal (com.questdb.net.ha.model.IndexedJournal)1 JournalServerState (com.questdb.net.ha.model.JournalServerState)1 Partition (com.questdb.store.Partition)1 JournalMetadata (com.questdb.store.factory.configuration.JournalMetadata)1 File (java.io.File)1 InetSocketAddress (java.net.InetSocketAddress)1 ByteBuffer (java.nio.ByteBuffer)1 Selector (java.nio.channels.Selector)1