use of org.apache.cassandra.net.MessageOut 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.MessageOut in project cassandra by apache.
the class ValidatorTest method testValidatorFailed.
@Test
public void testValidatorFailed() throws Throwable {
Range<Token> range = new Range<>(partitioner.getMinimumToken(), partitioner.getRandomToken());
final RepairJobDesc desc = new RepairJobDesc(UUID.randomUUID(), UUID.randomUUID(), keyspace, columnFamily, Arrays.asList(range));
final CompletableFuture<MessageOut> outgoingMessageSink = registerOutgoingMessageSink();
InetAddress remote = InetAddress.getByName("127.0.0.2");
Validator validator = new Validator(desc, remote, 0);
validator.fail();
MessageOut message = outgoingMessageSink.get(TEST_TIMEOUT, TimeUnit.SECONDS);
assertEquals(MessagingService.Verb.REPAIR_MESSAGE, message.verb);
RepairMessage m = (RepairMessage) message.payload;
assertEquals(RepairMessage.Type.VALIDATION_COMPLETE, m.messageType);
assertEquals(desc, m.desc);
assertFalse(((ValidationComplete) m).success());
assertNull(((ValidationComplete) m).trees);
}
use of org.apache.cassandra.net.MessageOut in project cassandra by apache.
the class RemoveTest method testRemoveHostId.
@Test
public void testRemoveHostId() throws InterruptedException {
// start removal in background and send replication confirmations
final AtomicBoolean success = new AtomicBoolean(false);
Thread remover = NamedThreadFactory.createThread(() -> {
try {
ss.removeNode(removalId.toString());
} catch (Exception e) {
System.err.println(e);
e.printStackTrace();
return;
}
success.set(true);
});
remover.start();
// make sure removal is waiting for confirmation
Thread.sleep(1000);
assertTrue(tmd.isLeaving(removalhost));
assertEquals(1, tmd.getSizeOfLeavingEndpoints());
for (InetAddress host : hosts) {
MessageOut msg = new MessageOut(host, MessagingService.Verb.REPLICATION_FINISHED, null, null, Collections.<String, byte[]>emptyMap());
MessagingService.instance().sendRR(msg, FBUtilities.getBroadcastAddress());
}
remover.join();
assertTrue(success.get());
assertTrue(tmd.getSizeOfLeavingEndpoints() == 0);
}
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);
}
}
Aggregations