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;
}
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);
}
}
}
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);
}
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);
}
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);
}
Aggregations