use of org.voltcore.utils.DeferredSerialization in project voltdb by VoltDB.
the class ForeignHost method send.
/** Send a message to the network. This public method is re-entrant. */
void send(final long[] destinations, final VoltMessage message) {
if (!m_isUp) {
hostLog.warn("Failed to send VoltMessage because connection to host " + CoreUtils.getHostIdFromHSId(destinations[0]) + " is closed");
return;
}
if (destinations.length == 0) {
return;
}
// if this link is "gone silent" for partition tests, just drop the message on the floor
if (!m_linkCutForTest.get()) {
m_network.enqueue(new DeferredSerialization() {
@Override
public final void serialize(final ByteBuffer buf) throws IOException {
buf.putInt(buf.capacity() - 4);
buf.putLong(message.m_sourceHSId);
buf.putInt(destinations.length);
for (int ii = 0; ii < destinations.length; ii++) {
buf.putLong(destinations[ii]);
}
message.flattenToBuffer(buf);
buf.flip();
}
@Override
public final void cancel() {
/*
* Can this be removed?
*/
}
@Override
public String toString() {
return message.getClass().getName();
}
@Override
public int getSerializedSize() {
final int len = 4 + /* length prefix */
8 + /* source hsid */
4 + /* destinationCount */
8 * destinations.length + /* destination list */
message.getSerializedSize();
return len;
}
});
}
long current_time = EstTime.currentTimeMillis();
long current_delta = current_time - m_lastMessageMillis.get();
/*
* Try and give some warning when a connection is timing out.
* Allows you to observe the liveness of the host receiving the heartbeats
*/
if (isPrimary() && current_delta > m_logRate) {
rateLimitedLogger.log("Have not received a message from host " + hostnameAndIPAndPort() + " for " + (current_delta / 1000.0) + " seconds", current_time);
}
// avoid repeat reports of a single node failure
if ((!m_closing && m_isUp) && isPrimary() && current_delta > m_deadHostTimeout) {
if (m_deadReportsCount.getAndIncrement() == 0) {
hostLog.error("DEAD HOST DETECTED, hostname: " + hostnameAndIPAndPort());
hostLog.info("\tcurrent time: " + current_time);
hostLog.info("\tlast message: " + m_lastMessageMillis);
hostLog.info("\tdelta (millis): " + current_delta);
hostLog.info("\ttimeout value (millis): " + m_deadHostTimeout);
VoltDB.dropStackTrace("Timed out foreign host " + hostnameAndIPAndPort() + " with delta " + current_delta);
}
m_hostMessenger.reportForeignHostFailed(m_hostId);
}
}
use of org.voltcore.utils.DeferredSerialization in project voltdb by VoltDB.
the class NIOWriteStream method shutdown.
/**
* Free the pool resources that are held by this WriteStream. The pool itself is thread local
* and will be freed when the thread terminates.
*/
@Override
synchronized void shutdown() {
super.shutdown();
DeferredSerialization ds = null;
while ((ds = m_queuedWrites.poll()) != null) {
ds.cancel();
}
}
use of org.voltcore.utils.DeferredSerialization in project voltdb by VoltDB.
the class TestClientInterface method initMsgAndSendRestartResp.
private void initMsgAndSendRestartResp(boolean shouldRestart) throws Exception {
// restart will update the hashinator config, initialize it now
TheHashinator.constructHashinator(TheHashinator.getConfiguredHashinatorClass(), TheHashinator.getConfigureBytes(3), false);
Pair<Long, byte[]> hashinatorConfig = TheHashinator.getCurrentVersionedConfig();
long newHashinatorVersion = hashinatorConfig.getFirst() + 1;
ByteBuffer msg = createMsg("hello", 1);
Iv2InitiateTaskMessage initMsg = readAndCheck(msg, "hello", 1, true, true);
assertEquals(1, initMsg.getStoredProcedureInvocation().getParameterAtIndex(0));
// fake a restart response
InitiateResponseMessage respMsg = new InitiateResponseMessage(initMsg);
respMsg.setMispartitioned(true, initMsg.getStoredProcedureInvocation(), Pair.of(newHashinatorVersion, hashinatorConfig.getSecond()));
// reset the message so that we can check for restart later
reset(m_messenger);
// Deliver a restart response
m_ci.m_mailbox.deliver(respMsg);
// Make sure that the txn is NOT restarted
DeferredSerialization resp = responsesDS.take();
if (shouldRestart) {
assertEquals(-1, resp.getSerializedSize());
checkInitMsgSent("hello", 1, true, true);
} else {
assertTrue(-1 != resp.getSerializedSize());
verify(m_messenger, never()).send(anyLong(), any(VoltMessage.class));
}
// the hashinator should've been updated in either case
assertEquals(newHashinatorVersion, TheHashinator.getCurrentVersionedConfig().getFirst().longValue());
}
use of org.voltcore.utils.DeferredSerialization in project voltdb by VoltDB.
the class TestClientInterface method testSubscribe.
@Test
public void testSubscribe() throws Exception {
RateLimitedClientNotifier.WARMUP_MS = 0;
ClientInterface.TOPOLOGY_CHANGE_CHECK_MS = 1;
try {
m_ci.startAcceptingConnections();
ByteBuffer msg = createMsg("@Subscribe", "TOPOLOGY");
ClientResponseImpl resp = m_ci.handleRead(msg, m_handler, m_cxn);
assertNotNull(resp);
assertEquals(ClientResponse.SUCCESS, resp.getStatus());
statsAnswers.offer(dsOf(getClientResponse("foo")));
m_ci.schedulePeriodicWorks();
//Shouldn't get anything
assertNull(responsesDS.poll(50, TimeUnit.MILLISECONDS));
statsAnswers.offer(dsOf(getClientResponse("foo")));
assertNull(responsesDS.poll(50, TimeUnit.MILLISECONDS));
//Change the bytes of the topology results and expect a topology update
//to make its way to the client
ByteBuffer expectedBuf = getClientResponse("bar");
statsAnswers.offer(dsOf(expectedBuf));
DeferredSerialization ds = responsesDS.take();
ByteBuffer actualBuf = ByteBuffer.allocate(ds.getSerializedSize());
ds.serialize(actualBuf);
assertEquals(expectedBuf, actualBuf);
} finally {
RateLimitedClientNotifier.WARMUP_MS = 1000;
ClientInterface.TOPOLOGY_CHANGE_CHECK_MS = 5000;
m_ci.shutdown();
}
}
use of org.voltcore.utils.DeferredSerialization in project voltdb by VoltDB.
the class TestRateLimitedClientNotifier method testDedupeMultiple2.
/*
* Test that the 2nd notification is skipped, but the third is delivered
*/
@Test
public void testDedupeMultiple2() throws Exception {
ByteBuffer buf = ByteBuffer.allocate(1);
Supplier<DeferredSerialization> sup = getSupplier(buf);
Supplier<DeferredSerialization> sup2 = getSupplier(buf);
Supplier<DeferredSerialization> sup3 = getSupplier(buf);
notifier.queueNotification(ImmutableList.of(cihm), sup, Predicates.<ClientInterfaceHandleManager>alwaysTrue());
notifier.queueNotification(ImmutableList.of(cihm), sup2, Predicates.<ClientInterfaceHandleManager>alwaysTrue());
notifier.queueNotification(ImmutableList.of(cihm), sup, Predicates.<ClientInterfaceHandleManager>alwaysTrue());
notifier.queueNotification(ImmutableList.of(cihm), sup3, Predicates.<ClientInterfaceHandleManager>alwaysTrue());
notifier.start();
messages.take();
messages.take();
messages.take();
assertNull(mws.m_messages.poll(50, TimeUnit.MILLISECONDS));
}
Aggregations