Search in sources :

Example 21 with RangesAtEndpoint

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);
}
Also used : RowUpdateBuilder(org.apache.cassandra.db.RowUpdateBuilder) Keyspace(org.apache.cassandra.db.Keyspace) Token(org.apache.cassandra.dht.Token) RangesAtEndpoint(org.apache.cassandra.locator.RangesAtEndpoint) BeforeClass(org.junit.BeforeClass)

Example 22 with RangesAtEndpoint

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) {
    }
}
Also used : RangesAtEndpoint(org.apache.cassandra.locator.RangesAtEndpoint) WrappedRunnable(org.apache.cassandra.utils.WrappedRunnable) ExecutorPlus(org.apache.cassandra.concurrent.ExecutorPlus) WrappedRunnable(org.apache.cassandra.utils.WrappedRunnable) CompactionInterruptedException(org.apache.cassandra.db.compaction.CompactionInterruptedException) UUID(java.util.UUID) AbstractPendingRepairTest(org.apache.cassandra.db.compaction.AbstractPendingRepairTest) Test(org.junit.Test)

Example 23 with RangesAtEndpoint

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;
}
Also used : Splitter(org.apache.cassandra.dht.Splitter) ArrayList(java.util.ArrayList) Token(org.apache.cassandra.dht.Token) RangesAtEndpoint(org.apache.cassandra.locator.RangesAtEndpoint)

Example 24 with RangesAtEndpoint

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;
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) NoSuchRepairSessionException(org.apache.cassandra.repair.NoSuchRepairSessionException) BytesToken(org.apache.cassandra.dht.ByteOrderedPartitioner.BytesToken) Arrays(java.util.Arrays) Util.assertOnDiskState(org.apache.cassandra.Util.assertOnDiskState) SSTableSet(org.apache.cassandra.db.lifecycle.SSTableSet) File(org.apache.cassandra.io.util.File) org.apache.cassandra.db(org.apache.cassandra.db) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) Assert.assertThat(org.junit.Assert.assertThat) NO_PENDING_REPAIR(org.apache.cassandra.service.ActiveRepairService.NO_PENDING_REPAIR) After(org.junit.After) Murmur3Partitioner(org.apache.cassandra.dht.Murmur3Partitioner) Transactional(org.apache.cassandra.utils.concurrent.Transactional) ImmutableSet(com.google.common.collect.ImmutableSet) FBUtilities(org.apache.cassandra.utils.FBUtilities) org.apache.cassandra.io.sstable(org.apache.cassandra.io.sstable) Predicate(java.util.function.Predicate) UNREPAIRED_SSTABLE(org.apache.cassandra.service.ActiveRepairService.UNREPAIRED_SSTABLE) Collection(java.util.Collection) KeyspaceParams(org.apache.cassandra.schema.KeyspaceParams) Set(java.util.Set) UUID(java.util.UUID) Sets(com.google.common.collect.Sets) RangesAtEndpoint(org.apache.cassandra.locator.RangesAtEndpoint) UUIDGen(org.apache.cassandra.utils.UUIDGen) List(java.util.List) LifecycleTransaction(org.apache.cassandra.db.lifecycle.LifecycleTransaction) Assert.assertFalse(org.junit.Assert.assertFalse) TableMetadata(org.apache.cassandra.schema.TableMetadata) InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) Iterables(com.google.common.collect.Iterables) BeforeClass(org.junit.BeforeClass) Range(org.apache.cassandra.dht.Range) ArrayList(java.util.ArrayList) Schema(org.apache.cassandra.schema.Schema) Token(org.apache.cassandra.dht.Token) ActiveRepairService(org.apache.cassandra.service.ActiveRepairService) Lists(com.google.common.collect.Lists) UnfilteredRowIterator(org.apache.cassandra.db.rows.UnfilteredRowIterator) Refs(org.apache.cassandra.utils.concurrent.Refs) UpdateBuilder(org.apache.cassandra.UpdateBuilder) Iterator(java.util.Iterator) MockSchema(org.apache.cassandra.schema.MockSchema) Assert.assertNotNull(org.junit.Assert.assertNotNull) ByteBufferUtil(org.apache.cassandra.utils.ByteBufferUtil) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) Replica(org.apache.cassandra.locator.Replica) SchemaLoader(org.apache.cassandra.SchemaLoader) PreviewKind(org.apache.cassandra.streaming.PreviewKind) EncodingStats(org.apache.cassandra.db.rows.EncodingStats) Assert(org.junit.Assert) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) UnfilteredRowIterator(org.apache.cassandra.db.rows.UnfilteredRowIterator) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) LifecycleTransaction(org.apache.cassandra.db.lifecycle.LifecycleTransaction) BytesToken(org.apache.cassandra.dht.ByteOrderedPartitioner.BytesToken) Token(org.apache.cassandra.dht.Token) UUID(java.util.UUID)

Example 25 with RangesAtEndpoint

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);
}
Also used : RangesAtEndpoint(org.apache.cassandra.locator.RangesAtEndpoint) ArrayList(java.util.ArrayList) LifecycleTransaction(org.apache.cassandra.db.lifecycle.LifecycleTransaction) Token(org.apache.cassandra.dht.Token) Range(org.apache.cassandra.dht.Range) Murmur3Partitioner(org.apache.cassandra.dht.Murmur3Partitioner) UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) HashSet(java.util.HashSet) Test(org.junit.Test) BMRules(org.jboss.byteman.contrib.bmunit.BMRules)

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