Search in sources :

Example 31 with EndpointsForRange

use of org.apache.cassandra.locator.EndpointsForRange in project cassandra by apache.

the class DataResolverTest method testResolveNewCollectionOverwritingDeleted.

@Test
public void testResolveNewCollectionOverwritingDeleted() {
    EndpointsForRange replicas = makeReplicas(2);
    ReadCommand cmd = Util.cmd(cfs2, dk).withNowInSeconds(nowInSec).build();
    TestableReadRepair readRepair = new TestableReadRepair(cmd);
    DataResolver resolver = new DataResolver(cmd, plan(replicas, ALL), readRepair, nanoTime());
    long[] ts = { 100, 200 };
    // cleared map column
    Row.Builder builder = BTreeRow.unsortedBuilder();
    builder.newRow(Clustering.EMPTY);
    builder.addComplexDeletion(m, new DeletionTime(ts[0] - 1, nowInSec));
    InetAddressAndPort peer1 = replicas.get(0).endpoint();
    resolver.preprocess(response(cmd, peer1, iter(PartitionUpdate.singleRowUpdate(cfm2, dk, builder.build()))));
    // newer, overwritten map column
    builder.newRow(Clustering.EMPTY);
    DeletionTime expectedCmplxDelete = new DeletionTime(ts[1] - 1, nowInSec);
    builder.addComplexDeletion(m, expectedCmplxDelete);
    Cell<?> expectedCell = mapCell(1, 1, ts[1]);
    builder.addCell(expectedCell);
    InetAddressAndPort peer2 = replicas.get(1).endpoint();
    resolver.preprocess(response(cmd, peer2, iter(PartitionUpdate.singleRowUpdate(cfm2, dk, builder.build()))));
    try (PartitionIterator data = resolver.resolve()) {
        try (RowIterator rows = Iterators.getOnlyElement(data)) {
            Row row = Iterators.getOnlyElement(rows);
            assertColumns(row, "m");
            ComplexColumnData cd = row.getComplexColumnData(m);
            assertEquals(Collections.singleton(expectedCell), Sets.newHashSet(cd));
        }
    }
    Row row = Iterators.getOnlyElement(readRepair.getForEndpoint(peer1).getPartitionUpdate(cfm2).iterator());
    ComplexColumnData cd = row.getComplexColumnData(m);
    assertEquals(Collections.singleton(expectedCell), Sets.newHashSet(cd));
    assertEquals(expectedCmplxDelete, cd.complexDeletion());
    Assert.assertNull(readRepair.sent.get(peer2));
}
Also used : InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) TestableReadRepair(org.apache.cassandra.service.reads.repair.TestableReadRepair) DeletionTime(org.apache.cassandra.db.DeletionTime) ReadCommand(org.apache.cassandra.db.ReadCommand) ComplexColumnData(org.apache.cassandra.db.rows.ComplexColumnData) UnfilteredPartitionIterator(org.apache.cassandra.db.partitions.UnfilteredPartitionIterator) PartitionIterator(org.apache.cassandra.db.partitions.PartitionIterator) RowIterator(org.apache.cassandra.db.rows.RowIterator) EndpointsForRange(org.apache.cassandra.locator.EndpointsForRange) BTreeRow(org.apache.cassandra.db.rows.BTreeRow) Row(org.apache.cassandra.db.rows.Row) Test(org.junit.Test)

Example 32 with EndpointsForRange

use of org.apache.cassandra.locator.EndpointsForRange in project cassandra by apache.

the class DataResolverTest method trackMismatchingRepairedDigestsWithSomeConclusive.

@Test
public void trackMismatchingRepairedDigestsWithSomeConclusive() {
    ByteBuffer digest1 = ByteBufferUtil.bytes("digest1");
    ByteBuffer digest2 = ByteBufferUtil.bytes("digest2");
    EndpointsForRange replicas = makeReplicas(2);
    InetAddressAndPort peer1 = replicas.get(0).endpoint();
    InetAddressAndPort peer2 = replicas.get(1).endpoint();
    TestRepairedDataVerifier verifier = new TestRepairedDataVerifier();
    verifier.expectDigest(peer1, digest1, false);
    verifier.expectDigest(peer2, digest2, true);
    DataResolver resolver = resolverWithVerifier(command, plan(replicas, ALL), readRepair, nanoTime(), verifier);
    resolver.preprocess(response(peer1, iter(PartitionUpdate.emptyUpdate(cfm, dk)), digest1, false, command));
    resolver.preprocess(response(peer2, iter(PartitionUpdate.emptyUpdate(cfm, dk)), digest2, true, command));
    resolveAndConsume(resolver);
    assertTrue(verifier.verified);
}
Also used : InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) EndpointsForRange(org.apache.cassandra.locator.EndpointsForRange) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 33 with EndpointsForRange

use of org.apache.cassandra.locator.EndpointsForRange in project cassandra by apache.

the class DataResolverTest method trackMatchingDigestsWithSomeConclusive.

@Test
public void trackMatchingDigestsWithSomeConclusive() {
    ByteBuffer digest1 = ByteBufferUtil.bytes("digest1");
    EndpointsForRange replicas = makeReplicas(2);
    InetAddressAndPort peer1 = replicas.get(0).endpoint();
    InetAddressAndPort peer2 = replicas.get(1).endpoint();
    TestRepairedDataVerifier verifier = new TestRepairedDataVerifier();
    verifier.expectDigest(peer1, digest1, true);
    verifier.expectDigest(peer2, digest1, false);
    DataResolver resolver = resolverWithVerifier(command, plan(replicas, ALL), readRepair, nanoTime(), verifier);
    resolver.preprocess(response(peer1, iter(PartitionUpdate.emptyUpdate(cfm, dk)), digest1, true, command));
    resolver.preprocess(response(peer2, iter(PartitionUpdate.emptyUpdate(cfm, dk)), digest1, false, command));
    resolveAndConsume(resolver);
    assertTrue(verifier.verified);
}
Also used : InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) EndpointsForRange(org.apache.cassandra.locator.EndpointsForRange) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 34 with EndpointsForRange

use of org.apache.cassandra.locator.EndpointsForRange in project cassandra by apache.

the class DataResolverTest method trackMatchingRepairedDigestsWithDifferentData.

@Test
public void trackMatchingRepairedDigestsWithDifferentData() {
    // As far as repaired data tracking is concerned, the actual data in the response is not relevant
    EndpointsForRange replicas = makeReplicas(2);
    ByteBuffer digest1 = ByteBufferUtil.bytes("digest1");
    InetAddressAndPort peer1 = replicas.get(0).endpoint();
    InetAddressAndPort peer2 = replicas.get(1).endpoint();
    TestRepairedDataVerifier verifier = new TestRepairedDataVerifier();
    verifier.expectDigest(peer1, digest1, true);
    verifier.expectDigest(peer2, digest1, true);
    DataResolver resolver = resolverWithVerifier(command, plan(replicas, ALL), readRepair, nanoTime(), verifier);
    resolver.preprocess(response(peer1, iter(new RowUpdateBuilder(cfm, nowInSec, 1L, dk).clustering("1").buildUpdate()), digest1, true, command));
    resolver.preprocess(response(peer2, iter(PartitionUpdate.emptyUpdate(cfm, dk)), digest1, true, command));
    resolveAndConsume(resolver);
    assertTrue(verifier.verified);
}
Also used : InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) RowUpdateBuilder(org.apache.cassandra.db.RowUpdateBuilder) EndpointsForRange(org.apache.cassandra.locator.EndpointsForRange) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 35 with EndpointsForRange

use of org.apache.cassandra.locator.EndpointsForRange in project cassandra by apache.

the class DataResolverTest method responsesFromOlderVersionsAreNotTracked.

@Test
public void responsesFromOlderVersionsAreNotTracked() {
    // In a mixed version cluster, responses from a replicas running older versions won't include
    // tracking info, so the digest and pending session status are defaulted. To make sure these
    // default values don't result in false positives we make sure not to consider them when
    // processing in DataResolver
    EndpointsForRange replicas = makeReplicas(2);
    TestRepairedDataVerifier verifier = new TestRepairedDataVerifier();
    ByteBuffer digest1 = ByteBufferUtil.bytes("digest1");
    InetAddressAndPort peer1 = replicas.get(0).endpoint();
    InetAddressAndPort peer2 = replicas.get(1).endpoint();
    verifier.expectDigest(peer1, digest1, true);
    DataResolver resolver = resolverWithVerifier(command, plan(replicas, ALL), readRepair, nanoTime(), verifier);
    resolver.preprocess(response(peer1, iter(PartitionUpdate.emptyUpdate(cfm, dk)), digest1, true, command));
    // peer2 is advertising an older version, so when we deserialize its response there are two things to note:
    // i) the actual serialized response cannot contain any tracking info so deserialization will use defaults of
    // an empty digest and pending sessions = false
    // ii) under normal circumstances, this would cause a mismatch with peer1, but because of the older version,
    // here it will not
    resolver.preprocess(response(command, peer2, iter(PartitionUpdate.emptyUpdate(cfm, dk)), false, MessagingService.VERSION_30, ByteBufferUtil.EMPTY_BYTE_BUFFER, false));
    resolveAndConsume(resolver);
    assertTrue(verifier.verified);
}
Also used : InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) EndpointsForRange(org.apache.cassandra.locator.EndpointsForRange) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Aggregations

EndpointsForRange (org.apache.cassandra.locator.EndpointsForRange)44 InetAddressAndPort (org.apache.cassandra.locator.InetAddressAndPort)36 Test (org.junit.Test)32 Mutation (org.apache.cassandra.db.Mutation)18 PartitionIterator (org.apache.cassandra.db.partitions.PartitionIterator)16 UnfilteredPartitionIterator (org.apache.cassandra.db.partitions.UnfilteredPartitionIterator)16 ByteBuffer (java.nio.ByteBuffer)14 RowUpdateBuilder (org.apache.cassandra.db.RowUpdateBuilder)13 BTreeRow (org.apache.cassandra.db.rows.BTreeRow)10 Row (org.apache.cassandra.db.rows.Row)10 Replica (org.apache.cassandra.locator.Replica)10 RowIterator (org.apache.cassandra.db.rows.RowIterator)9 DeletionTime (org.apache.cassandra.db.DeletionTime)8 HashMap (java.util.HashMap)6 Token (org.apache.cassandra.dht.Token)6 TestableReadRepair (org.apache.cassandra.service.reads.repair.TestableReadRepair)6 RangeTombstone (org.apache.cassandra.db.RangeTombstone)5 ReadCommand (org.apache.cassandra.db.ReadCommand)4 EndpointsByReplica (org.apache.cassandra.locator.EndpointsByReplica)4 VisibleForTesting (com.google.common.annotations.VisibleForTesting)3