use of org.voltcore.messaging.VoltMessage in project voltdb by VoltDB.
the class TestRepairLog method testOfferWithTruncation.
@Test
public void testOfferWithTruncation() {
final AtomicLong lastCommitted = new AtomicLong(Long.MIN_VALUE);
final TransactionCommitInterest interest = lastCommitted::set;
RepairLog rl = new RepairLog();
rl.registerTransactionCommitInterest(interest);
// add m1
VoltMessage m1 = truncInitMsg(0L, 1L);
rl.deliver(m1);
assertEquals(2, rl.contents(1L, false).size());
assertEquals(0, lastCommitted.get());
// add m2
VoltMessage m2 = truncInitMsg(0L, 2L);
rl.deliver(m2);
assertEquals(3, rl.contents(1L, false).size());
assertEquals(0, lastCommitted.get());
// trim m1. add m3
VoltMessage m3 = truncInitMsg(1L, 3L);
rl.deliver(m3);
assertEquals(3, rl.contents(1L, false).size());
assertEquals(m2, rl.contents(1L, false).get(1).getPayload());
assertEquals(2L, rl.contents(1L, false).get(1).getHandle());
assertEquals(m3, rl.contents(1L, false).get(2).getPayload());
assertEquals(3L, rl.contents(1L, false).get(2).getHandle());
assertEquals(1, lastCommitted.get());
}
use of org.voltcore.messaging.VoltMessage in project voltdb by VoltDB.
the class TestRepairLog method testOffer.
@Test
public void testOffer() {
final AtomicLong lastCommitted = new AtomicLong(Long.MIN_VALUE);
final TransactionCommitInterest interest = lastCommitted::set;
// offer some various messages to log and check
// that it keeps the expected ones.
RepairLog rl = new RepairLog();
rl.registerTransactionCommitInterest(interest);
VoltMessage m1 = nonTruncInitMsg();
VoltMessage m2 = nonTruncInitMsg();
rl.deliver(m1);
rl.deliver(m2);
List<Iv2RepairLogResponseMessage> contents = rl.contents(1l, false);
assertEquals(3, contents.size());
assertEquals(m1, contents.get(1).getPayload());
assertEquals(m2, contents.get(2).getPayload());
assertEquals(Long.MIN_VALUE, lastCommitted.get());
}
use of org.voltcore.messaging.VoltMessage in project voltdb by VoltDB.
the class MiniMailbox method send.
@Override
public void send(long hsId, VoltMessage message) {
message.m_sourceHSId = m_HSId;
m_sendQ.offer(new Message(m_HSId, hsId, message));
}
use of org.voltcore.messaging.VoltMessage in project voltdb by VoltDB.
the class MiniMailbox method recvBlocking.
@Override
public synchronized VoltMessage recvBlocking(Subject[] subjects, long timeout) {
VoltMessage message = null;
for (Subject s : subjects) {
final Deque<VoltMessage> dq = m_messages.get(s.getId());
message = dq.poll();
if (message != null) {
return message;
}
}
try {
this.wait(timeout);
} catch (InterruptedException e) {
return null;
}
for (Subject s : subjects) {
final Deque<VoltMessage> dq = m_messages.get(s.getId());
message = dq.poll();
if (message != null) {
return message;
}
}
return null;
}
use of org.voltcore.messaging.VoltMessage in project voltdb by VoltDB.
the class MiniNode method run.
@Override
public void run() {
m_miniSite.start();
for (long HSId : m_HSIds) {
// Don't track your own death
if (HSId != m_HSId) {
m_deadTracker.startTracking(HSId);
}
}
m_nodeState.set(NodeState.RUN);
while (m_shouldContinue.get()) {
Message msg = m_recvQ.poll();
synchronized (this) {
if (msg != null) {
if (msg.m_close) {
int failedHostId = CoreUtils.getHostIdFromHSId(msg.m_src);
long agreementHSId = CoreUtils.getHSIdFromHostAndSite(failedHostId, HostMessenger.AGREEMENT_SITE_ID);
m_miniSite.reportFault(agreementHSId);
m_deadTracker.stopTracking(msg.m_src);
} else {
m_deadTracker.updateHSId(msg.m_src);
// inject actual message into mailbox
VoltMessage message = msg.m_msg;
// snoop for SiteFailureMessage, inject into MiniSite's mailbox
if (message instanceof SiteFailureMessage && !(message instanceof SiteFailureForwardMessage)) {
SiteFailureMessage sfm = (SiteFailureMessage) message;
for (FaultMessage fm : sfm.asFaultMessages()) {
m_miniSite.reportFault(fm);
}
}
m_mailbox.deliver(message);
}
}
// Do dead host detection. Need to keep track of receive gaps from the remaining set
// of live hosts.
Set<Long> deadHosts = m_deadTracker.checkTimeouts();
for (long HSId : deadHosts) {
int failedHostId = CoreUtils.getHostIdFromHSId(HSId);
long agreementHSId = CoreUtils.getHSIdFromHostAndSite(failedHostId, HostMessenger.AGREEMENT_SITE_ID);
m_miniSite.reportFault(agreementHSId);
m_deadTracker.stopTracking(HSId);
}
}
}
}
Aggregations