Search in sources :

Example 16 with Iv2RepairLogResponseMessage

use of org.voltdb.messaging.Iv2RepairLogResponseMessage in project voltdb by VoltDB.

the class TestSpPromoteAlgo method makeResponse.

Iv2RepairLogResponseMessage makeResponse(long spHandle) {
    Iv2RepairLogResponseMessage m = mock(Iv2RepairLogResponseMessage.class);
    when(m.getHandle()).thenReturn(spHandle);
    Iv2InitiateTaskMessage im = mock(Iv2InitiateTaskMessage.class);
    when(m.getPayload()).thenReturn(im);
    return m;
}
Also used : Iv2RepairLogResponseMessage(org.voltdb.messaging.Iv2RepairLogResponseMessage) Iv2InitiateTaskMessage(org.voltdb.messaging.Iv2InitiateTaskMessage)

Example 17 with Iv2RepairLogResponseMessage

use of org.voltdb.messaging.Iv2RepairLogResponseMessage 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 18 with Iv2RepairLogResponseMessage

use of org.voltdb.messaging.Iv2RepairLogResponseMessage in project voltdb by VoltDB.

the class RepairLog method contents.

// produce the contents of the repair log.
public List<Iv2RepairLogResponseMessage> contents(long requestId, boolean forMPI) {
    List<Item> items = new LinkedList<Item>();
    // All cases include the log of MP transactions
    items.addAll(m_logMP);
    // SP repair requests also want the SP transactions
    if (!forMPI) {
        items.addAll(m_logSP);
    }
    // Contents need to be sorted in increasing spHandle order
    Collections.sort(items, m_handleComparator);
    int ofTotal = items.size() + 1;
    if (tmLog.isDebugEnabled()) {
        tmLog.debug("Responding with " + ofTotal + " repair log parts.");
    }
    List<Iv2RepairLogResponseMessage> responses = new LinkedList<Iv2RepairLogResponseMessage>();
    // this constructor sets its sequence no to 0 as ack
    // messages are first in the sequence
    Iv2RepairLogResponseMessage hheader = new Iv2RepairLogResponseMessage(requestId, ofTotal, m_lastSpHandle, m_lastMpHandle, TheHashinator.getCurrentVersionedConfigCooked());
    responses.add(hheader);
    // = 1, as the first sequence
    int seq = responses.size();
    Iterator<Item> itemator = items.iterator();
    while (itemator.hasNext()) {
        Item item = itemator.next();
        Iv2RepairLogResponseMessage response = new Iv2RepairLogResponseMessage(requestId, seq++, ofTotal, item.getHandle(), item.getTxnId(), item.getMessage());
        responses.add(response);
    }
    return responses;
}
Also used : Iv2RepairLogResponseMessage(org.voltdb.messaging.Iv2RepairLogResponseMessage) LinkedList(java.util.LinkedList)

Example 19 with Iv2RepairLogResponseMessage

use of org.voltdb.messaging.Iv2RepairLogResponseMessage in project voltdb by VoltDB.

the class TestMpPromoteAlgo method testFuzz.

@Test
public void testFuzz() throws Exception {
    System.out.println("Running testFuzz");
    InitiatorMailbox mbox = mock(InitiatorMailbox.class);
    Random rand = new Random(System.currentTimeMillis());
    // Generate a random message stream to several "replicas", interrupted
    // at random points to all but one.  Validate that promotion repair
    // results in identical, correct, repair streams to all replicas.
    TxnEgo sphandle = TxnEgo.makeZero(0);
    UniqueIdGenerator uig = new UniqueIdGenerator(0, 0);
    sphandle = sphandle.makeNext();
    RandomMsgGenerator msgGen = new RandomMsgGenerator();
    boolean[] stops = new boolean[3];
    RepairLog[] logs = new RepairLog[3];
    for (int i = 0; i < 3; i++) {
        logs[i] = new RepairLog();
        stops[i] = false;
    }
    for (int i = 0; i < 4000; i++) {
        // get next message, update the sphandle according to SpScheduler rules,
        // but only submit messages that would have been forwarded by the master
        // to the repair log.
        TransactionInfoBaseMessage msg = msgGen.generateRandomMessageInStream();
        msg.setSpHandle(sphandle.getTxnId());
        sphandle = sphandle.makeNext();
        if (!msg.isReadOnly() || msg instanceof CompleteTransactionMessage) {
            if (!stops[0]) {
                logs[0].deliver(msg);
            }
            if (!stops[1]) {
                logs[1].deliver(msg);
            }
            logs[2].deliver(msg);
            // be fed any transactions
            for (int j = 0; j < 2; j++) {
                // Hacky way to get spaced failures
                if (rand.nextDouble() < (.01 / ((j + 1) * 5))) {
                    stops[j] = true;
                }
            }
        }
    }
    List<Long> survivors = new ArrayList<Long>();
    survivors.add(0l);
    survivors.add(1l);
    survivors.add(2l);
    MpPromoteAlgo dut = new MpPromoteAlgo(survivors, mbox, "bleh ");
    Future<RepairResult> result = dut.start();
    for (int i = 0; i < 3; i++) {
        List<Iv2RepairLogResponseMessage> stuff = logs[i].contents(dut.getRequestId(), true);
        System.out.println("Repair log size from: " + i + ": " + stuff.size());
        for (Iv2RepairLogResponseMessage msg : stuff) {
            msg.m_sourceHSId = (long) i;
            dut.deliver(msg);
        }
    }
    result.get();
    assertFalse(result.isCancelled());
    assertTrue(result.isDone());
    // Unfortunately, it's painful to try to stub things to make repairSurvivors() work, so we'll
    // go and inspect the guts of SpPromoteAlgo instead.  This iteration is largely a copy of the inner loop
    // of repairSurvivors()
    List<TransactionInfoBaseMessage> finalStream = new ArrayList<TransactionInfoBaseMessage>();
    for (Iv2RepairLogResponseMessage li : dut.m_repairLogUnion) {
        VoltMessage msg = dut.createRepairMessage(li);
        finalStream.add((TransactionInfoBaseMessage) msg);
    }
    // Check the sanity of the repair stream generated by the MPI.
    long lastTxnId = Long.MIN_VALUE;
    boolean seenFrag = false;
    for (TransactionInfoBaseMessage msg : finalStream) {
        if (lastTxnId == Long.MIN_VALUE) {
            lastTxnId = msg.getTxnId();
        } else {
            assertTrue(msg.getTxnId() > lastTxnId);
            lastTxnId = msg.getTxnId();
        }
        if (msg instanceof FragmentTaskMessage) {
            assertFalse(seenFrag);
            seenFrag = true;
        }
    }
}
Also used : Iv2RepairLogResponseMessage(org.voltdb.messaging.Iv2RepairLogResponseMessage) FragmentTaskMessage(org.voltdb.messaging.FragmentTaskMessage) ArrayList(java.util.ArrayList) RepairResult(org.voltdb.iv2.RepairAlgo.RepairResult) VoltMessage(org.voltcore.messaging.VoltMessage) Random(java.util.Random) CompleteTransactionMessage(org.voltdb.messaging.CompleteTransactionMessage) TransactionInfoBaseMessage(org.voltcore.messaging.TransactionInfoBaseMessage) Test(org.junit.Test)

Example 20 with Iv2RepairLogResponseMessage

use of org.voltdb.messaging.Iv2RepairLogResponseMessage in project voltdb by VoltDB.

the class TestMpPromoteAlgo method makeRealAckResponse.

Iv2RepairLogResponseMessage makeRealAckResponse(long requestId, long sourceHSId, int sequence, int ofTotal, long handle, Pair<Long, byte[]> versionedHashinatorConfig) {
    assertEquals(0, sequence);
    Iv2RepairLogResponseMessage m = new Iv2RepairLogResponseMessage(requestId, ofTotal, handle, handle, versionedHashinatorConfig);
    m.m_sourceHSId = sourceHSId;
    return m;
}
Also used : Iv2RepairLogResponseMessage(org.voltdb.messaging.Iv2RepairLogResponseMessage)

Aggregations

Iv2RepairLogResponseMessage (org.voltdb.messaging.Iv2RepairLogResponseMessage)21 CompleteTransactionMessage (org.voltdb.messaging.CompleteTransactionMessage)7 Test (org.junit.Test)6 FragmentTaskMessage (org.voltdb.messaging.FragmentTaskMessage)6 Iv2InitiateTaskMessage (org.voltdb.messaging.Iv2InitiateTaskMessage)6 ArrayList (java.util.ArrayList)4 AtomicLong (java.util.concurrent.atomic.AtomicLong)3 TransactionInfoBaseMessage (org.voltcore.messaging.TransactionInfoBaseMessage)3 VoltMessage (org.voltcore.messaging.VoltMessage)3 Random (java.util.Random)2 RepairResult (org.voltdb.iv2.RepairAlgo.RepairResult)2 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 InOrder (org.mockito.InOrder)1 DumpMessage (org.voltdb.messaging.DumpMessage)1 Iv2RepairLogRequestMessage (org.voltdb.messaging.Iv2RepairLogRequestMessage)1 RepairLogTruncationMessage (org.voltdb.messaging.RepairLogTruncationMessage)1