use of org.apache.cassandra.exceptions.RequestFailureReason in project cassandra by apache.
the class ActiveRepairService method prepareForRepair.
public UUID prepareForRepair(UUID parentRepairSession, InetAddressAndPort coordinator, Set<InetAddressAndPort> endpoints, RepairOption options, boolean isForcedRepair, List<ColumnFamilyStore> columnFamilyStores) {
if (!verifyCompactionsPendingThreshold(parentRepairSession, options.getPreviewKind()))
// failRepair throws exception
failRepair(parentRepairSession, "Rejecting incoming repair, pending compactions above threshold");
long repairedAt = getRepairedAt(options, isForcedRepair);
registerParentRepairSession(parentRepairSession, coordinator, columnFamilyStores, options.getRanges(), options.isIncremental(), repairedAt, options.isGlobal(), options.getPreviewKind());
final CountDownLatch prepareLatch = newCountDownLatch(endpoints.size());
final AtomicBoolean status = new AtomicBoolean(true);
final Set<String> failedNodes = synchronizedSet(new HashSet<String>());
final AtomicInteger timeouts = new AtomicInteger(0);
RequestCallback callback = new RequestCallback() {
@Override
public void onResponse(Message msg) {
prepareLatch.decrement();
}
@Override
public void onFailure(InetAddressAndPort from, RequestFailureReason failureReason) {
status.set(false);
failedNodes.add(from.toString());
if (failureReason == RequestFailureReason.TIMEOUT)
timeouts.incrementAndGet();
prepareLatch.decrement();
}
@Override
public boolean invokeOnFailure() {
return true;
}
};
List<TableId> tableIds = new ArrayList<>(columnFamilyStores.size());
for (ColumnFamilyStore cfs : columnFamilyStores) tableIds.add(cfs.metadata.id);
for (InetAddressAndPort neighbour : endpoints) {
if (FailureDetector.instance.isAlive(neighbour)) {
PrepareMessage message = new PrepareMessage(parentRepairSession, tableIds, options.getRanges(), options.isIncremental(), repairedAt, options.isGlobal(), options.getPreviewKind());
Message<RepairMessage> msg = out(PREPARE_MSG, message);
MessagingService.instance().sendWithCallback(msg, neighbour, callback);
} else {
// remaining ones go down, we still want to fail so we don't create repair sessions that can't complete
if (isForcedRepair && !options.isIncremental()) {
prepareLatch.decrement();
} else {
// bailout early to avoid potentially waiting for a long time.
failRepair(parentRepairSession, "Endpoint not alive: " + neighbour);
}
}
}
try {
if (!prepareLatch.await(getRpcTimeout(MILLISECONDS), MILLISECONDS) || timeouts.get() > 0)
failRepair(parentRepairSession, "Did not get replies from all endpoints.");
} catch (InterruptedException e) {
failRepair(parentRepairSession, "Interrupted while waiting for prepare repair response.");
}
if (!status.get()) {
failRepair(parentRepairSession, "Got negative replies from endpoints " + failedNodes);
}
return parentRepairSession;
}
use of org.apache.cassandra.exceptions.RequestFailureReason in project cassandra by apache.
the class InboundSink method fail.
public void fail(Message.Header header, Throwable failure) {
if (header.callBackOnFailure()) {
InetAddressAndPort to = header.respondTo() != null ? header.respondTo() : header.from;
Message<RequestFailureReason> response = Message.failureResponse(header.id, header.expiresAtNanos, RequestFailureReason.forException(failure));
messaging.send(response, to);
}
}
use of org.apache.cassandra.exceptions.RequestFailureReason in project cassandra by apache.
the class ErrorMessageTest method testRequestFailureExceptionMakesCopy.
/**
* Make sure that the map passed in to create a Read/WriteFailureException is copied
* so later modifications to the map passed in don't affect the map in the exception.
*
* This is to prevent potential issues in serialization if the map created in
* ReadCallback/AbstractWriteResponseHandler is modified due to a delayed failure
* response after the exception is created.
*/
@Test
public void testRequestFailureExceptionMakesCopy() throws UnknownHostException {
Map<InetAddressAndPort, RequestFailureReason> modifiableFailureReasons = new HashMap<>(failureReasonMap1);
ReadFailureException rfe = new ReadFailureException(ConsistencyLevel.ALL, 3, 3, false, modifiableFailureReasons);
WriteFailureException wfe = new WriteFailureException(ConsistencyLevel.ALL, 3, 3, WriteType.SIMPLE, modifiableFailureReasons);
modifiableFailureReasons.put(InetAddressAndPort.getByName("127.0.0.4"), RequestFailureReason.UNKNOWN);
assertEquals(failureReasonMap1, rfe.failureReasonByEndpoint);
assertEquals(failureReasonMap1, wfe.failureReasonByEndpoint);
}
use of org.apache.cassandra.exceptions.RequestFailureReason in project cassandra by apache.
the class ConnectionTest method testInsufficientSpace.
@Test
public void testInsufficientSpace() throws Throwable {
test(new Settings(null).outbound(settings -> settings.withApplicationReserveSendQueueCapacityInBytes(1 << 15, new ResourceLimits.Concurrent(1 << 16)).withApplicationSendQueueCapacityInBytes(1 << 16)), (inbound, outbound, endpoint) -> {
CountDownLatch done = new CountDownLatch(1);
Message<?> message = Message.out(Verb._TEST_1, new Object());
MessagingService.instance().callbacks.addWithExpiration(new RequestCallback() {
@Override
public void onFailure(InetAddressAndPort from, RequestFailureReason failureReason) {
done.countDown();
}
@Override
public boolean invokeOnFailure() {
return true;
}
@Override
public void onResponse(Message msg) {
throw new IllegalStateException();
}
}, message, endpoint);
AtomicInteger delivered = new AtomicInteger();
unsafeSetSerializer(Verb._TEST_1, () -> new IVersionedSerializer<Object>() {
public void serialize(Object o, DataOutputPlus out, int version) throws IOException {
for (int i = 0; i <= 4 << 16; i += 8L) out.writeLong(1L);
}
public Object deserialize(DataInputPlus in, int version) throws IOException {
in.skipBytesFully(4 << 16);
return null;
}
public long serializedSize(Object o, int version) {
return 4 << 16;
}
});
unsafeSetHandler(Verb._TEST_1, () -> msg -> delivered.incrementAndGet());
outbound.enqueue(message);
Assert.assertTrue(done.await(10, SECONDS));
Assert.assertEquals(0, delivered.get());
check(outbound).submitted(1).sent(0, 0).pending(0, 0).overload(1, message.serializedSize(current_version)).expired(0, 0).error(0, 0).check();
check(inbound).received(0, 0).processed(0, 0).pending(0, 0).expired(0, 0).error(0, 0).check();
});
}
Aggregations