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);
}
use of org.apache.cassandra.net.MessageOut in project cassandra by apache.
the class RepairMessageVerbHandler method doVerb.
public void doVerb(final MessageIn<RepairMessage> message, final int id) {
// TODO add cancel/interrupt message
RepairJobDesc desc = message.payload.desc;
try {
switch(message.payload.messageType) {
case PREPARE_MESSAGE:
PrepareMessage prepareMessage = (PrepareMessage) message.payload;
logger.debug("Preparing, {}", prepareMessage);
List<ColumnFamilyStore> columnFamilyStores = new ArrayList<>(prepareMessage.tableIds.size());
for (TableId tableId : prepareMessage.tableIds) {
ColumnFamilyStore columnFamilyStore = ColumnFamilyStore.getIfExists(tableId);
if (columnFamilyStore == null) {
logErrorAndSendFailureResponse(String.format("Table with id %s was dropped during prepare phase of repair", tableId), message.from, id);
return;
}
columnFamilyStores.add(columnFamilyStore);
}
ActiveRepairService.instance.registerParentRepairSession(prepareMessage.parentRepairSession, message.from, columnFamilyStores, prepareMessage.ranges, prepareMessage.isIncremental, prepareMessage.timestamp, prepareMessage.isGlobal);
MessagingService.instance().sendReply(new MessageOut(MessagingService.Verb.INTERNAL_RESPONSE), id, message.from);
break;
case SNAPSHOT:
logger.debug("Snapshotting {}", desc);
final ColumnFamilyStore cfs = ColumnFamilyStore.getIfExists(desc.keyspace, desc.columnFamily);
if (cfs == null) {
logErrorAndSendFailureResponse(String.format("Table %s.%s was dropped during snapshot phase of repair", desc.keyspace, desc.columnFamily), message.from, id);
return;
}
ActiveRepairService.ParentRepairSession prs = ActiveRepairService.instance.getParentRepairSession(desc.parentSessionId);
if (prs.isGlobal) {
prs.maybeSnapshot(cfs.metadata.id, desc.parentSessionId);
} else {
cfs.snapshot(desc.sessionId.toString(), new Predicate<SSTableReader>() {
public boolean apply(SSTableReader sstable) {
return sstable != null && // exclude SSTables from 2i
!sstable.metadata().isIndex() && new Bounds<>(sstable.first.getToken(), sstable.last.getToken()).intersects(desc.ranges);
}
}, true, //ephemeral snapshot, if repair fails, it will be cleaned next startup
false);
}
logger.debug("Enqueuing response to snapshot request {} to {}", desc.sessionId, message.from);
MessagingService.instance().sendReply(new MessageOut(MessagingService.Verb.INTERNAL_RESPONSE), id, message.from);
break;
case VALIDATION_REQUEST:
ValidationRequest validationRequest = (ValidationRequest) message.payload;
logger.debug("Validating {}", validationRequest);
// trigger read-only compaction
ColumnFamilyStore store = ColumnFamilyStore.getIfExists(desc.keyspace, desc.columnFamily);
if (store == null) {
logger.error("Table {}.{} was dropped during snapshot phase of repair", desc.keyspace, desc.columnFamily);
MessagingService.instance().sendOneWay(new ValidationComplete(desc).createMessage(), message.from);
return;
}
ActiveRepairService.instance.consistent.local.maybeSetRepairing(desc.parentSessionId);
Validator validator = new Validator(desc, message.from, validationRequest.gcBefore, isConsistent(desc.parentSessionId));
CompactionManager.instance.submitValidation(store, validator);
break;
case SYNC_REQUEST:
// forwarded sync request
SyncRequest request = (SyncRequest) message.payload;
logger.debug("Syncing {}", request);
long repairedAt = ActiveRepairService.UNREPAIRED_SSTABLE;
if (desc.parentSessionId != null && ActiveRepairService.instance.getParentRepairSession(desc.parentSessionId) != null)
repairedAt = ActiveRepairService.instance.getParentRepairSession(desc.parentSessionId).getRepairedAt();
StreamingRepairTask task = new StreamingRepairTask(desc, request, repairedAt, isConsistent(desc.parentSessionId));
task.run();
break;
case CLEANUP:
logger.debug("cleaning up repair");
CleanupMessage cleanup = (CleanupMessage) message.payload;
ActiveRepairService.instance.removeParentRepairSession(cleanup.parentRepairSession);
MessagingService.instance().sendReply(new MessageOut(MessagingService.Verb.INTERNAL_RESPONSE), id, message.from);
break;
case CONSISTENT_REQUEST:
ActiveRepairService.instance.consistent.local.handlePrepareMessage(message.from, (PrepareConsistentRequest) message.payload);
break;
case CONSISTENT_RESPONSE:
ActiveRepairService.instance.consistent.coordinated.handlePrepareResponse((PrepareConsistentResponse) message.payload);
break;
case FINALIZE_PROPOSE:
ActiveRepairService.instance.consistent.local.handleFinalizeProposeMessage(message.from, (FinalizePropose) message.payload);
break;
case FINALIZE_PROMISE:
ActiveRepairService.instance.consistent.coordinated.handleFinalizePromiseMessage((FinalizePromise) message.payload);
break;
case FINALIZE_COMMIT:
ActiveRepairService.instance.consistent.local.handleFinalizeCommitMessage(message.from, (FinalizeCommit) message.payload);
break;
case FAILED_SESSION:
FailSession failure = (FailSession) message.payload;
ActiveRepairService.instance.consistent.coordinated.handleFailSessionMessage(failure);
ActiveRepairService.instance.consistent.local.handleFailSessionMessage(message.from, failure);
break;
case STATUS_REQUEST:
ActiveRepairService.instance.consistent.local.handleStatusRequest(message.from, (StatusRequest) message.payload);
break;
case STATUS_RESPONSE:
ActiveRepairService.instance.consistent.local.handleStatusResponse(message.from, (StatusResponse) message.payload);
break;
default:
ActiveRepairService.instance.handleMessage(message.from, message.payload);
break;
}
} catch (Exception e) {
logger.error("Got error, removing parent repair session");
if (desc != null && desc.parentSessionId != null)
ActiveRepairService.instance.removeParentRepairSession(desc.parentSessionId);
throw new RuntimeException(e);
}
}
use of org.apache.cassandra.net.MessageOut in project cassandra by apache.
the class ReplicationFinishedVerbHandler method doVerb.
public void doVerb(MessageIn msg, int id) {
StorageService.instance.confirmReplication(msg.from);
MessageOut response = new MessageOut(MessagingService.Verb.INTERNAL_RESPONSE);
if (logger.isDebugEnabled())
logger.debug("Replying to {}@{}", id, msg.from);
MessagingService.instance().sendReply(response, id, msg.from);
}
use of org.apache.cassandra.net.MessageOut in project cassandra by apache.
the class ReadCommandVerbHandler method doVerb.
public void doVerb(MessageIn<ReadCommand> message, int id) {
if (StorageService.instance.isBootstrapMode()) {
throw new RuntimeException("Cannot service reads while bootstrapping!");
}
ReadCommand command = message.payload;
command.setMonitoringTime(message.constructionTime, message.isCrossNode(), message.getTimeout(), message.getSlowQueryTimeout());
ReadResponse response;
try (ReadExecutionController executionController = command.executionController();
UnfilteredPartitionIterator iterator = command.executeLocally(executionController)) {
response = command.createResponse(iterator);
}
if (!command.complete()) {
Tracing.trace("Discarding partial response to {} (timed out)", message.from);
MessagingService.instance().incrementDroppedMessages(message, message.getLifetimeInMS());
return;
}
Tracing.trace("Enqueuing response to {}", message.from);
MessageOut<ReadResponse> reply = new MessageOut<>(MessagingService.Verb.REQUEST_RESPONSE, response, serializer());
MessagingService.instance().sendReply(reply, id, message.from);
}
use of org.apache.cassandra.net.MessageOut in project cassandra by apache.
the class GossipDigestSynVerbHandler method doVerb.
public void doVerb(MessageIn<GossipDigestSyn> message, int id) {
InetAddress from = message.from;
if (logger.isTraceEnabled())
logger.trace("Received a GossipDigestSynMessage from {}", from);
if (!Gossiper.instance.isEnabled() && !Gossiper.instance.isInShadowRound()) {
if (logger.isTraceEnabled())
logger.trace("Ignoring GossipDigestSynMessage because gossip is disabled");
return;
}
GossipDigestSyn gDigestMessage = message.payload;
/* 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;
}
if (gDigestMessage.partioner != null && !gDigestMessage.partioner.equals(DatabaseDescriptor.getPartitionerName())) {
logger.warn("Partitioner mismatch from {} {}!={}", from, gDigestMessage.partioner, DatabaseDescriptor.getPartitionerName());
return;
}
List<GossipDigest> gDigestList = gDigestMessage.getGossipDigests();
// are in their shadow round
if (!Gossiper.instance.isEnabled() && Gossiper.instance.isInShadowRound()) {
// doing a shadow round) will always contain > 0 digests
if (gDigestList.size() > 0) {
logger.debug("Ignoring non-empty GossipDigestSynMessage because currently in gossip shadow round");
return;
}
logger.debug("Received a shadow round syn from {}. Gossip is disabled but " + "currently also in shadow round, responding with a minimal ack", from);
MessagingService.instance().sendOneWay(new MessageOut<>(MessagingService.Verb.GOSSIP_DIGEST_ACK, new GossipDigestAck(new ArrayList<>(), new HashMap<>()), GossipDigestAck.serializer), from);
return;
}
if (logger.isTraceEnabled()) {
StringBuilder sb = new StringBuilder();
for (GossipDigest gDigest : gDigestList) {
sb.append(gDigest);
sb.append(" ");
}
logger.trace("Gossip syn digests are : {}", sb);
}
doSort(gDigestList);
List<GossipDigest> deltaGossipDigestList = new ArrayList<GossipDigest>();
Map<InetAddress, EndpointState> deltaEpStateMap = new HashMap<InetAddress, EndpointState>();
Gossiper.instance.examineGossiper(gDigestList, deltaGossipDigestList, deltaEpStateMap);
logger.trace("sending {} digests and {} deltas", deltaGossipDigestList.size(), deltaEpStateMap.size());
MessageOut<GossipDigestAck> gDigestAckMessage = new MessageOut<GossipDigestAck>(MessagingService.Verb.GOSSIP_DIGEST_ACK, new GossipDigestAck(deltaGossipDigestList, deltaEpStateMap), GossipDigestAck.serializer);
if (logger.isTraceEnabled())
logger.trace("Sending a GossipDigestAckMessage to {}", from);
MessagingService.instance().sendOneWay(gDigestAckMessage, from);
}
Aggregations