use of org.apache.cassandra.net.Message in project eiger by wlloyd.
the class ReadVerbHandler method doVerb.
public void doVerb(Message message, String id) {
if (StorageService.instance.isBootstrapMode()) {
throw new RuntimeException("Cannot service reads while bootstrapping!");
}
try {
FastByteArrayInputStream in = new FastByteArrayInputStream(message.getMessageBody());
ReadCommand command = ReadCommand.serializer().deserialize(new DataInputStream(in), message.getVersion());
Table table = Table.open(command.table);
Row row = command.getRow(table);
ReadResponse response = getResponse(command, row);
byte[] bytes = FBUtilities.serialize(response, ReadResponse.serializer(), message.getVersion());
Message reply = message.getReply(FBUtilities.getBroadcastAddress(), bytes, message.getVersion());
if (logger_.isDebugEnabled())
logger_.debug(String.format("Read key %s; sending response to %s@%s", ByteBufferUtil.bytesToHex(command.key), id, message.getFrom()));
MessagingService.instance().sendReply(reply, id, message.getFrom());
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
use of org.apache.cassandra.net.Message in project eiger by wlloyd.
the class AppliedOperations method sendDepCheckReply.
private static void sendDepCheckReply(Message depCheckMessage, String id) {
logger.debug("Send dependency check reply. (dcm.lt={})", depCheckMessage.getLamportTimestamp());
byte[] empty = new byte[0];
Message reply = depCheckMessage.getReply(FBUtilities.getBroadcastAddress(), empty, depCheckMessage.getVersion());
MessagingService.instance().sendReply(reply, id, depCheckMessage.getFrom());
}
use of org.apache.cassandra.net.Message in project eiger by wlloyd.
the class CounterMutationVerbHandler method applyAndRespond.
protected void applyAndRespond(Message message, String id, CounterMutation cm) {
try {
String localDataCenter = DatabaseDescriptor.getEndpointSnitch().getDatacenter(FBUtilities.getBroadcastAddress());
StorageProxy.applyCounterMutationOnLeader(cm, localDataCenter).get();
WriteResponse response = new WriteResponse(cm.getTable(), cm.key(), true);
Message responseMessage = WriteResponse.makeWriteResponseMessage(message, response);
MessagingService.instance().sendReply(responseMessage, id, message.getFrom());
} catch (UnavailableException e) {
// We check for UnavailableException in the coordinator not. It is
// hence reasonable to let the coordinator timeout in the very
// unlikely case we arrive here
} catch (TimeoutException e) {
// The coordinator node will have timeout itself so we let that goes
} catch (IOException e) {
logger.error("Error in counter mutation", e);
}
}
use of org.apache.cassandra.net.Message in project eiger by wlloyd.
the class TruncateVerbHandler method respondError.
private static void respondError(Truncation t, Message truncateRequestMessage) throws IOException {
TruncateResponse response = new TruncateResponse(t.keyspace, t.columnFamily, false);
Message responseMessage = TruncateResponse.makeTruncateResponseMessage(truncateRequestMessage, response);
MessagingService.instance().sendOneWay(responseMessage, truncateRequestMessage.getFrom());
}
use of org.apache.cassandra.net.Message in project eiger by wlloyd.
the class TruncateVerbHandler method doVerb.
public void doVerb(Message message, String id) {
byte[] bytes = message.getMessageBody();
FastByteArrayInputStream buffer = new FastByteArrayInputStream(bytes);
try {
Truncation t = Truncation.serializer().deserialize(new DataInputStream(buffer), message.getVersion());
logger.debug("Applying {}", t);
try {
ColumnFamilyStore cfs = Table.open(t.keyspace).getColumnFamilyStore(t.columnFamily);
cfs.truncate().get();
} catch (Exception e) {
logger.error("Error in truncation", e);
respondError(t, message);
}
logger.debug("Truncate operation succeeded at this host");
TruncateResponse response = new TruncateResponse(t.keyspace, t.columnFamily, true);
Message responseMessage = TruncateResponse.makeTruncateResponseMessage(message, response);
logger.debug("{} applied. Sending response to {}@{} ", new Object[] { t, id, message.getFrom() });
MessagingService.instance().sendReply(responseMessage, id, message.getFrom());
} catch (IOException e) {
throw new IOError(e);
}
}
Aggregations