use of org.voltdb.ClientResponseImpl in project voltdb by VoltDB.
the class SpScheduler method sequenceForReplay.
/**
* Sequence the message for replay if it's for CL or DR.
*
* @param message
* @return true if the message can be delivered directly to the scheduler,
* false if the message is queued
*/
@Override
public boolean sequenceForReplay(VoltMessage message) {
boolean canDeliver = false;
long sequenceWithUniqueId = Long.MIN_VALUE;
boolean commandLog = (message instanceof TransactionInfoBaseMessage && (((TransactionInfoBaseMessage) message).isForReplay()));
boolean sentinel = message instanceof MultiPartitionParticipantMessage;
boolean replay = commandLog || sentinel;
boolean sequenceForReplay = m_isLeader && replay;
if (replay) {
sequenceWithUniqueId = ((TransactionInfoBaseMessage) message).getUniqueId();
}
if (sequenceForReplay) {
InitiateResponseMessage dupe = m_replaySequencer.dedupe(sequenceWithUniqueId, (TransactionInfoBaseMessage) message);
if (dupe != null) {
// Duplicate initiate task message, send response
m_mailbox.send(dupe.getInitiatorHSId(), dupe);
} else if (!m_replaySequencer.offer(sequenceWithUniqueId, (TransactionInfoBaseMessage) message)) {
canDeliver = true;
} else {
deliverReadyTxns();
}
// If it's a DR sentinel, send an acknowledgement
if (sentinel && !commandLog) {
MultiPartitionParticipantMessage mppm = (MultiPartitionParticipantMessage) message;
final InitiateResponseMessage response = new InitiateResponseMessage(mppm);
ClientResponseImpl clientResponse = new ClientResponseImpl(ClientResponseImpl.UNEXPECTED_FAILURE, new VoltTable[0], ClientResponseImpl.IGNORED_TRANSACTION);
response.setResults(clientResponse);
m_mailbox.send(response.getInitiatorHSId(), response);
}
} else {
if (replay) {
// Update last seen and last polled uniqueId for replicas
m_replaySequencer.updateLastSeenUniqueId(sequenceWithUniqueId, (TransactionInfoBaseMessage) message);
m_replaySequencer.updateLastPolledUniqueId(sequenceWithUniqueId, (TransactionInfoBaseMessage) message);
}
canDeliver = true;
}
return canDeliver;
}
use of org.voltdb.ClientResponseImpl in project voltdb by VoltDB.
the class InitiateResponseMessage method initFromBuffer.
@Override
public void initFromBuffer(ByteBuffer buf) throws IOException {
m_txnId = buf.getLong();
m_spHandle = buf.getLong();
m_initiatorHSId = buf.getLong();
m_coordinatorHSId = buf.getLong();
m_clientInterfaceHandle = buf.getLong();
m_connectionId = buf.getLong();
m_readOnly = buf.get() == 1;
m_recovering = buf.get() == 1;
m_mispartitioned = buf.get() == 1;
m_response = new ClientResponseImpl();
m_response.initFromBuffer(buf);
m_commit = (m_response.getStatus() == ClientResponseImpl.SUCCESS);
if (m_mispartitioned) {
long hashinatorVersion = buf.getLong();
byte[] hashinatorBytes = new byte[buf.getInt()];
buf.get(hashinatorBytes);
m_currentHashinatorConfig = Pair.of(hashinatorVersion, hashinatorBytes);
// SPI must be the last to deserialize, it will take the remaining as parameter bytes
m_invocation = new StoredProcedureInvocation();
m_invocation.initFromBuffer(buf);
m_commit = false;
}
}
use of org.voltdb.ClientResponseImpl in project voltdb by VoltDB.
the class UpdateApplicationBase method makeQuickResponse.
/** Error generating shortcut method */
protected static CompletableFuture<ClientResponse> makeQuickResponse(byte statusCode, String msg) {
ClientResponseImpl cri = new ClientResponseImpl(statusCode, new VoltTable[0], msg);
CompletableFuture<ClientResponse> f = new CompletableFuture<>();
f.complete(cri);
return f;
}
use of org.voltdb.ClientResponseImpl in project voltdb by VoltDB.
the class TestVoltMessageSerialization method testInvalidTableCount.
public void testInvalidTableCount() throws Exception {
int size = // version
1 + // clientHandle
8 + // present fields
1 + // status
1 + // app status
1 + // cluster roundtrip time
4 + // number of result tables
2;
ByteBuffer buf = ByteBuffer.allocate(size);
//version
buf.put((byte) 0);
buf.putLong(1L);
byte presentFields = 0;
buf.put(presentFields);
buf.put(ClientResponse.SUCCESS);
buf.put(ClientResponse.SUCCESS);
buf.putInt(100);
buf.putShort((short) (Short.MAX_VALUE + 1));
buf.flip();
ClientResponseImpl deserialized = new ClientResponseImpl();
try {
deserialized.initFromBuffer(buf);
fail("Must have failed for invalid table count");
} catch (IOException e) {
assertTrue(e.getMessage().contains("is negative"));
}
}
use of org.voltdb.ClientResponseImpl in project voltdb by VoltDB.
the class TestVoltMessageSerialization method testInitiateResponseForIv2.
public void testInitiateResponseForIv2() throws IOException {
StoredProcedureInvocation spi = new StoredProcedureInvocation();
spi.setClientHandle(25);
spi.setProcName("elmerfudd");
spi.setParams(57, "wrascallywabbit");
Iv2InitiateTaskMessage itask = new Iv2InitiateTaskMessage(23, 8, 10L, 100045, 99, true, false, spi, 2101, 3101, true);
VoltTable table = new VoltTable(new VoltTable.ColumnInfo("foobar", VoltType.STRING));
table.addRow("howmanylicksdoesittaketogettothecenterofatootsiepop");
InitiateResponseMessage iresponse = new InitiateResponseMessage(itask);
iresponse.setResults(new ClientResponseImpl(ClientResponse.GRACEFUL_FAILURE, new VoltTable[] { table, table }, "knockknockbananna"));
iresponse.setClientHandle(99);
InitiateResponseMessage iresponse2 = (InitiateResponseMessage) checkVoltMessage(iresponse);
assertEquals(iresponse.getTxnId(), iresponse2.getTxnId());
assertTrue(iresponse2.isReadOnly());
}
Aggregations