use of org.voltdb.messaging.FragmentTaskMessage in project voltdb by VoltDB.
the class TestMpPromoteAlgo method testFuzz.
@Test
public void testFuzz() throws Exception {
System.out.println("Running testFuzz");
InitiatorMailbox mbox = mock(InitiatorMailbox.class);
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 uig = 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;
}
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());
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);
MpPromoteAlgo dut = new MpPromoteAlgo(survivors, mbox, "bleh ");
Future<RepairResult> result = dut.start();
for (int i = 0; i < 3; i++) {
List<Iv2RepairLogResponseMessage> stuff = logs[i].contents(dut.getRequestId(), true);
System.out.println("Repair log size from: " + i + ": " + stuff.size());
for (Iv2RepairLogResponseMessage msg : stuff) {
msg.m_sourceHSId = (long) i;
dut.deliver(msg);
}
}
result.get();
assertFalse(result.isCancelled());
assertTrue(result.isDone());
// Unfortunately, it's painful to try to stub things to make repairSurvivors() work, so we'll
// go and inspect the guts of SpPromoteAlgo instead. This iteration is largely a copy of the inner loop
// of repairSurvivors()
List<TransactionInfoBaseMessage> finalStream = new ArrayList<TransactionInfoBaseMessage>();
for (Iv2RepairLogResponseMessage li : dut.m_repairLogUnion) {
VoltMessage msg = dut.createRepairMessage(li);
finalStream.add((TransactionInfoBaseMessage) msg);
}
// Check the sanity of the repair stream generated by the MPI.
long lastTxnId = Long.MIN_VALUE;
boolean seenFrag = false;
for (TransactionInfoBaseMessage msg : finalStream) {
if (lastTxnId == Long.MIN_VALUE) {
lastTxnId = msg.getTxnId();
} else {
assertTrue(msg.getTxnId() > lastTxnId);
lastTxnId = msg.getTxnId();
}
if (msg instanceof FragmentTaskMessage) {
assertFalse(seenFrag);
seenFrag = true;
}
}
}
use of org.voltdb.messaging.FragmentTaskMessage in project voltdb by VoltDB.
the class TestMpPromoteAlgo method makeRealFragResponse.
Iv2RepairLogResponseMessage makeRealFragResponse(long requestId, long sourceHSId, int sequence, int ofTotal, long handle) {
FragmentTaskMessage frag = mock(FragmentTaskMessage.class);
when(frag.getInitiateTask()).thenReturn(mock(Iv2InitiateTaskMessage.class));
Iv2RepairLogResponseMessage m = new Iv2RepairLogResponseMessage(requestId, sequence, ofTotal, handle, handle, frag);
m.m_sourceHSId = sourceHSId;
return m;
}
use of org.voltdb.messaging.FragmentTaskMessage in project voltdb by VoltDB.
the class RandomMsgGenerator method generateRandomMessageInStream.
public TransactionInfoBaseMessage generateRandomMessageInStream() {
if (m_rand.nextDouble() > MPCHANCE) {
double type = m_rand.nextDouble();
boolean readOnly = (type < READCHANCE);
boolean binaryLog = (!readOnly && type < BINARYLOGCHANCE);
Iv2InitiateTaskMessage msg = makeIv2InitiateTaskMsg(readOnly, binaryLog, false);
return msg;
} else if (!m_mpInProgress) {
double type = m_rand.nextDouble();
m_currentMpReadOnly = (type < READCHANCE);
boolean binaryLog = (!m_currentMpReadOnly && type < BINARYLOGCHANCE);
FragmentTaskMessage msg = makeFragmentTaskMsg(m_currentMpReadOnly, false);
msg.setStateForDurability(makeIv2InitiateTaskMsg(false, binaryLog, true), Sets.newHashSet(0, 1, 2));
m_mpInProgress = true;
return msg;
} else if (m_rand.nextDouble() > MPDONECHANCE) {
// generate another MP fragment
FragmentTaskMessage msg = makeFragmentTaskMsg(m_currentMpReadOnly, false);
return msg;
} else {
// generate MP complete
// fake restarts
boolean restart = (!m_currentMpReadOnly && m_rand.nextDouble() < MPRESTARTCHANCE);
CompleteTransactionMessage msg = makeCompleteTxnMsg(m_currentMpReadOnly, restart, restart);
if (!restart) {
m_mpInProgress = false;
m_mpiTxnEgo = m_mpiTxnEgo.makeNext();
}
return msg;
}
}
Aggregations