use of org.apache.cassandra.io.util.FastByteArrayInputStream 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);
}
}
use of org.apache.cassandra.io.util.FastByteArrayInputStream in project eiger by wlloyd.
the class IncomingTcpConnection method run.
/**
* A new connection will either stream or message for its entire lifetime: because streaming
* bypasses the InputStream implementations to use sendFile, we cannot begin buffering until
* we've determined the type of the connection.
*/
@Override
public void run() {
DataInputStream input;
boolean isStream;
int version;
try {
// determine the connection type to decide whether to buffer
input = new DataInputStream(socket.getInputStream());
MessagingService.validateMagic(input.readInt());
int header = input.readInt();
isStream = MessagingService.getBits(header, 3, 1) == 1;
version = MessagingService.getBits(header, 15, 8);
logger.debug("Version for {} is {}", from, version);
if (isStream) {
if (version == MessagingService.version_) {
int size = input.readInt();
byte[] headerBytes = new byte[size];
input.readFully(headerBytes);
stream(StreamHeader.serializer().deserialize(new DataInputStream(new FastByteArrayInputStream(headerBytes)), version), input);
} else {
// streaming connections are per-session and have a fixed version. we can't do anything with a wrong-version stream connection, so drop it.
logger.error("Received stream using protocol version {} (my version {}). Terminating connection", version, MessagingService.version_);
}
// We are done with this connection....
return;
}
// we should buffer
input = new DataInputStream(new BufferedInputStream(socket.getInputStream(), 4096));
// Receive the first message to set the version.
Message msg = receiveMessage(input, version);
if (version > MessagingService.version_) {
// save the endpoint so gossip will reconnect to it
Gossiper.instance.addSavedEndpoint(from);
logger.info("Received " + (isStream ? "streaming " : "") + "connection from newer protocol version. Ignorning");
} else if (msg != null) {
Gossiper.instance.setVersion(msg.getFrom(), version);
logger.debug("set version for {} to {}", from, version);
}
// loop to get the next message.
while (true) {
// prepare to read the next message
MessagingService.validateMagic(input.readInt());
header = input.readInt();
assert isStream == (MessagingService.getBits(header, 3, 1) == 1) : "Connections cannot change type: " + isStream;
version = MessagingService.getBits(header, 15, 8);
logger.trace("Version is now {}", version);
receiveMessage(input, version);
}
} catch (EOFException e) {
logger.trace("eof reading from socket; closing", e);
// connection will be reset so no need to throw an exception.
} catch (IOException e) {
logger.debug("IOError reading from socket; closing", e);
} finally {
close();
}
}
use of org.apache.cassandra.io.util.FastByteArrayInputStream in project eiger by wlloyd.
the class AbstractRowResolver method preprocess.
public void preprocess(Message message) {
byte[] body = message.getMessageBody();
FastByteArrayInputStream bufIn = new FastByteArrayInputStream(body);
try {
ReadResponse result = ReadResponse.serializer().deserialize(new DataInputStream(bufIn), message.getVersion());
if (logger.isDebugEnabled())
logger.debug("Preprocessed {} response", result.isDigestQuery() ? "digest" : "data");
replies.put(message, result);
} catch (IOException e) {
throw new IOError(e);
}
}
use of org.apache.cassandra.io.util.FastByteArrayInputStream in project eiger by wlloyd.
the class GossipDigestAck2VerbHandler method doVerb.
public void doVerb(Message message, String id) {
if (logger_.isTraceEnabled()) {
InetAddress from = message.getFrom();
logger_.trace("Received a GossipDigestAck2Message from {}", from);
}
byte[] bytes = message.getMessageBody();
DataInputStream dis = new DataInputStream(new FastByteArrayInputStream(bytes));
GossipDigestAck2Message gDigestAck2Message;
try {
gDigestAck2Message = GossipDigestAck2Message.serializer().deserialize(dis, message.getVersion());
} catch (IOException e) {
throw new RuntimeException(e);
}
Map<InetAddress, EndpointState> remoteEpStateMap = gDigestAck2Message.getEndpointStateMap();
/* Notify the Failure Detector */
Gossiper.instance.notifyFailureDetector(remoteEpStateMap);
Gossiper.instance.applyStateLocally(remoteEpStateMap);
}
use of org.apache.cassandra.io.util.FastByteArrayInputStream in project eiger by wlloyd.
the class GossipDigestSynVerbHandler method doVerb.
public void doVerb(Message message, String id) {
InetAddress from = message.getFrom();
if (logger_.isTraceEnabled())
logger_.trace("Received a GossipDigestSynMessage from {}", from);
if (!Gossiper.instance.isEnabled()) {
if (logger_.isTraceEnabled())
logger_.trace("Ignoring GossipDigestSynMessage because gossip is disabled");
return;
}
byte[] bytes = message.getMessageBody();
DataInputStream dis = new DataInputStream(new FastByteArrayInputStream(bytes));
try {
GossipDigestSynMessage gDigestMessage = GossipDigestSynMessage.serializer().deserialize(dis, message.getVersion());
/* If the message is from a different cluster throw it away. */
if (!gDigestMessage.clusterId_.equals(DatabaseDescriptor.getClusterName())) {
logger_.warn("ClusterName mismatch from " + from + " " + gDigestMessage.clusterId_ + "!=" + DatabaseDescriptor.getClusterName());
return;
}
List<GossipDigest> gDigestList = gDigestMessage.getGossipDigests();
if (logger_.isTraceEnabled()) {
StringBuilder sb = new StringBuilder();
for (GossipDigest gDigest : gDigestList) {
sb.append(gDigest);
sb.append(" ");
}
logger_.trace("Gossip syn digests are : " + sb.toString());
}
/* Notify the Failure Detector */
Gossiper.instance.notifyFailureDetector(gDigestList);
doSort(gDigestList);
List<GossipDigest> deltaGossipDigestList = new ArrayList<GossipDigest>();
Map<InetAddress, EndpointState> deltaEpStateMap = new HashMap<InetAddress, EndpointState>();
Gossiper.instance.examineGossiper(gDigestList, deltaGossipDigestList, deltaEpStateMap);
GossipDigestAckMessage gDigestAck = new GossipDigestAckMessage(deltaGossipDigestList, deltaEpStateMap);
Message gDigestAckMessage = Gossiper.instance.makeGossipDigestAckMessage(gDigestAck, message.getVersion());
if (logger_.isTraceEnabled())
logger_.trace("Sending a GossipDigestAckMessage to {}", from);
MessagingService.instance().sendOneWay(gDigestAckMessage, from);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
Aggregations