Search in sources :

Example 11 with Iv2RepairLogResponseMessage

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

the class TestSpPromoteAlgo method testUnion.

// verify that responses are correctly unioned and ordered.
@Test
public void testUnion() throws Exception {
    SpPromoteAlgo term = new SpPromoteAlgo(null, null, "Test", 1);
    // returned sphandles in a non-trivial order, with duplicates.
    long[] returnedSpHandles = new long[] { 1L, 5L, 2L, 5L, 6L, 3L, 5L, 1L };
    long[] expectedUnion = new long[] { 1L, 2L, 3L, 5L, 6L };
    for (long sp : returnedSpHandles) {
        term.m_repairLogUnion.add(makeResponse(sp));
    }
    assertEquals(expectedUnion.length, term.m_repairLogUnion.size());
    int i = 0;
    for (Iv2RepairLogResponseMessage li : term.m_repairLogUnion) {
        assertEquals(li.getHandle(), expectedUnion[i++]);
    }
}
Also used : Iv2RepairLogResponseMessage(org.voltdb.messaging.Iv2RepairLogResponseMessage) Test(org.junit.Test)

Example 12 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 13 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 14 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)

Example 15 with Iv2RepairLogResponseMessage

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

the class TestMpPromoteAlgo method makeRealFragResponse.

Iv2RepairLogResponseMessage makeRealFragResponse(long requestId, long sourceHSId, int sequence, int ofTotal, long handle) {
    FragmentTaskMessage frag = mock(FragmentTaskMessage.class);
    when(frag.getInitiateTask()).thenReturn(mock(Iv2InitiateTaskMessage.class));
    Iv2RepairLogResponseMessage m = new Iv2RepairLogResponseMessage(requestId, sequence, ofTotal, handle, handle, frag);
    m.m_sourceHSId = sourceHSId;
    return m;
}
Also used : Iv2RepairLogResponseMessage(org.voltdb.messaging.Iv2RepairLogResponseMessage) FragmentTaskMessage(org.voltdb.messaging.FragmentTaskMessage) Iv2InitiateTaskMessage(org.voltdb.messaging.Iv2InitiateTaskMessage)

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