Search in sources :

Example 21 with Iv2InitiateTaskMessage

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

the class TestSpPromoteAlgo method testFuzz.

@Test
public void testFuzz() throws Exception {
    InitiatorMailbox mbox = mock(InitiatorMailbox.class);
    Map<Long, List<TransactionInfoBaseMessage>> finalStreams = new HashMap<Long, List<TransactionInfoBaseMessage>>();
    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 spbuig = new UniqueIdGenerator(0, 0);
    UniqueIdGenerator mpbuig = 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;
        finalStreams.put((long) i, new ArrayList<TransactionInfoBaseMessage>());
    }
    long maxBinaryLogSpUniqueId = Long.MIN_VALUE;
    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());
        if (msg instanceof Iv2InitiateTaskMessage) {
            Pair<Long, Long> uids = TestRepairLog.setBinaryLogUniqueId(msg, spbuig, mpbuig);
            maxBinaryLogSpUniqueId = Math.max(maxBinaryLogSpUniqueId, uids.getFirst());
        }
        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);
    SpPromoteAlgo dut = new SpPromoteAlgo(survivors, mbox, "bleh ", 0);
    Future<RepairResult> result = dut.start();
    for (int i = 0; i < 3; i++) {
        List<Iv2RepairLogResponseMessage> stuff = logs[i].contents(dut.getRequestId(), false);
        System.out.println("Repair log size from: " + i + ": " + stuff.size());
        for (Iv2RepairLogResponseMessage msg : stuff) {
            msg.m_sourceHSId = i;
            dut.deliver(msg);
            // First message is metadata only, skip it in validation stream
            if (msg.getSequence() > 0) {
                //System.out.println("finalstreams: " + finalStreams);
                //System.out.println("get(i): " + i + ": " + finalStreams.get((long)i));
                //System.out.println("msg: " + msg);
                finalStreams.get((long) i).add((TransactionInfoBaseMessage) msg.getPayload());
            }
        }
    }
    assertFalse(result.isCancelled());
    assertTrue(result.isDone());
    // of repairSurvivors()
    for (Iv2RepairLogResponseMessage li : dut.m_repairLogUnion) {
        for (Entry<Long, SpPromoteAlgo.ReplicaRepairStruct> entry : dut.m_replicaRepairStructs.entrySet()) {
            if (entry.getValue().needs(li.getHandle())) {
                // append the missing message for this 'node' to the list of messages that node has seen
                finalStreams.get(entry.getKey()).add((TransactionInfoBaseMessage) li.getPayload());
            }
        }
    }
    // check that all the lists for all the nodes are identical after repair
    int longest = Integer.MIN_VALUE;
    for (Entry<Long, List<TransactionInfoBaseMessage>> entry : finalStreams.entrySet()) {
        System.out.println("SIZE: " + entry.getValue().size());
        if (entry.getValue().size() > longest) {
            if (longest == Integer.MIN_VALUE) {
                longest = entry.getValue().size();
            } else {
                fail("Mismatch in repair stream size!");
            }
        }
    }
    for (int i = 0; i < longest; i++) {
        TransactionInfoBaseMessage current = null;
        for (Entry<Long, List<TransactionInfoBaseMessage>> entry : finalStreams.entrySet()) {
            TransactionInfoBaseMessage msg = entry.getValue().get(i);
            if (current == null) {
                current = msg;
            } else {
                assertEquals(current.getSpHandle(), msg.getSpHandle());
                assertEquals(current.getClass(), msg.getClass());
            }
        }
    }
}
Also used : Iv2RepairLogResponseMessage(org.voltdb.messaging.Iv2RepairLogResponseMessage) HashMap(java.util.HashMap) Iv2InitiateTaskMessage(org.voltdb.messaging.Iv2InitiateTaskMessage) ArrayList(java.util.ArrayList) Random(java.util.Random) CompleteTransactionMessage(org.voltdb.messaging.CompleteTransactionMessage) TransactionInfoBaseMessage(org.voltcore.messaging.TransactionInfoBaseMessage) ArrayList(java.util.ArrayList) List(java.util.List) RepairResult(org.voltdb.iv2.RepairAlgo.RepairResult) Test(org.junit.Test)

Example 22 with Iv2InitiateTaskMessage

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

the class TestSpSchedulerDedupe method testReplicaInitiateTaskResponse.

@Test
public void testReplicaInitiateTaskResponse() throws Exception {
    long txnid = TxnEgo.makeZero(0).getTxnId();
    long primary_hsid = 1111l;
    createObjs();
    Iv2InitiateTaskMessage sptask = createMsg(txnid, false, true, primary_hsid);
    sptask.setSpHandle(txnid);
    dut.deliver(sptask);
    // verify no response sent yet
    verify(mbox, times(0)).send(anyLong(), (VoltMessage) anyObject());
    verify(mbox, times(0)).send(new long[] { anyLong() }, (VoltMessage) anyObject());
    InitiateResponseMessage resp = new InitiateResponseMessage(sptask);
    dut.deliver(resp);
    verify(mbox, times(1)).send(eq(primary_hsid), eq(resp));
}
Also used : Iv2InitiateTaskMessage(org.voltdb.messaging.Iv2InitiateTaskMessage) InitiateResponseMessage(org.voltdb.messaging.InitiateResponseMessage) Test(org.junit.Test)

Example 23 with Iv2InitiateTaskMessage

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

the class TestSpSchedulerDedupe method testPrimaryInitiateTaskResponseNoReplicas.

@Test
public void testPrimaryInitiateTaskResponseNoReplicas() throws Exception {
    long txnid = TxnEgo.makeZero(0).getTxnId();
    long primary_hsid = 1111l;
    createObjs();
    dut.setLeaderState(true);
    dut.updateReplicas(new ArrayList<Long>(), null);
    Iv2InitiateTaskMessage sptask = createMsg(txnid, true, true, primary_hsid);
    dut.deliver(sptask);
    // verify no response sent yet
    verify(mbox, times(0)).send(anyLong(), (VoltMessage) anyObject());
    verify(mbox, times(0)).send(new long[] { anyLong() }, (VoltMessage) anyObject());
    InitiateResponseMessage resp = new InitiateResponseMessage(sptask);
    dut.deliver(resp);
    verify(mbox, times(1)).send(eq(primary_hsid), eq(resp));
}
Also used : Iv2InitiateTaskMessage(org.voltdb.messaging.Iv2InitiateTaskMessage) Matchers.anyLong(org.mockito.Matchers.anyLong) InitiateResponseMessage(org.voltdb.messaging.InitiateResponseMessage) Test(org.junit.Test)

Example 24 with Iv2InitiateTaskMessage

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

the class TestMpTransactionState method testTruncationHandleForwarding.

@Test
public void testTruncationHandleForwarding() throws IOException {
    long truncPt = 100L;
    Iv2InitiateTaskMessage taskmsg = new Iv2InitiateTaskMessage(0, 0, truncPt, 101L, System.currentTimeMillis(), true, false, new StoredProcedureInvocation(), 0, 0, false);
    assertEquals(truncPt, taskmsg.getTruncationHandle());
    FragmentTaskMessage localFrag = mock(FragmentTaskMessage.class);
    FragmentTaskMessage remoteFrag = mock(FragmentTaskMessage.class);
    when(remoteFrag.getFragmentCount()).thenReturn(1);
    buddyHSId = 0;
    Mailbox mailbox = mock(Mailbox.class);
    MpTransactionState dut = new MpTransactionState(mailbox, taskmsg, allHsids, partMasters, buddyHSId, false);
    // create local work and verify the created localwork has the
    // expected truncation point.
    dut.createLocalFragmentWork(localFrag, false);
    verify(dut.m_localWork).setTruncationHandle(truncPt);
    // same with partcipating work.
    dut.createAllParticipatingFragmentWork(remoteFrag);
    verify(dut.m_remoteWork).setTruncationHandle(truncPt);
}
Also used : StoredProcedureInvocation(org.voltdb.StoredProcedureInvocation) FragmentTaskMessage(org.voltdb.messaging.FragmentTaskMessage) Mailbox(org.voltcore.messaging.Mailbox) Iv2InitiateTaskMessage(org.voltdb.messaging.Iv2InitiateTaskMessage) Test(org.junit.Test)

Example 25 with Iv2InitiateTaskMessage

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

the class TestMpTransactionState method testOneSitePartitionedReadWithRollback.

@Test
public void testOneSitePartitionedReadWithRollback() throws IOException {
    long txnId = 1234l;
    int batch_size = 3;
    Iv2InitiateTaskMessage taskmsg = new Iv2InitiateTaskMessage(0, 0, (txnId - 1), txnId, System.currentTimeMillis(), true, false, new StoredProcedureInvocation(), 0, 0, false);
    int hsids = 1;
    buddyHSId = 0;
    long[] non_local = configureHSIds(hsids);
    MpTestPlan plan = createTestPlan(batch_size, true, false, true, non_local);
    Mailbox mailbox = mock(Mailbox.class);
    SiteProcedureConnection siteConnection = mock(SiteProcedureConnection.class);
    MpTransactionState dut = new MpTransactionState(mailbox, taskmsg, allHsids, partMasters, buddyHSId, false);
    // emulate ProcedureRunner's use for a single local fragment
    dut.setupProcedureResume(true, plan.depsToResume);
    dut.createLocalFragmentWork(plan.localWork, false);
    // This will be passed a FragmentTaskMessage with no deps
    dut.createAllParticipatingFragmentWork(plan.remoteWork);
    // we should send one message
    verify(mailbox).send(eq(new long[] { 0 }), (VoltMessage) any());
    // offer all the necessary fragment responses to satisfy deps
    for (FragmentResponseMessage msg : plan.generatedResponses) {
        System.out.println("Offering response: " + msg);
        dut.offerReceivedFragmentResponse(msg);
    }
    // We're getting an error, so this should throw something
    boolean threw = false;
    try {
        dut.recursableRun(siteConnection);
        fail();
    } catch (EEException eee) {
        if (eee.getErrorCode() == 1234) {
            threw = true;
        }
    }
    assertTrue(threw);
}
Also used : StoredProcedureInvocation(org.voltdb.StoredProcedureInvocation) Mailbox(org.voltcore.messaging.Mailbox) SiteProcedureConnection(org.voltdb.SiteProcedureConnection) Iv2InitiateTaskMessage(org.voltdb.messaging.Iv2InitiateTaskMessage) FragmentResponseMessage(org.voltdb.messaging.FragmentResponseMessage) EEException(org.voltdb.exceptions.EEException) Test(org.junit.Test)

Aggregations

Iv2InitiateTaskMessage (org.voltdb.messaging.Iv2InitiateTaskMessage)40 Test (org.junit.Test)14 StoredProcedureInvocation (org.voltdb.StoredProcedureInvocation)13 Mailbox (org.voltcore.messaging.Mailbox)8 FragmentTaskMessage (org.voltdb.messaging.FragmentTaskMessage)8 InitiateResponseMessage (org.voltdb.messaging.InitiateResponseMessage)8 ArrayList (java.util.ArrayList)7 CompleteTransactionMessage (org.voltdb.messaging.CompleteTransactionMessage)7 SiteProcedureConnection (org.voltdb.SiteProcedureConnection)6 FragmentResponseMessage (org.voltdb.messaging.FragmentResponseMessage)6 List (java.util.List)5 Iv2RepairLogResponseMessage (org.voltdb.messaging.Iv2RepairLogResponseMessage)5 Matchers.anyLong (org.mockito.Matchers.anyLong)4 ExecutionException (java.util.concurrent.ExecutionException)3 TransactionInfoBaseMessage (org.voltcore.messaging.TransactionInfoBaseMessage)3 ClientResponseImpl (org.voltdb.ClientResponseImpl)3 ParameterSet (org.voltdb.ParameterSet)3 VoltTable (org.voltdb.VoltTable)3 VoltTrace (org.voltdb.utils.VoltTrace)3 HashMap (java.util.HashMap)2