Search in sources :

Example 16 with VoltMessage

use of org.voltcore.messaging.VoltMessage in project voltdb by VoltDB.

the class TestVoltMessageSerialization method checkVoltMessage.

VoltMessage checkVoltMessage(VoltMessage msg) throws IOException {
    ByteBuffer buf1 = ByteBuffer.allocate(msg.getSerializedSize());
    msg.flattenToBuffer(buf1);
    buf1.flip();
    VoltDbMessageFactory vdbmf = new VoltDbMessageFactory();
    VoltMessage msg2 = vdbmf.createMessageFromBuffer(buf1, -1);
    ByteBuffer buf2 = ByteBuffer.allocate(msg2.getSerializedSize());
    msg2.flattenToBuffer(buf2);
    buf1.rewind();
    buf2.rewind();
    assertEquals(buf1.remaining(), buf2.remaining());
    assertTrue(buf1.compareTo(buf2) == 0);
    return msg2;
}
Also used : VoltMessage(org.voltcore.messaging.VoltMessage) ByteBuffer(java.nio.ByteBuffer)

Example 17 with VoltMessage

use of org.voltcore.messaging.VoltMessage in project voltdb by VoltDB.

the class SpScheduler method deliverReadyTxns.

/**
     * Poll the replay sequencer and process the messages until it returns null
     */
private void deliverReadyTxns() {
    // First, pull all the sequenced messages, if any.
    VoltMessage m = m_replaySequencer.poll();
    while (m != null) {
        deliver(m);
        m = m_replaySequencer.poll();
    }
    // Then, try to pull all the drainable messages, if any.
    m = m_replaySequencer.drain();
    while (m != null) {
        if (m instanceof Iv2InitiateTaskMessage) {
            // Send IGNORED response for all SPs
            Iv2InitiateTaskMessage task = (Iv2InitiateTaskMessage) m;
            final InitiateResponseMessage response = new InitiateResponseMessage(task);
            response.setResults(new ClientResponseImpl(ClientResponse.UNEXPECTED_FAILURE, new VoltTable[0], ClientResponseImpl.IGNORED_TRANSACTION));
            m_mailbox.send(response.getInitiatorHSId(), response);
        }
        m = m_replaySequencer.drain();
    }
}
Also used : VoltMessage(org.voltcore.messaging.VoltMessage) Iv2InitiateTaskMessage(org.voltdb.messaging.Iv2InitiateTaskMessage) InitiateResponseMessage(org.voltdb.messaging.InitiateResponseMessage) ClientResponseImpl(org.voltdb.ClientResponseImpl) VoltTable(org.voltdb.VoltTable)

Example 18 with VoltMessage

use of org.voltcore.messaging.VoltMessage in project voltdb by VoltDB.

the class MpScheduler method updateReplicas.

@Override
public void updateReplicas(final List<Long> replicas, final Map<Integer, Long> partitionMasters) {
    // Handle startup and promotion semi-gracefully
    m_iv2Masters.clear();
    m_iv2Masters.addAll(replicas);
    m_partitionMasters.clear();
    m_partitionMasters.putAll(partitionMasters);
    if (!m_isLeader) {
        return;
    }
    // Stolen from SpScheduler.  Need to update the duplicate counters associated with any EveryPartitionTasks
    // Cleanup duplicate counters and collect DONE counters
    // in this list for further processing.
    List<Long> doneCounters = new LinkedList<Long>();
    for (Entry<Long, DuplicateCounter> entry : m_duplicateCounters.entrySet()) {
        DuplicateCounter counter = entry.getValue();
        int result = counter.updateReplicas(m_iv2Masters);
        if (result == DuplicateCounter.DONE) {
            doneCounters.add(entry.getKey());
        }
    }
    // Maintain the CI invariant that responses arrive in txnid order.
    Collections.sort(doneCounters);
    for (Long key : doneCounters) {
        DuplicateCounter counter = m_duplicateCounters.remove(key);
        VoltMessage resp = counter.getLastResponse();
        if (resp != null && resp instanceof InitiateResponseMessage) {
            InitiateResponseMessage msg = (InitiateResponseMessage) resp;
            if (msg.shouldCommit()) {
                m_repairLogTruncationHandle = m_repairLogAwaitingCommit;
                m_repairLogAwaitingCommit = msg.getTxnId();
            }
            m_outstandingTxns.remove(msg.getTxnId());
            m_mailbox.send(counter.m_destinationId, resp);
        } else {
            hostLog.warn("TXN " + counter.getTxnId() + " lost all replicas and " + "had no responses.  This should be impossible?");
        }
    }
    MpRepairTask repairTask = new MpRepairTask((InitiatorMailbox) m_mailbox, replicas);
    m_pendingTasks.repair(repairTask, replicas, partitionMasters);
}
Also used : VoltMessage(org.voltcore.messaging.VoltMessage) InitiateResponseMessage(org.voltdb.messaging.InitiateResponseMessage) LinkedList(java.util.LinkedList)

Example 19 with VoltMessage

use of org.voltcore.messaging.VoltMessage in project voltdb by VoltDB.

the class TestRepairLog method testOfferFragmentTaskMessage.

@Test
public void testOfferFragmentTaskMessage() {
    final AtomicLong lastCommitted = new AtomicLong(Long.MIN_VALUE);
    final TransactionCommitInterest interest = lastCommitted::set;
    RepairLog rl = new RepairLog();
    rl.registerTransactionCommitInterest(interest);
    // trunc(trunc point, txnId).
    VoltMessage m1 = truncFragMsg(0L, 1L);
    rl.deliver(m1);
    assertEquals(2, rl.contents(1L, false).size());
    VoltMessage m2 = truncFragMsg(0L, 2L);
    rl.deliver(m2);
    assertEquals(3, rl.contents(1L, false).size());
    // only the first message for a transaction is logged.
    VoltMessage m2b = truncFragMsg(0L, 2L);
    rl.deliver(m2b);
    assertEquals(3, rl.contents(1L, false).size());
    // trim m1. add m3
    VoltMessage m3 = truncFragMsg(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).getTxnId());
    assertEquals(m3, rl.contents(1L, false).get(2).getPayload());
    assertEquals(3L, rl.contents(1L, false).get(2).getTxnId());
    assertEquals(Long.MIN_VALUE, lastCommitted.get());
}
Also used : VoltMessage(org.voltcore.messaging.VoltMessage) AtomicLong(java.util.concurrent.atomic.AtomicLong) Test(org.junit.Test)

Example 20 with VoltMessage

use of org.voltcore.messaging.VoltMessage in project voltdb by VoltDB.

the class TestRepairLog method testOfferCompleteMessage.

@Test
public void testOfferCompleteMessage() {
    final AtomicLong lastCommitted = new AtomicLong(Long.MIN_VALUE);
    final TransactionCommitInterest interest = lastCommitted::set;
    RepairLog rl = new RepairLog();
    rl.registerTransactionCommitInterest(interest);
    // trunc(trunc point, txnId).
    VoltMessage m1 = truncCompleteMsg(0L, 1L);
    rl.deliver(m1);
    assertEquals(2, rl.contents(1L, false).size());
    VoltMessage m2 = truncCompleteMsg(0L, 2L);
    rl.deliver(m2);
    assertEquals(3, rl.contents(1L, false).size());
    // trim m1. add m3
    VoltMessage m3 = truncCompleteMsg(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).getTxnId());
    assertEquals(m3, rl.contents(1L, false).get(2).getPayload());
    assertEquals(3L, rl.contents(1L, false).get(2).getTxnId());
    assertEquals(Long.MIN_VALUE, lastCommitted.get());
}
Also used : VoltMessage(org.voltcore.messaging.VoltMessage) AtomicLong(java.util.concurrent.atomic.AtomicLong) Test(org.junit.Test)

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