use of org.apache.cassandra.service.reads.trackwarnings.WarningsSnapshot in project cassandra by apache.
the class ReadCallback method awaitResults.
public void awaitResults() throws ReadFailureException, ReadTimeoutException {
boolean signaled = await(command.getTimeout(MILLISECONDS), TimeUnit.MILLISECONDS);
/**
* Here we are checking isDataPresent in addition to the responses size because there is a possibility
* that an asynchronous speculative execution request could be returning after a local failure already
* signaled. Responses may have been set while the data reference is not yet.
* See {@link DigestResolver#preprocess(Message)}
* CASSANDRA-16097
*/
int received = resolver.responses.size();
boolean failed = failures > 0 && (blockFor > received || !resolver.isDataPresent());
WarningContext warnings = warningContext;
// save the snapshot so abort state is not changed between now and when mayAbort gets called
WarningsSnapshot snapshot = null;
if (warnings != null) {
snapshot = warnings.snapshot();
// this is likely to happen when a timeout happens or from a speculative response
if (!snapshot.isEmpty())
CoordinatorWarnings.update(command, snapshot);
}
if (signaled && !failed)
return;
if (isTracing()) {
String gotData = received > 0 ? (resolver.isDataPresent() ? " (including data)" : " (only digests)") : "";
Tracing.trace("{}; received {} of {} responses{}", failed ? "Failed" : "Timed out", received, blockFor, gotData);
} else if (logger.isDebugEnabled()) {
String gotData = received > 0 ? (resolver.isDataPresent() ? " (including data)" : " (only digests)") : "";
logger.debug("{}; received {} of {} responses{}", failed ? "Failed" : "Timed out", received, blockFor, gotData);
}
if (snapshot != null)
snapshot.maybeAbort(command, replicaPlan().consistencyLevel(), received, blockFor, resolver.isDataPresent(), failureReasonByEndpoint);
// Same as for writes, see AbstractWriteResponseHandler
throw failed ? new ReadFailureException(replicaPlan().consistencyLevel(), received, blockFor, resolver.isDataPresent(), failureReasonByEndpoint) : new ReadTimeoutException(replicaPlan().consistencyLevel(), received, blockFor, resolver.isDataPresent());
}
use of org.apache.cassandra.service.reads.trackwarnings.WarningsSnapshot in project cassandra by apache.
the class WarningsSnapshotTest method mergeEmtpy.
@Test
public void mergeEmtpy() {
WarningsSnapshot result = empty().merge(empty());
assertThat(result).isEqualTo(empty());
}
use of org.apache.cassandra.service.reads.trackwarnings.WarningsSnapshot in project cassandra by apache.
the class WarningsSnapshotTest method mergeConflict.
@Test
public void mergeConflict() {
WarningsSnapshot a = builder().tombstonesAbort(ImmutableSet.of(HOME), 42).build();
WarningsSnapshot b = builder().tombstonesAbort(ImmutableSet.of(VACATION_HOME), 12).build();
WarningsSnapshot expected = builder().tombstonesAbort(ImmutableSet.of(HOME, VACATION_HOME), 42).build();
// validate builder to protect against empty = empty passing this test
assertThat(a.tombstones.aborts.instances).isEqualTo(ImmutableSet.of(HOME));
assertThat(a.tombstones.aborts.maxValue).isEqualTo(42);
assertThat(b.tombstones.aborts.instances).isEqualTo(ImmutableSet.of(VACATION_HOME));
assertThat(b.tombstones.aborts.maxValue).isEqualTo(12);
assertThat(expected.tombstones.aborts.instances).isEqualTo(ImmutableSet.of(HOME, VACATION_HOME));
assertThat(expected.tombstones.aborts.maxValue).isEqualTo(42);
WarningsSnapshot output = a.merge(b);
assertThat(output).isEqualTo(expected).isEqualTo(expected.merge(empty()));
assertThat(output.merge(expected)).isEqualTo(expected);
}
use of org.apache.cassandra.service.reads.trackwarnings.WarningsSnapshot in project cassandra by apache.
the class WarningsSnapshotTest method mergeNonEmpty.
@Test
public void mergeNonEmpty() {
WarningsSnapshot expected = builder().tombstonesAbort(ImmutableSet.of(HOME), 42).localReadSizeWarning(ImmutableSet.of(VACATION_HOME), 12).build();
// validate builder to protect against empty = empty passing this test
assertThat(expected.tombstones.aborts.instances).isEqualTo(ImmutableSet.of(HOME));
assertThat(expected.tombstones.aborts.maxValue).isEqualTo(42);
assertThat(expected.localReadSize.warnings.instances).isEqualTo(ImmutableSet.of(VACATION_HOME));
assertThat(expected.localReadSize.warnings.maxValue).isEqualTo(12);
WarningsSnapshot output = empty().merge(expected);
assertThat(output).isEqualTo(expected).isEqualTo(expected.merge(empty()));
assertThat(output.merge(expected)).isEqualTo(expected);
}
use of org.apache.cassandra.service.reads.trackwarnings.WarningsSnapshot in project cassandra by apache.
the class WarningsSnapshotTest method staticMergeEmtpy.
@Test
public void staticMergeEmtpy() {
WarningsSnapshot result = merge(null, empty(), null, empty());
assertThat(result).isNull();
}
Aggregations