Search in sources :

Example 21 with VoltMessage

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());
}
Also used : VoltMessage(org.voltcore.messaging.VoltMessage) AtomicLong(java.util.concurrent.atomic.AtomicLong) Test(org.junit.Test)

Example 22 with VoltMessage

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());
}
Also used : VoltMessage(org.voltcore.messaging.VoltMessage) Iv2RepairLogResponseMessage(org.voltdb.messaging.Iv2RepairLogResponseMessage) AtomicLong(java.util.concurrent.atomic.AtomicLong) Test(org.junit.Test)

Example 23 with VoltMessage

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));
}
Also used : VoltMessage(org.voltcore.messaging.VoltMessage) Message(org.voltcore.agreement.FakeMesh.Message)

Example 24 with VoltMessage

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;
}
Also used : VoltMessage(org.voltcore.messaging.VoltMessage) Subject(org.voltcore.messaging.Subject)

Example 25 with VoltMessage

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);
            }
        }
    }
}
Also used : VoltMessage(org.voltcore.messaging.VoltMessage) FaultMessage(org.voltcore.messaging.FaultMessage) SiteFailureForwardMessage(org.voltcore.messaging.SiteFailureForwardMessage) FaultMessage(org.voltcore.messaging.FaultMessage) VoltMessage(org.voltcore.messaging.VoltMessage) SiteFailureMessage(org.voltcore.messaging.SiteFailureMessage) Message(org.voltcore.agreement.FakeMesh.Message) SiteFailureForwardMessage(org.voltcore.messaging.SiteFailureForwardMessage) SiteFailureMessage(org.voltcore.messaging.SiteFailureMessage)

Aggregations

VoltMessage (org.voltcore.messaging.VoltMessage)31 Test (org.junit.Test)8 AtomicLong (java.util.concurrent.atomic.AtomicLong)5 FaultMessage (org.voltcore.messaging.FaultMessage)4 SiteFailureMessage (org.voltcore.messaging.SiteFailureMessage)4 Subject (org.voltcore.messaging.Subject)4 ByteBuffer (java.nio.ByteBuffer)3 ArrayList (java.util.ArrayList)3 Iv2RepairLogResponseMessage (org.voltdb.messaging.Iv2RepairLogResponseMessage)3 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 LinkedList (java.util.LinkedList)2 Map (java.util.Map)2 Message (org.voltcore.agreement.FakeMesh.Message)2 SiteFailureForwardMessage (org.voltcore.messaging.SiteFailureForwardMessage)2 InitiateResponseMessage (org.voltdb.messaging.InitiateResponseMessage)2 LocalMailbox (org.voltdb.messaging.LocalMailbox)2 ImmutableList (com.google_voltpatches.common.collect.ImmutableList)1 ImmutableMap (com.google_voltpatches.common.collect.ImmutableMap)1 List (java.util.List)1