use of org.apache.cassandra.io.util.FastByteArrayInputStream in project cassandra by apache.
the class MutationVerbHandler method forwardToLocalNodes.
private static void forwardToLocalNodes(Mutation mutation, MessagingService.Verb verb, byte[] forwardBytes, InetAddress from) throws IOException {
try (DataInputStream in = new DataInputStream(new FastByteArrayInputStream(forwardBytes))) {
int size = in.readInt();
// tell the recipients who to send their ack to
MessageOut<Mutation> message = new MessageOut<>(verb, mutation, Mutation.serializer).withParameter(Mutation.FORWARD_FROM, from.getAddress());
// Send a message to each of the addresses on our Forward List
for (int i = 0; i < size; i++) {
InetAddress address = CompactEndpointSerializationHelper.deserialize(in);
int id = in.readInt();
Tracing.trace("Enqueuing forwarded write to {}", address);
MessagingService.instance().sendOneWay(message, id, address);
}
}
}
use of org.apache.cassandra.io.util.FastByteArrayInputStream in project eiger by wlloyd.
the class IndexScanCommand method read.
public static IndexScanCommand read(Message message) throws IOException {
byte[] bytes = message.getMessageBody();
FastByteArrayInputStream bis = new FastByteArrayInputStream(bytes);
return serializer.deserialize(new DataInputStream(bis), message.getVersion());
}
use of org.apache.cassandra.io.util.FastByteArrayInputStream 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.io.util.FastByteArrayInputStream in project eiger by wlloyd.
the class CounterMutationVerbHandler method doVerb.
@Override
public void doVerb(Message message, String id) {
byte[] bytes = message.getMessageBody();
FastByteArrayInputStream buffer = new FastByteArrayInputStream(bytes);
try {
DataInputStream is = new DataInputStream(buffer);
CounterMutation cm = CounterMutation.serializer().deserialize(is, message.getVersion());
if (logger.isDebugEnabled())
logger.debug("Applying forwarded " + cm);
//Check Dependencies
assert VersionUtil.extractDatacenter(cm.extractTimestamp()) != ShortNodeId.getLocalDC() : "Do not expect replication mutations from the localDC (yet)";
if (cm.getDependencies().size() > 0) {
StorageProxy.checkDependencies(cm.getTable(), cm.key(), cm.extractTimestamp(), cm.getDependencies(), new CounterMutationCompletion(message, id, cm));
} else {
applyAndRespond(message, id, cm);
}
} catch (IOException e) {
logger.error("Error in counter mutation", e);
}
}
use of org.apache.cassandra.io.util.FastByteArrayInputStream in project eiger by wlloyd.
the class RowMutation method fromBytes.
public static RowMutation fromBytes(byte[] raw, int version) throws IOException {
RowMutation rm = serializer_.deserialize(new DataInputStream(new FastByteArrayInputStream(raw)), version);
boolean hasCounters = false;
for (Map.Entry<Integer, ColumnFamily> entry : rm.modifications_.entrySet()) {
if (entry.getValue().metadata().getDefaultValidator().isCommutative()) {
hasCounters = true;
break;
}
}
// We need to deserialize at least once for counters to cleanup the delta
if (!hasCounters && version == MessagingService.version_)
rm.preserializedBuffers.put(version, raw);
return rm;
}
Aggregations