use of org.apache.cassandra.locator.InetAddressAndPort in project cassandra by apache.
the class HintVerbHandler method doVerb.
public void doVerb(Message<HintMessage> message) {
UUID hostId = message.payload.hostId;
Hint hint = message.payload.hint;
InetAddressAndPort 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);
respond(message);
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);
respond(message);
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);
respond(message);
} 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);
respond(message);
} else {
// the common path - the node is both the destination and a valid replica for the hint.
hint.applyFuture().addCallback(o -> respond(message), e -> logger.debug("Failed to apply hint", e));
}
}
use of org.apache.cassandra.locator.InetAddressAndPort in project cassandra by apache.
the class HintsService method deleteAllHintsForEndpoint.
/**
* Deletes all hints for the provided destination. Doesn't make snapshots - should be used with care.
*
* @param address inet address of the target node - encoded as a string for easier JMX consumption
*/
public void deleteAllHintsForEndpoint(String address) {
InetAddressAndPort target;
try {
target = InetAddressAndPort.getByName(address);
} catch (UnknownHostException e) {
throw new IllegalArgumentException(e);
}
deleteAllHintsForEndpoint(target);
}
use of org.apache.cassandra.locator.InetAddressAndPort in project cassandra by apache.
the class ReadCallback method onResponse.
@Override
public void onResponse(Message<ReadResponse> message) {
assertWaitingFor(message.from());
Map<ParamType, Object> params = message.header.params();
InetAddressAndPort from = message.from();
if (WarningContext.isSupported(params.keySet())) {
RequestFailureReason reason = getWarningContext().updateCounters(params, from);
if (reason != null) {
onFailure(message.from(), reason);
return;
}
}
resolver.preprocess(message);
/*
* Ensure that data is present and the response accumulator has properly published the
* responses it has received. This may result in not signaling immediately when we receive
* the minimum number of required results, but it guarantees at least the minimum will
* be accessible when we do signal. (see CASSANDRA-16807)
*/
if (resolver.isDataPresent() && resolver.responses.size() >= blockFor)
condition.signalAll();
}
use of org.apache.cassandra.locator.InetAddressAndPort in project cassandra by apache.
the class RowIteratorMergeListener method close.
public void close() {
boolean hasRepairs = false;
for (int i = 0; !hasRepairs && i < repairs.length; ++i) hasRepairs = repairs[i] != null;
if (!hasRepairs)
return;
PartitionUpdate fullDiffRepair = null;
if (buildFullDiff && repairs[repairs.length - 1] != null)
fullDiffRepair = repairs[repairs.length - 1].build();
Map<Replica, Mutation> mutations = Maps.newHashMapWithExpectedSize(writePlan.contacts().size());
ObjectIntHashMap<InetAddressAndPort> sourceIds = new ObjectIntHashMap<>(((repairs.length + 1) * 4) / 3);
for (int i = 0; i < readPlan.contacts().size(); ++i) sourceIds.put(readPlan.contacts().get(i).endpoint(), 1 + i);
for (Replica replica : writePlan.contacts()) {
PartitionUpdate update = null;
int i = -1 + sourceIds.get(replica.endpoint());
if (i < 0)
update = fullDiffRepair;
else if (repairs[i] != null)
update = repairs[i].build();
Mutation mutation = BlockingReadRepairs.createRepairMutation(update, readPlan.consistencyLevel(), replica.endpoint(), false);
if (mutation == null)
continue;
mutations.put(replica, mutation);
}
readRepair.repairPartition(partitionKey, mutations, writePlan);
}
use of org.apache.cassandra.locator.InetAddressAndPort in project cassandra by apache.
the class GossipTest method nodeDownDuringMove.
@Test
public void nodeDownDuringMove() throws Throwable {
int liveCount = 1;
try (Cluster cluster = Cluster.build(2 + liveCount).withConfig(config -> config.with(NETWORK).with(GOSSIP)).createWithoutStarting()) {
int fail = liveCount + 1;
int late = fail + 1;
for (int i = 1; i <= liveCount; ++i) cluster.get(i).startup();
cluster.get(fail).startup();
Collection<String> expectTokens = cluster.get(fail).callsOnInstance(() -> StorageService.instance.getTokenMetadata().getTokens(FBUtilities.getBroadcastAddressAndPort()).stream().map(Object::toString).collect(Collectors.toList())).call();
InetSocketAddress failAddress = cluster.get(fail).broadcastAddress();
// wait for NORMAL state
for (int i = 1; i <= liveCount; ++i) {
cluster.get(i).acceptsOnInstance((InetSocketAddress address) -> {
EndpointState ep;
InetAddressAndPort endpoint = toCassandraInetAddressAndPort(address);
while (null == (ep = Gossiper.instance.getEndpointStateForEndpoint(endpoint)) || ep.getApplicationState(ApplicationState.STATUS_WITH_PORT) == null || !ep.getApplicationState(ApplicationState.STATUS_WITH_PORT).value.startsWith("NORMAL")) LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(10L));
}).accept(failAddress);
}
// set ourselves to MOVING, and wait for it to propagate
cluster.get(fail).runOnInstance(() -> {
Token token = Iterables.getFirst(StorageService.instance.getTokenMetadata().getTokens(FBUtilities.getBroadcastAddressAndPort()), null);
Gossiper.instance.addLocalApplicationState(ApplicationState.STATUS_WITH_PORT, StorageService.instance.valueFactory.moving(token));
});
for (int i = 1; i <= liveCount; ++i) {
cluster.get(i).acceptsOnInstance((InetSocketAddress address) -> {
EndpointState ep;
InetAddressAndPort endpoint = toCassandraInetAddressAndPort(address);
while (null == (ep = Gossiper.instance.getEndpointStateForEndpoint(endpoint)) || (ep.getApplicationState(ApplicationState.STATUS_WITH_PORT) == null || !ep.getApplicationState(ApplicationState.STATUS_WITH_PORT).value.startsWith("MOVING"))) LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(100L));
}).accept(failAddress);
}
cluster.get(fail).shutdown(false).get();
cluster.get(late).startup();
cluster.get(late).acceptsOnInstance((InetSocketAddress address) -> {
EndpointState ep;
InetAddressAndPort endpoint = toCassandraInetAddressAndPort(address);
while (null == (ep = Gossiper.instance.getEndpointStateForEndpoint(endpoint)) || !ep.getApplicationState(ApplicationState.STATUS_WITH_PORT).value.startsWith("MOVING")) LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(100L));
}).accept(failAddress);
Collection<String> tokens = cluster.get(late).appliesOnInstance((InetSocketAddress address) -> StorageService.instance.getTokenMetadata().getTokens(toCassandraInetAddressAndPort(address)).stream().map(Object::toString).collect(Collectors.toList())).apply(failAddress);
Assert.assertEquals(expectTokens, tokens);
}
}
Aggregations