Search in sources :

Example 26 with RangesAtEndpoint

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

the class CleanupTransientTest method testCleanup.

@Test
public void testCleanup() throws Exception {
    Keyspace keyspace = Keyspace.open(KEYSPACE1);
    ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(CF_STANDARD1);
    // insert data and verify we get it back w/ range query
    fillCF(cfs, "val", LOOPS);
    // record max timestamps of the sstables pre-cleanup
    List<Long> expectedMaxTimestamps = getMaxTimestampList(cfs);
    assertEquals(LOOPS, Util.getAll(Util.cmd(cfs).build()).size());
    // with two tokens RF=2/1 and the sstable not repaired this should do nothing
    CompactionManager.instance.performCleanup(cfs, 2);
    // ensure max timestamp of the sstables are retained post-cleanup
    assert expectedMaxTimestamps.equals(getMaxTimestampList(cfs));
    // check data is still there
    assertEquals(LOOPS, Util.getAll(Util.cmd(cfs).build()).size());
    // Get an exact count of how many partitions are in the fully replicated range and should
    // be retained
    int fullCount = 0;
    RangesAtEndpoint localRanges = StorageService.instance.getLocalReplicas(keyspace.getName()).filter(Replica::isFull);
    for (FilteredPartition partition : Util.getAll(Util.cmd(cfs).build())) {
        Token token = partition.partitionKey().getToken();
        for (Replica r : localRanges) {
            if (r.range().contains(token))
                fullCount++;
        }
    }
    SSTableReader sstable = cfs.getLiveSSTables().iterator().next();
    sstable.descriptor.getMetadataSerializer().mutateRepairMetadata(sstable.descriptor, 1, null, false);
    sstable.reloadSSTableMetadata();
    // This should remove approximately 50% of the data, specifically whatever was transiently replicated
    CompactionManager.instance.performCleanup(cfs, 2);
    // ensure max timestamp of the sstables are retained post-cleanup
    assert expectedMaxTimestamps.equals(getMaxTimestampList(cfs));
    // check less data is there, all transient data should be gone since the table was repaired
    assertEquals(fullCount, Util.getAll(Util.cmd(cfs).build()).size());
}
Also used : RangesAtEndpoint(org.apache.cassandra.locator.RangesAtEndpoint) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) FilteredPartition(org.apache.cassandra.db.partitions.FilteredPartition) Token(org.apache.cassandra.dht.Token) Replica(org.apache.cassandra.locator.Replica) RangesAtEndpoint(org.apache.cassandra.locator.RangesAtEndpoint) Test(org.junit.Test)

Example 27 with RangesAtEndpoint

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

the class MoveTest method assertRanges.

private static void assertRanges(RangesByEndpoint epReplicas, String endpoint, int... rangePairs) {
    if (rangePairs.length % 2 == 1)
        throw new RuntimeException("assertRanges argument count should be even");
    InetAddressAndPort ep = inet(endpoint);
    List<Replica> expected = new ArrayList<>(rangePairs.length / 2);
    for (int i = 0; i < rangePairs.length; i += 2) expected.add(replica(ep, rangePairs[i], rangePairs[i + 1]));
    RangesAtEndpoint actual = epReplicas.get(ep);
    assertEquals(expected.size(), actual.size());
    for (Replica replica : expected) if (!actual.contains(replica))
        assertEquals(RangesAtEndpoint.copyOf(expected), actual);
}
Also used : InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) RangesAtEndpoint(org.apache.cassandra.locator.RangesAtEndpoint) Replica(org.apache.cassandra.locator.Replica) RangesAtEndpoint(org.apache.cassandra.locator.RangesAtEndpoint) RangesByEndpoint(org.apache.cassandra.locator.RangesByEndpoint)

Example 28 with RangesAtEndpoint

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

the class MoveTransientTest method calculateStreamAndFetchRangesMoveForward.

private Pair<RangesAtEndpoint, RangesAtEndpoint> calculateStreamAndFetchRangesMoveForward() throws Exception {
    Range<Token> aPrimeRange = new Range<>(oneToken, fourToken);
    RangesAtEndpoint updated = RangesAtEndpoint.of(new Replica(address01, aPrimeRange, true), new Replica(address01, range_11_1, true), new Replica(address01, range_9_11, false));
    Pair<RangesAtEndpoint, RangesAtEndpoint> result = RangeRelocator.calculateStreamAndFetchRanges(current, updated);
    assertContentsIgnoreOrder(result.left);
    assertContentsIgnoreOrder(result.right, fullReplica(address01, threeToken, fourToken));
    return result;
}
Also used : RangesAtEndpoint(org.apache.cassandra.locator.RangesAtEndpoint) Token(org.apache.cassandra.dht.Token) Range(org.apache.cassandra.dht.Range) Replica.fullReplica(org.apache.cassandra.locator.Replica.fullReplica) Replica(org.apache.cassandra.locator.Replica) Replica.transientReplica(org.apache.cassandra.locator.Replica.transientReplica) EndpointsByReplica(org.apache.cassandra.locator.EndpointsByReplica)

Example 29 with RangesAtEndpoint

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

the class MoveTransientTest method calculateStreamAndFetchRangesMoveBackward.

private Pair<RangesAtEndpoint, RangesAtEndpoint> calculateStreamAndFetchRangesMoveBackward() throws Exception {
    Range<Token> aPrimeRange = new Range<>(oneToken, twoToken);
    RangesAtEndpoint updated = RangesAtEndpoint.of(new Replica(address01, aPrimeRange, true), new Replica(address01, range_11_1, true), new Replica(address01, range_9_11, false));
    Pair<RangesAtEndpoint, RangesAtEndpoint> result = RangeRelocator.calculateStreamAndFetchRanges(current, updated);
    // Moving backwards has no impact on any replica. We already fully replicate counter clockwise
    // The transient replica does transiently replicate slightly more, but that is addressed by cleanup
    assertContentsIgnoreOrder(result.left, fullReplica(address01, twoToken, threeToken));
    assertContentsIgnoreOrder(result.right);
    return result;
}
Also used : RangesAtEndpoint(org.apache.cassandra.locator.RangesAtEndpoint) Token(org.apache.cassandra.dht.Token) Range(org.apache.cassandra.dht.Range) Replica.fullReplica(org.apache.cassandra.locator.Replica.fullReplica) Replica(org.apache.cassandra.locator.Replica) Replica.transientReplica(org.apache.cassandra.locator.Replica.transientReplica) EndpointsByReplica(org.apache.cassandra.locator.EndpointsByReplica)

Example 30 with RangesAtEndpoint

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

the class MoveTransientTest method testResubtract.

@Test
public void testResubtract() {
    Token oneToken = new RandomPartitioner.BigIntegerToken("0001");
    Token tenToken = new RandomPartitioner.BigIntegerToken("0010");
    Token fiveToken = new RandomPartitioner.BigIntegerToken("0005");
    Range<Token> range_1_10 = new Range<>(oneToken, tenToken);
    Range<Token> range_1_5 = new Range<>(oneToken, tenToken);
    Range<Token> range_5_10 = new Range<>(fiveToken, tenToken);
    RangesAtEndpoint singleRange = RangesAtEndpoint.of(new Replica(address01, range_1_10, true));
    RangesAtEndpoint splitRanges = RangesAtEndpoint.of(new Replica(address01, range_1_5, true), new Replica(address01, range_5_10, true));
    // forward
    Pair<RangesAtEndpoint, RangesAtEndpoint> calculated = RangeRelocator.calculateStreamAndFetchRanges(singleRange, splitRanges);
    assertTrue(calculated.left.toString(), calculated.left.isEmpty());
    assertTrue(calculated.right.toString(), calculated.right.isEmpty());
    // backward
    calculated = RangeRelocator.calculateStreamAndFetchRanges(splitRanges, singleRange);
    assertTrue(calculated.left.toString(), calculated.left.isEmpty());
    assertTrue(calculated.right.toString(), calculated.right.isEmpty());
}
Also used : RangesAtEndpoint(org.apache.cassandra.locator.RangesAtEndpoint) Token(org.apache.cassandra.dht.Token) Range(org.apache.cassandra.dht.Range) Replica.fullReplica(org.apache.cassandra.locator.Replica.fullReplica) Replica(org.apache.cassandra.locator.Replica) Replica.transientReplica(org.apache.cassandra.locator.Replica.transientReplica) EndpointsByReplica(org.apache.cassandra.locator.EndpointsByReplica) Test(org.junit.Test)

Aggregations

RangesAtEndpoint (org.apache.cassandra.locator.RangesAtEndpoint)32 Token (org.apache.cassandra.dht.Token)22 Range (org.apache.cassandra.dht.Range)20 Replica (org.apache.cassandra.locator.Replica)17 SSTableReader (org.apache.cassandra.io.sstable.format.SSTableReader)10 EndpointsByReplica (org.apache.cassandra.locator.EndpointsByReplica)10 ArrayList (java.util.ArrayList)9 List (java.util.List)9 Test (org.junit.Test)9 Logger (org.slf4j.Logger)9 LoggerFactory (org.slf4j.LoggerFactory)9 Collection (java.util.Collection)8 DatabaseDescriptor (org.apache.cassandra.config.DatabaseDescriptor)8 InetAddressAndPort (org.apache.cassandra.locator.InetAddressAndPort)8 VisibleForTesting (com.google.common.annotations.VisibleForTesting)7 Set (java.util.Set)7 UUID (java.util.UUID)7 Replica.fullReplica (org.apache.cassandra.locator.Replica.fullReplica)7 IOException (java.io.IOException)6 Replica.transientReplica (org.apache.cassandra.locator.Replica.transientReplica)6