use of org.apache.cassandra.locator.RangesAtEndpoint in project cassandra by apache.
the class EntireSSTableStreamConcurrentComponentMutationTest method defineSchemaAndPrepareSSTable.
@BeforeClass
public static void defineSchemaAndPrepareSSTable() {
SchemaLoader.prepareServer();
SchemaLoader.createKeyspace(KEYSPACE, KeyspaceParams.simple(1), SchemaLoader.standardCFMD(KEYSPACE, CF_STANDARD));
Keyspace keyspace = Keyspace.open(KEYSPACE);
store = keyspace.getColumnFamilyStore("Standard1");
// insert data and compact to a single sstable
CompactionManager.instance.disableAutoCompaction();
for (int j = 0; j < 10; j++) {
new RowUpdateBuilder(store.metadata(), j, String.valueOf(j)).clustering("0").add("val", ByteBufferUtil.EMPTY_BYTE_BUFFER).build().applyUnsafe();
}
store.forceBlockingFlush();
CompactionManager.instance.performMaximal(store, false);
Token start = ByteOrderedPartitioner.instance.getTokenFactory().fromString(Long.toHexString(0));
Token end = ByteOrderedPartitioner.instance.getTokenFactory().fromString(Long.toHexString(100));
rangesAtEndpoint = RangesAtEndpoint.toDummyList(Collections.singleton(new Range<>(start, end)));
service = Executors.newFixedThreadPool(2);
}
use of org.apache.cassandra.locator.RangesAtEndpoint in project cassandra by apache.
the class PendingAntiCompactionTest method antiCompactionException.
/**
* Makes sure that PendingAntiCompaction fails when anticompaction throws exception
*/
@Test
public void antiCompactionException() {
cfs.disableAutoCompaction();
makeSSTables(2);
UUID prsid = UUID.randomUUID();
ExecutorPlus es = ImmediateExecutor.INSTANCE;
PendingAntiCompaction pac = new PendingAntiCompaction(prsid, Collections.singleton(cfs), atEndpoint(FULL_RANGE, NO_RANGES), es, () -> false) {
@Override
protected AcquisitionCallback getAcquisitionCallback(UUID prsId, RangesAtEndpoint tokenRanges) {
return new AcquisitionCallback(prsid, tokenRanges, () -> false) {
@Override
Future submitPendingAntiCompaction(AcquireResult result) {
Runnable r = new WrappedRunnable() {
protected void runMayThrow() {
throw new CompactionInterruptedException("antiCompactionExceptionTest");
}
};
return es.submit(r);
}
};
}
};
ListenableFuture<?> fut = pac.run();
try {
fut.get();
fail("Should throw exception");
} catch (Throwable t) {
}
}
use of org.apache.cassandra.locator.RangesAtEndpoint in project cassandra by apache.
the class DiskBoundaryManager method getDiskBoundaries.
/**
* Returns a list of disk boundaries, the result will differ depending on whether vnodes are enabled or not.
*
* What is returned are upper bounds for the disks, meaning everything from partitioner.minToken up to
* getDiskBoundaries(..).get(0) should be on the first disk, everything between 0 to 1 should be on the second disk
* etc.
*
* The final entry in the returned list will always be the partitioner maximum tokens upper key bound
*/
private static List<PartitionPosition> getDiskBoundaries(RangesAtEndpoint replicas, IPartitioner partitioner, Directories.DataDirectory[] dataDirectories) {
assert partitioner.splitter().isPresent();
Splitter splitter = partitioner.splitter().get();
boolean dontSplitRanges = DatabaseDescriptor.getNumTokens() > 1;
List<Splitter.WeightedRange> weightedRanges = new ArrayList<>(replicas.size());
// note that Range.sort unwraps any wraparound ranges, so we need to sort them here
for (Range<Token> r : Range.sort(replicas.onlyFull().ranges())) weightedRanges.add(new Splitter.WeightedRange(1.0, r));
for (Range<Token> r : Range.sort(replicas.onlyTransient().ranges())) weightedRanges.add(new Splitter.WeightedRange(0.1, r));
weightedRanges.sort(Comparator.comparing(Splitter.WeightedRange::left));
List<Token> boundaries = splitter.splitOwnedRanges(dataDirectories.length, weightedRanges, dontSplitRanges);
// If we can't split by ranges, split evenly to ensure utilisation of all disks
if (dontSplitRanges && boundaries.size() < dataDirectories.length)
boundaries = splitter.splitOwnedRanges(dataDirectories.length, weightedRanges, false);
List<PartitionPosition> diskBoundaries = new ArrayList<>();
for (int i = 0; i < boundaries.size() - 1; i++) diskBoundaries.add(boundaries.get(i).maxKeyBound());
diskBoundaries.add(partitioner.getMaximumToken().maxKeyBound());
return diskBoundaries;
}
use of org.apache.cassandra.locator.RangesAtEndpoint in project cassandra by apache.
the class AntiCompactionTest method antiCompactRanges.
private SSTableStats antiCompactRanges(ColumnFamilyStore store, RangesAtEndpoint ranges) throws IOException {
UUID sessionID = UUID.randomUUID();
Collection<SSTableReader> sstables = getUnrepairedSSTables(store);
try (LifecycleTransaction txn = store.getTracker().tryModify(sstables, OperationType.ANTICOMPACTION);
Refs<SSTableReader> refs = Refs.ref(sstables)) {
if (txn == null)
throw new IllegalStateException();
registerParentRepairSession(sessionID, ranges.ranges(), FBUtilities.nowInSeconds(), sessionID);
CompactionManager.instance.performAnticompaction(store, ranges, refs, txn, sessionID, () -> false);
}
SSTableStats stats = new SSTableStats();
stats.numLiveSSTables = store.getLiveSSTables().size();
Predicate<Token> fullContains = t -> Iterables.any(ranges.onlyFull().ranges(), r -> r.contains(t));
Predicate<Token> transContains = t -> Iterables.any(ranges.onlyTransient().ranges(), r -> r.contains(t));
for (SSTableReader sstable : store.getLiveSSTables()) {
assertFalse(sstable.isRepaired());
assertEquals(sstable.isPendingRepair() ? sessionID : NO_PENDING_REPAIR, sstable.getPendingRepair());
try (ISSTableScanner scanner = sstable.getScanner()) {
while (scanner.hasNext()) {
UnfilteredRowIterator row = scanner.next();
Token token = row.partitionKey().getToken();
if (sstable.isPendingRepair() && !sstable.isTransient()) {
assertTrue(fullContains.test(token));
assertFalse(transContains.test(token));
stats.pendingKeys++;
} else if (sstable.isPendingRepair() && sstable.isTransient()) {
assertTrue(transContains.test(token));
assertFalse(fullContains.test(token));
stats.transKeys++;
} else {
assertFalse(fullContains.test(token));
assertFalse(transContains.test(token));
stats.unrepairedKeys++;
}
}
}
}
for (SSTableReader sstable : store.getLiveSSTables()) {
assertFalse(sstable.isMarkedCompacted());
assertEquals(1, sstable.selfRef().globalCount());
}
assertEquals(0, store.getTracker().getCompacting().size());
return stats;
}
use of org.apache.cassandra.locator.RangesAtEndpoint in project cassandra by apache.
the class AntiCompactionBytemanTest method testRedundantTransitions.
@Test
@BMRules(rules = { @BMRule(name = "Insert delay after first prepareToCommit", targetClass = "CompactionManager", targetMethod = "antiCompactGroup", condition = "not flagged(\"done\")", targetLocation = "AFTER INVOKE prepareToCommit", action = "Thread.sleep(2000);") })
public void testRedundantTransitions() throws Throwable {
createTable("create table %s (id int primary key, i int)");
execute("insert into %s (id, i) values (1, 1)");
execute("insert into %s (id, i) values (2, 1)");
execute("insert into %s (id, i) values (3, 1)");
getCurrentColumnFamilyStore().forceBlockingFlush();
UntypedResultSet res = execute("select token(id) as tok from %s");
Iterator<UntypedResultSet.Row> it = res.iterator();
List<Long> tokens = new ArrayList<>();
while (it.hasNext()) {
UntypedResultSet.Row r = it.next();
tokens.add(r.getLong("tok"));
}
tokens.sort(Long::compareTo);
long first = tokens.get(0) - 10;
long last = tokens.get(0) + 10;
Range<Token> toRepair = new Range<>(new Murmur3Partitioner.LongToken(first), new Murmur3Partitioner.LongToken(last));
first = tokens.get(1) - 10;
last = tokens.get(1) + 10;
Range<Token> pending = new Range<>(new Murmur3Partitioner.LongToken(first), new Murmur3Partitioner.LongToken(last));
RangesAtEndpoint ranges = new RangesAtEndpoint.Builder(FBUtilities.getBroadcastAddressAndPort()).add(Replica.fullReplica(FBUtilities.getBroadcastAddressAndPort(), toRepair)).add(Replica.transientReplica(InetAddressAndPort.getByName("127.0.0.1"), pending)).build();
AtomicBoolean failed = new AtomicBoolean(false);
AtomicBoolean finished = new AtomicBoolean(false);
Thread t = new Thread(() -> {
while (!finished.get()) {
UntypedResultSet result = null;
try {
result = execute("select id from %s");
} catch (Throwable throwable) {
failed.set(true);
throw new RuntimeException(throwable);
}
Iterator<UntypedResultSet.Row> rowIter = result.iterator();
Set<Integer> ids = new HashSet<>();
while (rowIter.hasNext()) {
UntypedResultSet.Row r = rowIter.next();
ids.add(r.getInt("id"));
}
if (!Sets.newHashSet(1, 2, 3).equals(ids)) {
failed.set(true);
return;
}
Uninterruptibles.sleepUninterruptibly(10, TimeUnit.MILLISECONDS);
}
});
t.start();
assertEquals(1, getCurrentColumnFamilyStore().getLiveSSTables().size());
SSTableReader sstableBefore = getCurrentColumnFamilyStore().getLiveSSTables().iterator().next();
try (LifecycleTransaction txn = getCurrentColumnFamilyStore().getTracker().tryModify(getCurrentColumnFamilyStore().getLiveSSTables(), OperationType.ANTICOMPACTION)) {
CompactionManager.instance.antiCompactGroup(getCurrentColumnFamilyStore(), ranges, txn, UUID.randomUUID(), () -> false);
}
finished.set(true);
t.join();
assertFalse(failed.get());
assertFalse(getCurrentColumnFamilyStore().getLiveSSTables().contains(sstableBefore));
Util.assertOnDiskState(getCurrentColumnFamilyStore(), 3);
}
Aggregations