Search in sources :

Example 1 with Mailbox

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

the class ProcedureRunnerNT method callAllNodeNTProcedure.

/**
     * Send an invocation directly to each host's CI mailbox.
     * This ONLY works for NT procedures.
     * Track responses and complete the returned future when they're all accounted for.
     */
protected CompletableFuture<Map<Integer, ClientResponse>> callAllNodeNTProcedure(String procName, Object... params) {
    // only one of these at a time
    if (m_outstandingAllHostProc.get()) {
        throw new VoltAbortException(new IllegalStateException("Only one AllNodeNTProcedure operation can be running at a time."));
    }
    m_outstandingAllHostProc.set(true);
    StoredProcedureInvocation invocation = new StoredProcedureInvocation();
    invocation.setProcName(procName);
    invocation.setParams(params);
    invocation.setClientHandle(m_id);
    final Iv2InitiateTaskMessage workRequest = new Iv2InitiateTaskMessage(m_mailbox.getHSId(), m_mailbox.getHSId(), Iv2InitiateTaskMessage.UNUSED_TRUNC_HANDLE, m_id, m_id, true, false, invocation, m_id, ClientInterface.NT_REMOTE_PROC_CID, false);
    m_allHostFut = new CompletableFuture<>();
    m_allHostResponses = new HashMap<>();
    Set<Integer> liveHostIds = null;
    // also held when
    synchronized (m_allHostCallbackLock) {
        // collect the set of live client interface mailbox ids
        liveHostIds = VoltDB.instance().getHostMessenger().getLiveHostIds();
        m_outstandingAllHostProcedureHostIds = liveHostIds;
    }
    // convert host ids to hsids
    long[] hsids = liveHostIds.stream().map(hostId -> CoreUtils.getHSIdFromHostAndSite(hostId, HostMessenger.CLIENT_INTERFACE_SITE_ID)).mapToLong(x -> x).toArray();
    //  you get a concurrent modification exception
    for (long hsid : hsids) {
        m_mailbox.send(hsid, workRequest);
    }
    return m_allHostFut;
}
Also used : VoltAbortException(org.voltdb.VoltProcedure.VoltAbortException) Set(java.util.Set) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) ClientResponse(org.voltdb.client.ClientResponse) InvocationTargetException(java.lang.reflect.InvocationTargetException) ExecutionException(java.util.concurrent.ExecutionException) HostMessenger(org.voltcore.messaging.HostMessenger) Connection(org.voltcore.network.Connection) Mailbox(org.voltcore.messaging.Mailbox) InitiateResponseMessage(org.voltdb.messaging.InitiateResponseMessage) SerializableException(org.voltdb.exceptions.SerializableException) Map(java.util.Map) CoreUtils(org.voltcore.utils.CoreUtils) AuthUser(org.voltdb.AuthSystem.AuthUser) ProcedureCallback(org.voltdb.client.ProcedureCallback) Method(java.lang.reflect.Method) ExecutorService(java.util.concurrent.ExecutorService) VoltLogger(org.voltcore.logging.VoltLogger) Iv2InitiateTaskMessage(org.voltdb.messaging.Iv2InitiateTaskMessage) Iv2InitiateTaskMessage(org.voltdb.messaging.Iv2InitiateTaskMessage) VoltAbortException(org.voltdb.VoltProcedure.VoltAbortException)

Example 2 with Mailbox

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

the class MockMailbox method send.

@Override
public void send(long[] HSIds, VoltMessage message) {
    for (int i = 0; HSIds != null && i < HSIds.length; ++i) {
        Mailbox dest = postoffice.get(HSIds[i]);
        if (dest != null) {
            message.m_sourceHSId = m_hsId;
            dest.deliver(message);
        }
    }
}
Also used : Mailbox(org.voltcore.messaging.Mailbox)

Example 3 with Mailbox

use of org.voltcore.messaging.Mailbox 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 4 with Mailbox

use of org.voltcore.messaging.Mailbox 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)

Example 5 with Mailbox

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

the class TestMpTransactionState method testMultiSitePartitionedRead.

@Test
public void testMultiSitePartitionedRead() 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);
    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);
    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)

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