use of org.voltcore.messaging.VoltMessage in project voltdb by VoltDB.
the class TestVoltMessageSerialization method checkVoltMessage.
VoltMessage checkVoltMessage(VoltMessage msg) throws IOException {
ByteBuffer buf1 = ByteBuffer.allocate(msg.getSerializedSize());
msg.flattenToBuffer(buf1);
buf1.flip();
VoltDbMessageFactory vdbmf = new VoltDbMessageFactory();
VoltMessage msg2 = vdbmf.createMessageFromBuffer(buf1, -1);
ByteBuffer buf2 = ByteBuffer.allocate(msg2.getSerializedSize());
msg2.flattenToBuffer(buf2);
buf1.rewind();
buf2.rewind();
assertEquals(buf1.remaining(), buf2.remaining());
assertTrue(buf1.compareTo(buf2) == 0);
return msg2;
}
use of org.voltcore.messaging.VoltMessage in project voltdb by VoltDB.
the class SpScheduler method deliverReadyTxns.
/**
* Poll the replay sequencer and process the messages until it returns null
*/
private void deliverReadyTxns() {
// First, pull all the sequenced messages, if any.
VoltMessage m = m_replaySequencer.poll();
while (m != null) {
deliver(m);
m = m_replaySequencer.poll();
}
// Then, try to pull all the drainable messages, if any.
m = m_replaySequencer.drain();
while (m != null) {
if (m instanceof Iv2InitiateTaskMessage) {
// Send IGNORED response for all SPs
Iv2InitiateTaskMessage task = (Iv2InitiateTaskMessage) m;
final InitiateResponseMessage response = new InitiateResponseMessage(task);
response.setResults(new ClientResponseImpl(ClientResponse.UNEXPECTED_FAILURE, new VoltTable[0], ClientResponseImpl.IGNORED_TRANSACTION));
m_mailbox.send(response.getInitiatorHSId(), response);
}
m = m_replaySequencer.drain();
}
}
use of org.voltcore.messaging.VoltMessage in project voltdb by VoltDB.
the class MpScheduler method updateReplicas.
@Override
public void updateReplicas(final List<Long> replicas, final Map<Integer, Long> partitionMasters) {
// Handle startup and promotion semi-gracefully
m_iv2Masters.clear();
m_iv2Masters.addAll(replicas);
m_partitionMasters.clear();
m_partitionMasters.putAll(partitionMasters);
if (!m_isLeader) {
return;
}
// Stolen from SpScheduler. Need to update the duplicate counters associated with any EveryPartitionTasks
// Cleanup duplicate counters and collect DONE counters
// in this list for further processing.
List<Long> doneCounters = new LinkedList<Long>();
for (Entry<Long, DuplicateCounter> entry : m_duplicateCounters.entrySet()) {
DuplicateCounter counter = entry.getValue();
int result = counter.updateReplicas(m_iv2Masters);
if (result == DuplicateCounter.DONE) {
doneCounters.add(entry.getKey());
}
}
// Maintain the CI invariant that responses arrive in txnid order.
Collections.sort(doneCounters);
for (Long key : doneCounters) {
DuplicateCounter counter = m_duplicateCounters.remove(key);
VoltMessage resp = counter.getLastResponse();
if (resp != null && resp instanceof InitiateResponseMessage) {
InitiateResponseMessage msg = (InitiateResponseMessage) resp;
if (msg.shouldCommit()) {
m_repairLogTruncationHandle = m_repairLogAwaitingCommit;
m_repairLogAwaitingCommit = msg.getTxnId();
}
m_outstandingTxns.remove(msg.getTxnId());
m_mailbox.send(counter.m_destinationId, resp);
} else {
hostLog.warn("TXN " + counter.getTxnId() + " lost all replicas and " + "had no responses. This should be impossible?");
}
}
MpRepairTask repairTask = new MpRepairTask((InitiatorMailbox) m_mailbox, replicas);
m_pendingTasks.repair(repairTask, replicas, partitionMasters);
}
use of org.voltcore.messaging.VoltMessage in project voltdb by VoltDB.
the class TestRepairLog method testOfferFragmentTaskMessage.
@Test
public void testOfferFragmentTaskMessage() {
final AtomicLong lastCommitted = new AtomicLong(Long.MIN_VALUE);
final TransactionCommitInterest interest = lastCommitted::set;
RepairLog rl = new RepairLog();
rl.registerTransactionCommitInterest(interest);
// trunc(trunc point, txnId).
VoltMessage m1 = truncFragMsg(0L, 1L);
rl.deliver(m1);
assertEquals(2, rl.contents(1L, false).size());
VoltMessage m2 = truncFragMsg(0L, 2L);
rl.deliver(m2);
assertEquals(3, rl.contents(1L, false).size());
// only the first message for a transaction is logged.
VoltMessage m2b = truncFragMsg(0L, 2L);
rl.deliver(m2b);
assertEquals(3, rl.contents(1L, false).size());
// trim m1. add m3
VoltMessage m3 = truncFragMsg(1L, 3L);
rl.deliver(m3);
assertEquals(3, rl.contents(1L, false).size());
assertEquals(m2, rl.contents(1L, false).get(1).getPayload());
assertEquals(2L, rl.contents(1L, false).get(1).getTxnId());
assertEquals(m3, rl.contents(1L, false).get(2).getPayload());
assertEquals(3L, rl.contents(1L, false).get(2).getTxnId());
assertEquals(Long.MIN_VALUE, lastCommitted.get());
}
use of org.voltcore.messaging.VoltMessage in project voltdb by VoltDB.
the class TestRepairLog method testOfferCompleteMessage.
@Test
public void testOfferCompleteMessage() {
final AtomicLong lastCommitted = new AtomicLong(Long.MIN_VALUE);
final TransactionCommitInterest interest = lastCommitted::set;
RepairLog rl = new RepairLog();
rl.registerTransactionCommitInterest(interest);
// trunc(trunc point, txnId).
VoltMessage m1 = truncCompleteMsg(0L, 1L);
rl.deliver(m1);
assertEquals(2, rl.contents(1L, false).size());
VoltMessage m2 = truncCompleteMsg(0L, 2L);
rl.deliver(m2);
assertEquals(3, rl.contents(1L, false).size());
// trim m1. add m3
VoltMessage m3 = truncCompleteMsg(1L, 3L);
rl.deliver(m3);
assertEquals(3, rl.contents(1L, false).size());
assertEquals(m2, rl.contents(1L, false).get(1).getPayload());
assertEquals(2L, rl.contents(1L, false).get(1).getTxnId());
assertEquals(m3, rl.contents(1L, false).get(2).getPayload());
assertEquals(3L, rl.contents(1L, false).get(2).getTxnId());
assertEquals(Long.MIN_VALUE, lastCommitted.get());
}
Aggregations