use of com.questdb.net.ha.comsumer.HugeBufferConsumer in project questdb by bluestreak01.
the class JournalServerAgentTest method setUp.
@Before
public void setUp() throws Exception {
channel = new MockByteChannel();
quoteWriter = getFactory().writer(Quote.class);
tradeWriter = getFactory().writer(Trade.class);
ServerConfig config = new ServerConfig() {
{
setHeartbeatFrequency(100);
setEnableMultiCast(false);
}
};
server = new JournalServer(config, getFactory());
server.publish(quoteWriter);
agent = new JournalServerAgent(server, new InetSocketAddress(NetworkConfig.DEFAULT_DATA_PORT), null);
hugeBufferConsumer = new HugeBufferConsumer(temp.newFile());
}
use of com.questdb.net.ha.comsumer.HugeBufferConsumer in project questdb by bluestreak01.
the class MetadataReplicationTest method testReplication.
@Test
public void testReplication() {
try (JournalWriter w = getFactory().writer(Quote.class)) {
MockByteChannel channel = new MockByteChannel();
HugeBufferProducer p = new HugeBufferProducer(new File(w.getLocation(), JournalConfiguration.FILE_NAME));
HugeBufferConsumer c = new HugeBufferConsumer(new File(w.getLocation(), "_remote"));
p.write(channel);
c.read(channel);
try (JournalWriter w2 = getFactory().writer(new JournalMetadata<>(c.getHb(), "xyz"))) {
Assert.assertTrue(w.getMetadata().isCompatible(w2.getMetadata(), false));
}
p.free();
c.free();
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.questdb.net.ha.comsumer.HugeBufferConsumer in project questdb by bluestreak01.
the class JournalClient method subscribeOne.
private void subscribeOne(int index, SubscriptionHolder holder, String name, boolean newSubscription) {
if (newSubscription) {
SubscriptionHolder sub = new SubscriptionHolder();
sub.local = holder.local;
sub.remote = holder.remote;
sub.listener = holder.listener;
sub.writer = holder.writer;
subscriptions.add(sub);
}
JournalWriter<?> writer = writers.getQuiet(index);
try {
commandProducer.write(channel, Command.ADD_KEY_CMD);
setKeyRequestProducer.write(channel, new IndexedJournalKey(index, holder.remote));
checkAck();
// todo: do we really have to use file here?
JournalMetadata<?> metadata;
File file = Files.makeTempFile();
try {
try (HugeBufferConsumer h = new HugeBufferConsumer(file)) {
h.read(channel);
metadata = new JournalMetadata(h.getHb(), name);
} catch (JournalException e) {
throw new JournalNetworkException(e);
}
} finally {
Files.delete(file);
}
boolean validate = true;
if (writer == null) {
if (holder.writer == null) {
try {
writer = factory.writer(metadata);
} catch (JournalException e) {
LOG.error().$("Failed to create writer: ").$(e).$();
unsubscribe(index, null, holder, JournalEvents.EVT_JNL_INCOMPATIBLE);
return;
}
writersToClose.add(writer);
validate = false;
} else {
writer = holder.writer;
}
writer.disableCommitOnClose();
statusSentList.extendAndSet(index, 0);
deltaConsumers.extendAndSet(index, new JournalDeltaConsumer(writer));
writers.extendAndSet(index, writer);
writer.setJournalListener(holder.listener);
} else {
statusSentList.setQuick(index, 0);
}
if (validate && !metadata.isCompatible(writer.getMetadata(), false)) {
LOG.error().$("Journal ").$(holder.local.getName()).$(" is not compatible with ").$(holder.remote.getName()).$("(remote)").$();
unsubscribe(index, writer, holder, JournalEvents.EVT_JNL_INCOMPATIBLE);
return;
}
commandProducer.write(channel, Command.DELTA_REQUEST_CMD);
journalClientStateProducer.write(channel, new IndexedJournal(index, writer));
checkAck();
statusSentList.setQuick(index, 1);
if (holder.listener != null) {
holder.listener.onEvent(JournalEvents.EVT_JNL_SUBSCRIBED);
}
LOG.info().$("Subscribed ").$(name).$(" to ").$(holder.remote.getName()).$("(remote)").$();
} catch (JournalNetworkException e) {
LOG.error().$("Failed to subscribe ").$(name).$(" to ").$(holder.remote.getName()).$("(remote)").$();
unsubscribe(index, writer, holder, JournalEvents.EVT_JNL_SERVER_ERROR);
}
}
Aggregations