Search in sources :

Example 11 with SinglePartitionReadCommand

use of org.apache.cassandra.db.SinglePartitionReadCommand in project cassandra by apache.

the class Ballots method latestBallotFromBaseTable.

public static long latestBallotFromBaseTable(DecoratedKey key, TableMetadata metadata) {
    SinglePartitionReadCommand cmd = SinglePartitionReadCommand.create(metadata, 0, key, Slice.ALL);
    ImmutableBTreePartition partition;
    try (ReadExecutionController controller = cmd.executionController();
        UnfilteredPartitionIterator partitions = cmd.executeLocally(controller)) {
        if (!partitions.hasNext())
            return 0L;
        try (UnfilteredRowIterator rows = partitions.next()) {
            partition = ImmutableBTreePartition.create(rows);
        }
    }
    return latestBallot(partition);
}
Also used : ReadExecutionController(org.apache.cassandra.db.ReadExecutionController) UnfilteredRowIterator(org.apache.cassandra.db.rows.UnfilteredRowIterator) SinglePartitionReadCommand(org.apache.cassandra.db.SinglePartitionReadCommand) UnfilteredPartitionIterator(org.apache.cassandra.db.partitions.UnfilteredPartitionIterator) ImmutableBTreePartition(org.apache.cassandra.db.partitions.ImmutableBTreePartition)

Example 12 with SinglePartitionReadCommand

use of org.apache.cassandra.db.SinglePartitionReadCommand in project cassandra by apache.

the class DigestResolverTest method digestMismatch.

@Test
public void digestMismatch() {
    SinglePartitionReadCommand command = SinglePartitionReadCommand.fullPartitionRead(cfm, nowInSec, dk);
    EndpointsForToken targetReplicas = EndpointsForToken.of(dk.getToken(), full(EP1), full(EP2));
    DigestResolver resolver = new DigestResolver(command, plan(ConsistencyLevel.QUORUM, targetReplicas), 0);
    PartitionUpdate response1 = update(row(1000, 4, 4), row(1000, 5, 5)).build();
    PartitionUpdate response2 = update(row(2000, 4, 5)).build();
    Assert.assertFalse(resolver.isDataPresent());
    resolver.preprocess(response(command, EP2, iter(response1), true));
    resolver.preprocess(response(command, EP1, iter(response2), false));
    Assert.assertTrue(resolver.isDataPresent());
    Assert.assertFalse(resolver.responsesMatch());
    Assert.assertFalse(resolver.hasTransientResponse());
}
Also used : EndpointsForToken(org.apache.cassandra.locator.EndpointsForToken) SinglePartitionReadCommand(org.apache.cassandra.db.SinglePartitionReadCommand) PartitionUpdate(org.apache.cassandra.db.partitions.PartitionUpdate) Test(org.junit.Test)

Example 13 with SinglePartitionReadCommand

use of org.apache.cassandra.db.SinglePartitionReadCommand in project cassandra by apache.

the class DigestResolverTest method noRepairNeeded.

@Test
public void noRepairNeeded() {
    SinglePartitionReadCommand command = SinglePartitionReadCommand.fullPartitionRead(cfm, nowInSec, dk);
    EndpointsForToken targetReplicas = EndpointsForToken.of(dk.getToken(), full(EP1), full(EP2));
    DigestResolver resolver = new DigestResolver(command, plan(ConsistencyLevel.QUORUM, targetReplicas), 0);
    PartitionUpdate response = update(row(1000, 4, 4), row(1000, 5, 5)).build();
    Assert.assertFalse(resolver.isDataPresent());
    resolver.preprocess(response(command, EP2, iter(response), true));
    resolver.preprocess(response(command, EP1, iter(response), false));
    Assert.assertTrue(resolver.isDataPresent());
    Assert.assertTrue(resolver.responsesMatch());
    assertPartitionsEqual(filter(iter(response)), resolver.getData());
}
Also used : EndpointsForToken(org.apache.cassandra.locator.EndpointsForToken) SinglePartitionReadCommand(org.apache.cassandra.db.SinglePartitionReadCommand) PartitionUpdate(org.apache.cassandra.db.partitions.PartitionUpdate) Test(org.junit.Test)

Example 14 with SinglePartitionReadCommand

use of org.apache.cassandra.db.SinglePartitionReadCommand in project cassandra by apache.

the class DigestResolverTest method agreeingTransient.

/**
 * A full response and a transient response, with the transient response being a subset of the full one
 */
@Test
public void agreeingTransient() {
    SinglePartitionReadCommand command = SinglePartitionReadCommand.fullPartitionRead(cfm, nowInSec, dk);
    EndpointsForToken targetReplicas = EndpointsForToken.of(dk.getToken(), full(EP1), trans(EP2));
    DigestResolver<?, ?> resolver = new DigestResolver<>(command, plan(ConsistencyLevel.QUORUM, targetReplicas), 0);
    PartitionUpdate response1 = update(row(1000, 4, 4), row(1000, 5, 5)).build();
    PartitionUpdate response2 = update(row(1000, 5, 5)).build();
    Assert.assertFalse(resolver.isDataPresent());
    resolver.preprocess(response(command, EP1, iter(response1), false));
    resolver.preprocess(response(command, EP2, iter(response2), false));
    Assert.assertTrue(resolver.isDataPresent());
    Assert.assertTrue(resolver.responsesMatch());
    Assert.assertTrue(resolver.hasTransientResponse());
}
Also used : EndpointsForToken(org.apache.cassandra.locator.EndpointsForToken) SinglePartitionReadCommand(org.apache.cassandra.db.SinglePartitionReadCommand) PartitionUpdate(org.apache.cassandra.db.partitions.PartitionUpdate) Test(org.junit.Test)

Aggregations

SinglePartitionReadCommand (org.apache.cassandra.db.SinglePartitionReadCommand)14 PartitionUpdate (org.apache.cassandra.db.partitions.PartitionUpdate)7 Test (org.junit.Test)7 EndpointsForToken (org.apache.cassandra.locator.EndpointsForToken)6 ReadExecutionController (org.apache.cassandra.db.ReadExecutionController)3 UnfilteredRowIterator (org.apache.cassandra.db.rows.UnfilteredRowIterator)3 InvalidRequestException (org.apache.cassandra.exceptions.InvalidRequestException)3 TableMetadata (org.apache.cassandra.schema.TableMetadata)3 ConsistencyLevel (org.apache.cassandra.db.ConsistencyLevel)2 DecoratedKey (org.apache.cassandra.db.DecoratedKey)2 FilteredPartition (org.apache.cassandra.db.partitions.FilteredPartition)2 PartitionIterator (org.apache.cassandra.db.partitions.PartitionIterator)2 UnfilteredPartitionIterator (org.apache.cassandra.db.partitions.UnfilteredPartitionIterator)2 RowIterator (org.apache.cassandra.db.rows.RowIterator)2 CasWriteTimeoutException (org.apache.cassandra.exceptions.CasWriteTimeoutException)2 ReadAbortException (org.apache.cassandra.exceptions.ReadAbortException)2 ReadFailureException (org.apache.cassandra.exceptions.ReadFailureException)2 ReadTimeoutException (org.apache.cassandra.exceptions.ReadTimeoutException)2 UnavailableException (org.apache.cassandra.exceptions.UnavailableException)2 WriteFailureException (org.apache.cassandra.exceptions.WriteFailureException)2