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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations