use of org.voltcore.messaging.TransactionInfoBaseMessage in project voltdb by VoltDB.
the class TestSpPromoteAlgo method testFuzz.
@Test
public void testFuzz() throws Exception {
InitiatorMailbox mbox = mock(InitiatorMailbox.class);
Map<Long, List<TransactionInfoBaseMessage>> finalStreams = new HashMap<Long, List<TransactionInfoBaseMessage>>();
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 spbuig = new UniqueIdGenerator(0, 0);
UniqueIdGenerator mpbuig = 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;
finalStreams.put((long) i, new ArrayList<TransactionInfoBaseMessage>());
}
long maxBinaryLogSpUniqueId = Long.MIN_VALUE;
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());
if (msg instanceof Iv2InitiateTaskMessage) {
Pair<Long, Long> uids = TestRepairLog.setBinaryLogUniqueId(msg, spbuig, mpbuig);
maxBinaryLogSpUniqueId = Math.max(maxBinaryLogSpUniqueId, uids.getFirst());
}
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);
SpPromoteAlgo dut = new SpPromoteAlgo(survivors, mbox, "bleh ", 0);
Future<RepairResult> result = dut.start();
for (int i = 0; i < 3; i++) {
List<Iv2RepairLogResponseMessage> stuff = logs[i].contents(dut.getRequestId(), false);
System.out.println("Repair log size from: " + i + ": " + stuff.size());
for (Iv2RepairLogResponseMessage msg : stuff) {
msg.m_sourceHSId = i;
dut.deliver(msg);
// First message is metadata only, skip it in validation stream
if (msg.getSequence() > 0) {
//System.out.println("finalstreams: " + finalStreams);
//System.out.println("get(i): " + i + ": " + finalStreams.get((long)i));
//System.out.println("msg: " + msg);
finalStreams.get((long) i).add((TransactionInfoBaseMessage) msg.getPayload());
}
}
}
assertFalse(result.isCancelled());
assertTrue(result.isDone());
// of repairSurvivors()
for (Iv2RepairLogResponseMessage li : dut.m_repairLogUnion) {
for (Entry<Long, SpPromoteAlgo.ReplicaRepairStruct> entry : dut.m_replicaRepairStructs.entrySet()) {
if (entry.getValue().needs(li.getHandle())) {
// append the missing message for this 'node' to the list of messages that node has seen
finalStreams.get(entry.getKey()).add((TransactionInfoBaseMessage) li.getPayload());
}
}
}
// check that all the lists for all the nodes are identical after repair
int longest = Integer.MIN_VALUE;
for (Entry<Long, List<TransactionInfoBaseMessage>> entry : finalStreams.entrySet()) {
System.out.println("SIZE: " + entry.getValue().size());
if (entry.getValue().size() > longest) {
if (longest == Integer.MIN_VALUE) {
longest = entry.getValue().size();
} else {
fail("Mismatch in repair stream size!");
}
}
}
for (int i = 0; i < longest; i++) {
TransactionInfoBaseMessage current = null;
for (Entry<Long, List<TransactionInfoBaseMessage>> entry : finalStreams.entrySet()) {
TransactionInfoBaseMessage msg = entry.getValue().get(i);
if (current == null) {
current = msg;
} else {
assertEquals(current.getSpHandle(), msg.getSpHandle());
assertEquals(current.getClass(), msg.getClass());
}
}
}
}
use of org.voltcore.messaging.TransactionInfoBaseMessage in project voltdb by VoltDB.
the class TestRepairLog method testFuzz.
@Test
public void testFuzz() {
TxnEgo sphandle = TxnEgo.makeZero(0);
UniqueIdGenerator spbuig = new UniqueIdGenerator(0, 0);
UniqueIdGenerator mpbuig = new UniqueIdGenerator(0, 0);
sphandle = sphandle.makeNext();
RandomMsgGenerator msgGen = new RandomMsgGenerator();
RepairLog dut = new RepairLog();
long spBinaryLogSpUniqueId = Long.MIN_VALUE;
long spBinaryLogMpUniqueId = Long.MIN_VALUE;
long mpBinaryLogMpUniqueId = Long.MIN_VALUE;
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());
if (msg instanceof Iv2InitiateTaskMessage) {
Pair<Long, Long> uids = setBinaryLogUniqueId(msg, spbuig, mpbuig);
spBinaryLogSpUniqueId = Math.max(spBinaryLogSpUniqueId, uids.getFirst());
spBinaryLogMpUniqueId = Math.max(spBinaryLogMpUniqueId, uids.getSecond());
} else if (msg instanceof FragmentTaskMessage) {
mpBinaryLogMpUniqueId = Math.max(mpBinaryLogMpUniqueId, setBinaryLogUniqueId(msg, null, mpbuig).getSecond());
}
sphandle = sphandle.makeNext();
if (!msg.isReadOnly() || msg instanceof CompleteTransactionMessage) {
dut.deliver(msg);
}
}
List<Iv2RepairLogResponseMessage> stuff = dut.contents(1l, false);
validateRepairLog(stuff, spBinaryLogSpUniqueId, spBinaryLogMpUniqueId);
// Also check the MP version
stuff = dut.contents(1l, true);
validateRepairLog(stuff, Long.MIN_VALUE, mpBinaryLogMpUniqueId);
}
use of org.voltcore.messaging.TransactionInfoBaseMessage in project voltdb by VoltDB.
the class TestReplaySequencer method testDrain.
@Test
public void testDrain() {
ReplaySequencer dut = new ReplaySequencer();
// need
// sp1
// mp1
// sp2
// mp2
// sp3
// mp3
// sp4
TransactionInfoBaseMessage init1 = makeIv2InitTask(101L);
TransactionInfoBaseMessage sentinel1 = makeSentinel(1L);
TransactionInfoBaseMessage init2 = makeIv2InitTask(102L);
TransactionInfoBaseMessage sentinel2 = makeSentinel(2L);
TransactionInfoBaseMessage init3 = makeIv2InitTask(103L);
TransactionInfoBaseMessage sentinel3 = makeSentinel(3L);
TransactionInfoBaseMessage init4 = makeIv2InitTask(104L);
Assert.assertFalse(dut.offer(101L, init1));
Assert.assertTrue(dut.offer(1L, sentinel1));
Assert.assertTrue(dut.offer(102L, init2));
Assert.assertTrue(dut.offer(2L, sentinel2));
Assert.assertTrue(dut.offer(103L, init3));
Assert.assertTrue(dut.offer(3L, sentinel3));
Assert.assertTrue(dut.offer(104L, init4));
Assert.assertNull(dut.drain());
// MPI EOL
Assert.assertTrue(dut.offer(0L, makeMPIEOL()));
// Now, we need to be able to drain all of the SP inits out in order to respond IGNORING
Assert.assertNull(dut.poll());
Assert.assertEquals(init2, dut.drain());
Assert.assertEquals(init3, dut.drain());
Assert.assertEquals(init4, dut.drain());
Assert.assertNull(dut.drain());
}
use of org.voltcore.messaging.TransactionInfoBaseMessage in project voltdb by VoltDB.
the class TestReplaySequencer method testAllowLoadTableWithSameTxnId.
@Test
public void testAllowLoadTableWithSameTxnId() {
ReplaySequencer dut = new ReplaySequencer();
TransactionInfoBaseMessage init1 = makeIv2InitTask(1L, "@LoadSinglepartitionTable");
TransactionInfoBaseMessage init2 = makeIv2InitTask(2L, "@LoadMultipartitionTable");
Assert.assertFalse(dut.offer(1L, init1));
Assert.assertNull(dut.dedupe(1L, init1));
Assert.assertFalse(dut.offer(1L, init1));
Assert.assertNull(dut.poll());
Assert.assertFalse(dut.offer(2L, init2));
Assert.assertNull(dut.dedupe(2L, init2));
Assert.assertFalse(dut.offer(2L, init2));
Assert.assertNull(dut.poll());
}
use of org.voltcore.messaging.TransactionInfoBaseMessage in project voltdb by VoltDB.
the class TestReplaySequencer method testMPIEOL.
@Test
public void testMPIEOL() {
ReplaySequencer dut = new ReplaySequencer();
TransactionInfoBaseMessage init1 = makeIv2InitTask(101L);
TransactionInfoBaseMessage sentinel1 = makeSentinel(1L);
TransactionInfoBaseMessage init2 = makeIv2InitTask(102L);
TransactionInfoBaseMessage init3 = makeIv2InitTask(103L);
TransactionInfoBaseMessage sentinel2 = makeSentinel(2L);
TransactionInfoBaseMessage init4 = makeIv2InitTask(104L);
TransactionInfoBaseMessage init5 = makeIv2InitTask(105L);
Assert.assertFalse(dut.offer(101L, init1));
Assert.assertNull(dut.poll());
Assert.assertTrue(dut.offer(1L, sentinel1));
Assert.assertNull(dut.poll());
// SPs blocked by the sentinel
Assert.assertTrue(dut.offer(102L, init2));
Assert.assertTrue(dut.offer(103L, init3));
Assert.assertNull(dut.poll());
// SPs blocked by second sentinel
Assert.assertTrue(dut.offer(2L, sentinel2));
Assert.assertTrue(dut.offer(104L, init4));
Assert.assertTrue(dut.offer(105L, init5));
Assert.assertNull(dut.poll());
Assert.assertNull(dut.drain());
TransactionInfoBaseMessage frag1 = makeFragment(1L);
TransactionInfoBaseMessage complete1 = makeCompleteTxn(1L);
// Offering the fragment and the complete releases init2 and init3
Assert.assertTrue(dut.offer(1L, frag1));
Assert.assertEquals(frag1, dut.poll());
Assert.assertEquals(init2, dut.poll());
Assert.assertEquals(init3, dut.poll());
Assert.assertNull(dut.poll());
Assert.assertFalse(dut.offer(1L, complete1));
Assert.assertNull(dut.drain());
// Move us to drain() mode
Assert.assertTrue(dut.offer(0L, makeMPIEOL()));
// All blocked SPs should be released
Assert.assertNull(dut.poll());
Assert.assertEquals(init4, dut.drain());
Assert.assertEquals(init5, dut.drain());
Assert.assertNull(dut.drain());
}
Aggregations