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());
}
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);
}
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;
}
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;
}
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());
}
Aggregations