Search in sources :

Example 6 with Mailbox

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

the class TestMpTransactionState method testOneSitePartitionedRead.

@Test
public void testOneSitePartitionedRead() throws IOException {
    long txnId = 1234l;
    int batch_size = 3;
    Iv2InitiateTaskMessage taskmsg = new Iv2InitiateTaskMessage(0, -1, (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, false, 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[] { buddyHSId }), (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);
    }
    // if we've satisfied everything, this should run to completion
    Map<Integer, List<VoltTable>> results = dut.recursableRun(siteConnection);
    // Verify we send a BorrowTask
    verify(mailbox).send(eq(buddyHSId), (BorrowTaskMessage) any());
    // verify returned deps/tables
    assertEquals(batch_size, results.size());
    System.out.println(results);
}
Also used : StoredProcedureInvocation(org.voltdb.StoredProcedureInvocation) Iv2InitiateTaskMessage(org.voltdb.messaging.Iv2InitiateTaskMessage) Mailbox(org.voltcore.messaging.Mailbox) SiteProcedureConnection(org.voltdb.SiteProcedureConnection) FragmentResponseMessage(org.voltdb.messaging.FragmentResponseMessage) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 7 with Mailbox

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

the class TestMpTransactionState method testSingleReplicatedReadFragment.

@Test
public void testSingleReplicatedReadFragment() throws IOException {
    long txnId = 1234l;
    int batch_size = 3;
    Iv2InitiateTaskMessage taskmsg = new Iv2InitiateTaskMessage(3, 4, (txnId - 1), txnId, System.currentTimeMillis(), true, false, new StoredProcedureInvocation(), 0, 0, false);
    int hsids = 6;
    buddyHSId = 3;
    long[] non_local = configureHSIds(hsids);
    MpTestPlan plan = createTestPlan(batch_size, true, true, false, 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);
    // verify no messages sent to non-3 HSIDs for read-only
    verify(mailbox, never()).send(anyLong(), (VoltMessage) any());
    verify(mailbox, never()).send(new long[] { anyLong() }, (VoltMessage) any());
    // offer all the necessary fragment responses to satisfy deps
    for (FragmentResponseMessage msg : plan.generatedResponses) {
        dut.offerReceivedFragmentResponse(msg);
    }
    // if we've satisfied everything, this should run to completion
    Map<Integer, List<VoltTable>> results = dut.recursableRun(siteConnection);
    verify(mailbox).send(eq(buddyHSId), (BorrowTaskMessage) any());
    // verify returned deps/tables
    assertEquals(batch_size, results.size());
    System.out.println(results);
}
Also used : StoredProcedureInvocation(org.voltdb.StoredProcedureInvocation) Iv2InitiateTaskMessage(org.voltdb.messaging.Iv2InitiateTaskMessage) Mailbox(org.voltcore.messaging.Mailbox) SiteProcedureConnection(org.voltdb.SiteProcedureConnection) FragmentResponseMessage(org.voltdb.messaging.FragmentResponseMessage) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 8 with Mailbox

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

the class TestMpTransactionState method testMPReadWithDummyResponse.

@Test
public void testMPReadWithDummyResponse() throws IOException {
    long txnId = 1234l;
    int batch_size = 3;
    Iv2InitiateTaskMessage taskmsg = new Iv2InitiateTaskMessage(0, -1, (txnId - 1), txnId, System.currentTimeMillis(), true, false, new StoredProcedureInvocation(), 0, 0, false);
    int hsids = 6;
    buddyHSId = 0;
    long[] non_local = configureHSIds(hsids);
    MpTestPlan plan = createTestPlan(batch_size, true, false, false, non_local);
    // replace the last remote fragment response with a dummy
    for (FragmentResponseMessage dummy : plan.generatedResponses) {
        if (dummy.getExecutorSiteId() == non_local[non_local.length - 1]) {
            dummy.setRecovering(true);
            for (int i = 0; i < dummy.getTableCount(); i++) {
                VoltTable depTable = dummy.getTableAtIndex(i);
                depTable.setStatusCode(VoltTableUtil.NULL_DEPENDENCY_STATUS);
                depTable.clearRowData();
            }
        }
    }
    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 6 messages
    verify(mailbox).send(eq(non_local), (VoltMessage) any());
    // offer all the necessary fragment responses to satisfy deps
    for (FragmentResponseMessage msg : plan.generatedResponses) {
        dut.offerReceivedFragmentResponse(msg);
    }
    // if we've satisfied everything, this should run to completion
    Map<Integer, List<VoltTable>> results = dut.recursableRun(siteConnection);
    ArgumentCaptor<BorrowTaskMessage> borrowCaptor = ArgumentCaptor.forClass(BorrowTaskMessage.class);
    verify(mailbox).send(eq(buddyHSId), borrowCaptor.capture());
    // make sure that the borrow task message doesn't have any dummy dependency tables as input
    BorrowTaskMessage borrowMsg = borrowCaptor.getValue();
    Map<Integer, List<VoltTable>> inputDepMap = borrowMsg.getInputDepMap();
    for (List<VoltTable> tables : inputDepMap.values()) {
        for (VoltTable table : tables) {
            assertNotSame(VoltTableUtil.NULL_DEPENDENCY_STATUS, table.getStatusCode());
        }
    }
    // verify returned deps/tables
    assertEquals(batch_size, results.size());
    System.out.println(results);
}
Also used : StoredProcedureInvocation(org.voltdb.StoredProcedureInvocation) Iv2InitiateTaskMessage(org.voltdb.messaging.Iv2InitiateTaskMessage) BorrowTaskMessage(org.voltdb.messaging.BorrowTaskMessage) VoltTable(org.voltdb.VoltTable) Mailbox(org.voltcore.messaging.Mailbox) SiteProcedureConnection(org.voltdb.SiteProcedureConnection) FragmentResponseMessage(org.voltdb.messaging.FragmentResponseMessage) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 9 with Mailbox

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

the class TestMpTransactionState method testOneSitePartitionedReadWithBuddyRollback.

@Test
public void testOneSitePartitionedReadWithBuddyRollback() 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, false, 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[] { buddyHSId }), (VoltMessage) any());
    // to simplify, offer messages first
    // offer all the necessary fragment responses to satisfy deps
    // just be lazy and perturb the buddy response here
    plan.generatedResponses.get(plan.generatedResponses.size() - 1).setStatus(FragmentResponseMessage.UNEXPECTED_ERROR, new EEException(1234));
    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)

Example 10 with Mailbox

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

the class StreamSnapshotWritePlan method createDataTargets.

private List<DataTargetInfo> createDataTargets(List<StreamSnapshotRequestConfig.Stream> localStreams, HashinatorSnapshotData hashinatorData, Map<Integer, byte[]> schemas) {
    byte[] hashinatorConfig = null;
    if (hashinatorData != null) {
        ByteBuffer hashinatorConfigBuf = ByteBuffer.allocate(8 + hashinatorData.m_serData.length);
        hashinatorConfigBuf.putLong(hashinatorData.m_version);
        hashinatorConfigBuf.put(hashinatorData.m_serData);
        hashinatorConfig = hashinatorConfigBuf.array();
    }
    List<DataTargetInfo> sdts = Lists.newArrayList();
    if (haveAnyStreamPairs(localStreams) && !schemas.isEmpty()) {
        Mailbox mb = VoltDB.instance().getHostMessenger().createMailbox();
        StreamSnapshotDataTarget.SnapshotSender sender = new StreamSnapshotDataTarget.SnapshotSender(mb);
        StreamSnapshotAckReceiver ackReceiver = new StreamSnapshotAckReceiver(mb);
        new Thread(sender, "Stream Snapshot Sender").start();
        new Thread(ackReceiver, "Stream Snapshot Ack Receiver").start();
        // The mailbox will be removed after all snapshot data targets are finished
        SnapshotSiteProcessor.m_tasksOnSnapshotCompletion.offer(createCompletionTask(mb));
        // Create data target for each source HSID in each stream
        for (StreamSnapshotRequestConfig.Stream stream : localStreams) {
            SNAP_LOG.debug("Sites to stream from: " + CoreUtils.hsIdCollectionToString(stream.streamPairs.keySet()));
            for (Entry<Long, Long> entry : stream.streamPairs.entries()) {
                long srcHSId = entry.getKey();
                long destHSId = entry.getValue();
                sdts.add(new DataTargetInfo(stream, srcHSId, destHSId, new StreamSnapshotDataTarget(destHSId, hashinatorConfig, schemas, sender, ackReceiver)));
            }
        }
    }
    return sdts;
}
Also used : ByteBuffer(java.nio.ByteBuffer) Mailbox(org.voltcore.messaging.Mailbox) StreamSnapshotAckReceiver(org.voltdb.rejoin.StreamSnapshotAckReceiver) StreamSnapshotDataTarget(org.voltdb.rejoin.StreamSnapshotDataTarget)

Aggregations

Mailbox (org.voltcore.messaging.Mailbox)12 Iv2InitiateTaskMessage (org.voltdb.messaging.Iv2InitiateTaskMessage)8 Test (org.junit.Test)7 StoredProcedureInvocation (org.voltdb.StoredProcedureInvocation)7 SiteProcedureConnection (org.voltdb.SiteProcedureConnection)6 FragmentResponseMessage (org.voltdb.messaging.FragmentResponseMessage)6 ArrayList (java.util.ArrayList)4 List (java.util.List)4 ByteBuffer (java.nio.ByteBuffer)2 EEException (org.voltdb.exceptions.EEException)2 ImmutableList (com.google_voltpatches.common.collect.ImmutableList)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Set (java.util.Set)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ExecutionException (java.util.concurrent.ExecutionException)1 ExecutorService (java.util.concurrent.ExecutorService)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1