use of org.apache.cassandra.net.MessageIn 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.MessageIn in project cassandra by apache.
the class HintVerbHandler method doVerb.
public void doVerb(MessageIn<HintMessage> message, int id) {
UUID hostId = message.payload.hostId;
Hint hint = message.payload.hint;
InetAddress address = StorageService.instance.getEndpointForHostId(hostId);
// is schema agreement between the sender and the receiver.
if (hint == null) {
logger.trace("Failed to decode and apply a hint for {}: {} - table with id {} is unknown", address, hostId, message.payload.unknownTableID);
reply(id, message.from);
return;
}
// We must perform validation before applying the hint, and there is no other place to do it other than here.
try {
hint.mutation.getPartitionUpdates().forEach(PartitionUpdate::validate);
} catch (MarshalException e) {
logger.warn("Failed to validate a hint for {}: {} - skipped", address, hostId);
reply(id, message.from);
return;
}
if (!hostId.equals(StorageService.instance.getLocalHostUUID())) {
// the node is not the final destination of the hint (must have gotten it from a decommissioning node),
// so just store it locally, to be delivered later.
HintsService.instance.write(hostId, hint);
reply(id, message.from);
} else if (!StorageProxy.instance.appliesLocally(hint.mutation)) {
// the topology has changed, and we are no longer a replica of the mutation - since we don't know which node(s)
// it has been handed over to, re-address the hint to all replicas; see CASSANDRA-5902.
HintsService.instance.writeForAllReplicas(hint);
reply(id, message.from);
} else {
// the common path - the node is both the destination and a valid replica for the hint.
hint.applyFuture().thenAccept(o -> reply(id, message.from)).exceptionally(e -> {
logger.debug("Failed to apply hint", e);
return null;
});
}
}
use of org.apache.cassandra.net.MessageIn in project cassandra by apache.
the class AbstractPendingRepairTest method setupClass.
@BeforeClass
public static void setupClass() {
SchemaLoader.prepareServer();
ARS = ActiveRepairService.instance;
LocalSessionAccessor.startup();
// cutoff messaging service
MessagingService.instance().addMessageSink(new IMessageSink() {
public boolean allowOutgoingMessage(MessageOut message, int id, InetAddress to) {
return false;
}
public boolean allowIncomingMessage(MessageIn message, int id) {
return false;
}
});
}
use of org.apache.cassandra.net.MessageIn in project cassandra by apache.
the class ValidatorTest method registerOutgoingMessageSink.
private CompletableFuture<MessageOut> registerOutgoingMessageSink() {
final CompletableFuture<MessageOut> future = new CompletableFuture<>();
MessagingService.instance().addMessageSink(new IMessageSink() {
public boolean allowOutgoingMessage(MessageOut message, int id, InetAddress to) {
future.complete(message);
return false;
}
public boolean allowIncomingMessage(MessageIn message, int id) {
return false;
}
});
return future;
}
use of org.apache.cassandra.net.MessageIn in project cassandra by apache.
the class Gossiper method markAlive.
private void markAlive(final InetAddress addr, final EndpointState localState) {
localState.markDead();
MessageOut<EchoMessage> echoMessage = new MessageOut<EchoMessage>(MessagingService.Verb.ECHO, EchoMessage.instance, EchoMessage.serializer);
logger.trace("Sending a EchoMessage to {}", addr);
IAsyncCallback echoHandler = new IAsyncCallback() {
public boolean isLatencyForSnitch() {
return false;
}
public void response(MessageIn msg) {
realMarkAlive(addr, localState);
}
};
MessagingService.instance().sendRR(echoMessage, addr, echoHandler);
}
Aggregations