use of org.apache.cassandra.net.MessageOut in project cassandra by apache.
the class SnapshotVerbHandler method doVerb.
public void doVerb(MessageIn<SnapshotCommand> message, int id) {
SnapshotCommand command = message.payload;
if (command.clear_snapshot) {
Keyspace.clearSnapshot(command.snapshot_name, command.keyspace);
} else
Keyspace.open(command.keyspace).getColumnFamilyStore(command.column_family).snapshot(command.snapshot_name);
logger.debug("Enqueuing response to snapshot request {} to {}", command.snapshot_name, message.from);
MessagingService.instance().sendReply(new MessageOut(MessagingService.Verb.INTERNAL_RESPONSE), id, message.from);
}
use of org.apache.cassandra.net.MessageOut in project cassandra by apache.
the class MigrationTask method runMayThrow.
public void runMayThrow() throws Exception {
// a higher major.
if (!MigrationManager.shouldPullSchemaFrom(endpoint)) {
logger.info("Skipped sending a migration request: node {} has a higher major version now.", endpoint);
return;
}
if (!FailureDetector.instance.isAlive(endpoint)) {
logger.debug("Can't send schema pull request: node {} is down.", endpoint);
return;
}
MessageOut message = new MessageOut<>(MessagingService.Verb.MIGRATION_REQUEST, null, MigrationManager.MigrationsSerializer.instance);
final CountDownLatch completionLatch = new CountDownLatch(1);
IAsyncCallback<Collection<Mutation>> cb = new IAsyncCallback<Collection<Mutation>>() {
@Override
public void response(MessageIn<Collection<Mutation>> message) {
try {
Schema.instance.mergeAndAnnounceVersion(message.payload);
} catch (ConfigurationException e) {
logger.error("Configuration exception merging remote schema", e);
} finally {
completionLatch.countDown();
}
}
public boolean isLatencyForSnitch() {
return false;
}
};
// Only save the latches if we need bootstrap or are bootstrapping
if (monitoringBootstrapStates.contains(SystemKeyspace.getBootstrapState()))
inflightTasks.offer(completionLatch);
MessagingService.instance().sendRR(message, endpoint, cb);
}
use of org.apache.cassandra.net.MessageOut in project cassandra by apache.
the class GossipDigestAckVerbHandler method doVerb.
public void doVerb(MessageIn<GossipDigestAck> message, int id) {
InetAddress from = message.from;
if (logger.isTraceEnabled())
logger.trace("Received a GossipDigestAckMessage from {}", from);
if (!Gossiper.instance.isEnabled() && !Gossiper.instance.isInShadowRound()) {
if (logger.isTraceEnabled())
logger.trace("Ignoring GossipDigestAckMessage because gossip is disabled");
return;
}
GossipDigestAck gDigestAckMessage = message.payload;
List<GossipDigest> gDigestList = gDigestAckMessage.getGossipDigestList();
Map<InetAddress, EndpointState> epStateMap = gDigestAckMessage.getEndpointStateMap();
logger.trace("Received ack with {} digests and {} states", gDigestList.size(), epStateMap.size());
if (epStateMap.size() > 0) {
/* Notify the Failure Detector */
Gossiper.instance.notifyFailureDetector(epStateMap);
Gossiper.instance.applyStateLocally(epStateMap);
}
if (Gossiper.instance.isInShadowRound()) {
if (logger.isDebugEnabled())
logger.debug("Received an ack from {}, which may trigger exit from shadow round", from);
// if the ack is completely empty, then we can infer that the respondent is also in a shadow round
Gossiper.instance.maybeFinishShadowRound(from, gDigestList.isEmpty() && epStateMap.isEmpty());
// don't bother doing anything else, we have what we came for
return;
}
/* Get the state required to send to this gossipee - construct GossipDigestAck2Message */
Map<InetAddress, EndpointState> deltaEpStateMap = new HashMap<InetAddress, EndpointState>();
for (GossipDigest gDigest : gDigestList) {
InetAddress addr = gDigest.getEndpoint();
EndpointState localEpStatePtr = Gossiper.instance.getStateForVersionBiggerThan(addr, gDigest.getMaxVersion());
if (localEpStatePtr != null)
deltaEpStateMap.put(addr, localEpStatePtr);
}
MessageOut<GossipDigestAck2> gDigestAck2Message = new MessageOut<GossipDigestAck2>(MessagingService.Verb.GOSSIP_DIGEST_ACK2, new GossipDigestAck2(deltaEpStateMap), GossipDigestAck2.serializer);
if (logger.isTraceEnabled())
logger.trace("Sending a GossipDigestAck2Message to {}", from);
MessagingService.instance().sendOneWay(gDigestAck2Message, from);
}
use of org.apache.cassandra.net.MessageOut in project cassandra by apache.
the class Gossiper method doShadowRound.
/**
* Do a single 'shadow' round of gossip, where we do not modify any state
* Used when preparing to join the ring:
* * when replacing a node, to get and assume its tokens
* * when joining, to check that the local host id matches any previous id for the endpoint address
*/
public void doShadowRound() {
buildSeedsList();
// list in which case, attempting a shadow round is pointless
if (seeds.isEmpty())
return;
seedsInShadowRound.clear();
// send a completely empty syn
List<GossipDigest> gDigests = new ArrayList<GossipDigest>();
GossipDigestSyn digestSynMessage = new GossipDigestSyn(DatabaseDescriptor.getClusterName(), DatabaseDescriptor.getPartitionerName(), gDigests);
MessageOut<GossipDigestSyn> message = new MessageOut<GossipDigestSyn>(MessagingService.Verb.GOSSIP_DIGEST_SYN, digestSynMessage, GossipDigestSyn.serializer);
inShadowRound = true;
int slept = 0;
try {
while (true) {
if (slept % 5000 == 0) {
// CASSANDRA-8072, retry at the beginning and every 5 seconds
logger.trace("Sending shadow round GOSSIP DIGEST SYN to seeds {}", seeds);
for (InetAddress seed : seeds) MessagingService.instance().sendOneWay(message, seed);
}
Thread.sleep(1000);
if (!inShadowRound)
break;
slept += 1000;
if (slept > StorageService.RING_DELAY) {
// if we don't consider ourself to be a seed, fail out
if (!DatabaseDescriptor.getSeeds().contains(FBUtilities.getBroadcastAddress()))
throw new RuntimeException("Unable to gossip with any seeds");
logger.warn("Unable to gossip with any seeds but continuing since node is in its own seed list");
inShadowRound = false;
break;
}
}
} catch (InterruptedException wtf) {
throw new RuntimeException(wtf);
}
}
use of org.apache.cassandra.net.MessageOut in project cassandra by apache.
the class Gossiper method stop.
public void stop() {
EndpointState mystate = endpointStateMap.get(FBUtilities.getBroadcastAddress());
if (mystate != null && !isSilentShutdownState(mystate) && StorageService.instance.isJoined()) {
logger.info("Announcing shutdown");
addLocalApplicationState(ApplicationState.STATUS, StorageService.instance.valueFactory.shutdown(true));
MessageOut message = new MessageOut(MessagingService.Verb.GOSSIP_SHUTDOWN);
for (InetAddress ep : liveEndpoints) MessagingService.instance().sendOneWay(message, ep);
Uninterruptibles.sleepUninterruptibly(Integer.getInteger("cassandra.shutdown_announce_in_ms", 2000), TimeUnit.MILLISECONDS);
} else
logger.warn("No local state, state is in silent shutdown, or node hasn't joined, not announcing shutdown");
if (scheduledGossipTask != null)
scheduledGossipTask.cancel(false);
}
Aggregations