use of org.voltdb.messaging.FragmentTaskMessage in project voltdb by VoltDB.
the class VoltSystemProcedure method executeSysProcPlanFragmentsAsync.
/**
* Produce work units, possibly on all sites, for a list of plan fragments.
* The final plan fragment must aggregate intermediate results and produce a
* single output dependency. This aggregate output is returned as the
* result.
*
* @param pfs
* an array of synthesized plan fragments
* @param aggregatorOutputDependencyId
* dependency id produced by the aggregation pf The id of the
* table returned as the result of this procedure.
*/
public void executeSysProcPlanFragmentsAsync(SynthesizedPlanFragment[] pfs) {
TransactionState txnState = m_runner.getTxnState();
for (SynthesizedPlanFragment pf : pfs) {
assert (pf.parameters != null);
// run this on
if (pf.multipartition) {
assert ((pf.outputDepId & DtxnConstants.MULTIPARTITION_DEPENDENCY) == DtxnConstants.MULTIPARTITION_DEPENDENCY);
}
FragmentTaskMessage task = FragmentTaskMessage.createWithOneFragment(txnState.initiatorHSId, m_site.getCorrespondingSiteId(), txnState.txnId, txnState.uniqueId, txnState.isReadOnly(), fragIdToHash(pf.fragmentId), pf.outputDepId, pf.parameters, false, txnState.isForReplay());
if (pf.inputDepIds != null) {
for (int depId : pf.inputDepIds) {
task.addInputDepId(0, depId);
}
}
task.setFragmentTaskType(FragmentTaskMessage.SYS_PROC_PER_SITE);
if (pf.suppressDuplicates) {
task.setFragmentTaskType(FragmentTaskMessage.SYS_PROC_PER_PARTITION);
}
if (pf.multipartition) {
// create a workunit for every execution site
txnState.createAllParticipatingFragmentWork(task);
} else {
// create one workunit for the current site
if (pf.siteId == -1)
txnState.createLocalFragmentWork(task, false);
else
txnState.createFragmentWork(new long[] { pf.siteId }, task);
}
}
}
use of org.voltdb.messaging.FragmentTaskMessage in project voltdb by VoltDB.
the class MpTransactionTaskQueue method repair.
// repair is used by MPI repair to inject a repair task into the
// SiteTaskerQueue. Before it does this, it unblocks the MP transaction
// that may be running in the Site thread and causes it to rollback by
// faking an unsuccessful FragmentResponseMessage.
synchronized void repair(SiteTasker task, List<Long> masters, Map<Integer, Long> partitionMasters) {
// We know that every Site assigned to the MPI (either the main writer or
// any of the MP read pool) will only have one active transaction at a time,
// and that we either have active reads or active writes, but never both.
// Figure out which we're doing, and then poison all of the appropriate sites.
Map<Long, TransactionTask> currentSet;
if (!m_currentReads.isEmpty()) {
assert (m_currentWrites.isEmpty());
tmLog.debug("MpTTQ: repairing reads");
for (Long txnId : m_currentReads.keySet()) {
m_sitePool.repair(txnId, task);
}
currentSet = m_currentReads;
} else {
tmLog.debug("MpTTQ: repairing writes");
m_taskQueue.offer(task);
currentSet = m_currentWrites;
}
for (Entry<Long, TransactionTask> e : currentSet.entrySet()) {
if (e.getValue() instanceof MpProcedureTask) {
MpProcedureTask next = (MpProcedureTask) e.getValue();
tmLog.debug("MpTTQ: poisoning task: " + next);
next.doRestart(masters, partitionMasters);
MpTransactionState txn = (MpTransactionState) next.getTransactionState();
// inject poison pill
FragmentTaskMessage dummy = new FragmentTaskMessage(0L, 0L, 0L, 0L, false, false, false);
FragmentResponseMessage poison = // Don't care about source HSID here
new FragmentResponseMessage(dummy, 0L);
// Provide a TransactionRestartException which will be converted
// into a ClientResponse.RESTART, so that the MpProcedureTask can
// detect the restart and take the appropriate actions.
TransactionRestartException restart = new TransactionRestartException("Transaction being restarted due to fault recovery or shutdown.", next.getTxnId());
poison.setStatus(FragmentResponseMessage.UNEXPECTED_ERROR, restart);
txn.offerReceivedFragmentResponse(poison);
} else {
// Don't think that EveryPartitionTasks need to do anything here, since they
// don't actually run java, they just exist for sequencing. Any cleanup should be
// to the duplicate counter in MpScheduler for this transaction.
}
}
// Now, iterate through the backlog and update the partition masters
// for all ProcedureTasks
Iterator<TransactionTask> iter = m_backlog.iterator();
while (iter.hasNext()) {
TransactionTask tt = iter.next();
if (tt instanceof MpProcedureTask) {
MpProcedureTask next = (MpProcedureTask) tt;
tmLog.debug("Repair updating task: " + next + " with masters: " + masters);
next.updateMasters(masters, partitionMasters);
} else if (tt instanceof EveryPartitionTask) {
EveryPartitionTask next = (EveryPartitionTask) tt;
tmLog.debug("Repair updating EPT task: " + next + " with masters: " + masters);
next.updateMasters(masters);
}
}
}
use of org.voltdb.messaging.FragmentTaskMessage in project voltdb by VoltDB.
the class Site method replayFromTaskLog.
boolean replayFromTaskLog(MinimumRatioMaintainer mrm) throws IOException {
// not yet time to catch-up.
if (m_rejoinState != kStateReplayingRejoin) {
return false;
}
TransactionInfoBaseMessage tibm = m_rejoinTaskLog.getNextMessage();
if (tibm != null) {
mrm.didUnrestricted();
if (tibm instanceof Iv2InitiateTaskMessage) {
Iv2InitiateTaskMessage m = (Iv2InitiateTaskMessage) tibm;
SpProcedureTask t = new SpProcedureTask(m_initiatorMailbox, m.getStoredProcedureName(), null, m);
if (!filter(tibm)) {
m_currentTxnId = t.getTxnId();
m_lastTxnTime = EstTime.currentTimeMillis();
t.runFromTaskLog(this);
}
} else if (tibm instanceof FragmentTaskMessage) {
FragmentTaskMessage m = (FragmentTaskMessage) tibm;
if (global_replay_mpTxn == null) {
global_replay_mpTxn = new ParticipantTransactionState(m.getTxnId(), m);
} else if (global_replay_mpTxn.txnId != m.getTxnId()) {
VoltDB.crashLocalVoltDB("Started a MP transaction during replay before completing " + " open transaction.", false, null);
}
TransactionTask t;
if (m.isSysProcTask()) {
t = new SysprocFragmentTask(m_initiatorMailbox, m, global_replay_mpTxn);
} else {
t = new FragmentTask(m_initiatorMailbox, m, global_replay_mpTxn);
}
if (!filter(tibm)) {
m_currentTxnId = t.getTxnId();
m_lastTxnTime = EstTime.currentTimeMillis();
t.runFromTaskLog(this);
}
} else if (tibm instanceof CompleteTransactionMessage) {
// Only complete transactions that are open...
if (global_replay_mpTxn != null) {
CompleteTransactionMessage m = (CompleteTransactionMessage) tibm;
CompleteTransactionTask t = new CompleteTransactionTask(m_initiatorMailbox, global_replay_mpTxn, null, m);
if (!m.isRestart()) {
global_replay_mpTxn = null;
}
if (!filter(tibm)) {
t.runFromTaskLog(this);
}
}
} else {
VoltDB.crashLocalVoltDB("Can not replay message type " + tibm + " during live rejoin. Unexpected error.", false, null);
}
}
// is wrong. Run MP txns fully kStateRejoining or fully kStateRunning.
if (m_rejoinTaskLog.isEmpty() && global_replay_mpTxn == null) {
setReplayRejoinComplete();
}
return tibm != null;
}
use of org.voltdb.messaging.FragmentTaskMessage in project voltdb by VoltDB.
the class RepairLog method deliver.
// Offer a new message to the repair log. This will truncate
// the repairLog if the message includes a truncation hint.
public void deliver(VoltMessage msg) {
if (!m_isLeader && msg instanceof Iv2InitiateTaskMessage) {
final Iv2InitiateTaskMessage m = (Iv2InitiateTaskMessage) msg;
// We can't repair read only SP transactions. Just don't log them to the repair log.
if (m.isReadOnly()) {
return;
}
m_lastSpHandle = m.getSpHandle();
truncate(m.getTruncationHandle(), IS_SP);
m_logSP.add(new Item(IS_SP, m, m.getSpHandle(), m.getTxnId()));
} else if (msg instanceof FragmentTaskMessage) {
final FragmentTaskMessage m = (FragmentTaskMessage) msg;
// We can't repair read only SP transactions. Just don't log them to the repair log.
if (m.isReadOnly()) {
return;
}
truncate(m.getTruncationHandle(), IS_MP);
// only log the first fragment of a procedure (and handle 1st case)
if (m.getTxnId() > m_lastMpHandle || m_lastMpHandle == Long.MAX_VALUE) {
m_logMP.add(new Item(IS_MP, m, m.getSpHandle(), m.getTxnId()));
m_lastMpHandle = m.getTxnId();
m_lastSpHandle = m.getSpHandle();
}
} else if (msg instanceof CompleteTransactionMessage) {
// a CompleteTransactionMessage which indicates restart is not the end of the
// transaction. We don't want to log it in the repair log.
CompleteTransactionMessage ctm = (CompleteTransactionMessage) msg;
// Restart transaction do not need to be repaired here, don't log them as well.
if (ctm.isReadOnly() || ctm.isRestart()) {
return;
}
truncate(ctm.getTruncationHandle(), IS_MP);
m_logMP.add(new Item(IS_MP, ctm, ctm.getSpHandle(), ctm.getTxnId()));
//Restore will send a complete transaction message with a lower mp transaction id because
//the restore transaction precedes the loading of the right mp transaction id from the snapshot
//Hence Math.max
m_lastMpHandle = Math.max(m_lastMpHandle, ctm.getTxnId());
m_lastSpHandle = ctm.getSpHandle();
} else if (msg instanceof DumpMessage) {
String who = CoreUtils.hsIdToString(m_HSId);
tmLog.warn("Repair log dump for site: " + who + ", isLeader: " + m_isLeader + ", " + who + ": lastSpHandle: " + m_lastSpHandle + ", lastMpHandle: " + m_lastMpHandle);
for (Iv2RepairLogResponseMessage il : contents(0l, false)) {
tmLog.warn("[Repair log contents]" + who + ": msg: " + il);
}
} else if (msg instanceof RepairLogTruncationMessage) {
final RepairLogTruncationMessage truncateMsg = (RepairLogTruncationMessage) msg;
truncate(truncateMsg.getHandle(), IS_SP);
}
}
use of org.voltdb.messaging.FragmentTaskMessage in project voltdb by VoltDB.
the class TestTransactionTaskQueue method createFrag.
// Create follow-on fragments of an MP txn
private FragmentTask createFrag(TransactionState txn, long mpTxnId, TransactionTaskQueue queue) {
FragmentTaskMessage msg = mock(FragmentTaskMessage.class);
when(msg.getTxnId()).thenReturn(mpTxnId);
InitiatorMailbox mbox = mock(InitiatorMailbox.class);
when(mbox.getHSId()).thenReturn(1337l);
FragmentTask task = new FragmentTask(mbox, (ParticipantTransactionState) txn, queue, msg, null);
return task;
}
Aggregations