Search in sources :

Example 36 with EndpointsForRange

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

the class DataResolverTest method testResolveWithOneEmpty.

@Test
public void testResolveWithOneEmpty() {
    EndpointsForRange replicas = makeReplicas(2);
    DataResolver resolver = new DataResolver(command, plan(replicas, ALL), readRepair, nanoTime());
    InetAddressAndPort peer1 = replicas.get(0).endpoint();
    resolver.preprocess(response(command, peer1, iter(new RowUpdateBuilder(cfm, nowInSec, 1L, dk).clustering("1").add("c2", "v2").buildUpdate())));
    InetAddressAndPort peer2 = replicas.get(1).endpoint();
    resolver.preprocess(response(command, peer2, EmptyIterators.unfilteredPartition(cfm)));
    try (PartitionIterator data = resolver.resolve()) {
        try (RowIterator rows = Iterators.getOnlyElement(data)) {
            Row row = Iterators.getOnlyElement(rows);
            assertColumns(row, "c2");
            assertColumn(cfm, row, "c2", "v2", 1);
        }
    }
    assertEquals(1, readRepair.sent.size());
    // peer 2 needs the row from peer 1
    Mutation mutation = readRepair.getForEndpoint(peer2);
    assertRepairMetadata(mutation);
    assertRepairContainsNoDeletions(mutation);
    assertRepairContainsColumn(mutation, "1", "c2", "v2", 1);
}
Also used : InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) RowUpdateBuilder(org.apache.cassandra.db.RowUpdateBuilder) 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) Mutation(org.apache.cassandra.db.Mutation) Test(org.junit.Test)

Example 37 with EndpointsForRange

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

the class DataResolverTest method testResolveNewCollection.

@Test
public void testResolveNewCollection() {
    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 };
    // map column
    Row.Builder builder = BTreeRow.unsortedBuilder();
    builder.newRow(Clustering.EMPTY);
    DeletionTime expectedCmplxDelete = new DeletionTime(ts[0] - 1, nowInSec);
    builder.addComplexDeletion(m, expectedCmplxDelete);
    Cell<?> expectedCell = mapCell(0, 0, ts[0]);
    builder.addCell(expectedCell);
    // empty map column
    InetAddressAndPort peer1 = replicas.get(0).endpoint();
    resolver.preprocess(response(cmd, peer1, iter(PartitionUpdate.singleRowUpdate(cfm2, dk, builder.build()))));
    InetAddressAndPort peer2 = replicas.get(1).endpoint();
    resolver.preprocess(response(cmd, peer2, iter(PartitionUpdate.emptyUpdate(cfm2, dk))));
    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));
        }
    }
    Assert.assertNull(readRepair.sent.get(peer1));
    Mutation mutation = readRepair.getForEndpoint(peer2);
    Iterator<Row> rowIter = mutation.getPartitionUpdate(cfm2).iterator();
    assertTrue(rowIter.hasNext());
    Row row = rowIter.next();
    assertFalse(rowIter.hasNext());
    ComplexColumnData cd = row.getComplexColumnData(m);
    assertEquals(Sets.newHashSet(expectedCell), Sets.newHashSet(cd));
    assertEquals(expectedCmplxDelete, cd.complexDeletion());
}
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) Mutation(org.apache.cassandra.db.Mutation) Test(org.junit.Test)

Example 38 with EndpointsForRange

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

the class DataResolverTest method trackMatchingDigestsWithAllConclusive.

@Test
public void trackMatchingDigestsWithAllConclusive() {
    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, true);
    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, 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 39 with EndpointsForRange

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

the class DataResolverTest method trackMatchingEmptyDigestsWithSomeConclusive.

@Test
public void trackMatchingEmptyDigestsWithSomeConclusive() {
    ByteBuffer digest1 = ByteBufferUtil.EMPTY_BYTE_BUFFER;
    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, digest1, 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)), digest1, 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 40 with EndpointsForRange

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

the class DataResolverTest method trackMismatchingRepairedDigestsWithDifferentData.

@Test
public void trackMismatchingRepairedDigestsWithDifferentData() {
    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, true);
    verifier.expectDigest(peer2, digest2, 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)), digest2, 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)

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