Search in sources :

Example 1 with ExecutorPlus

use of org.apache.cassandra.concurrent.ExecutorPlus in project cassandra by apache.

the class MonitorMethodTransformerTest method testSynchronizedMethodMultiThreaded.

@Test
public void testSynchronizedMethodMultiThreaded() {
    // Similar to the method above, but this test adds submission of tasks to an Executor
    // within the simulated system, effectively adding another layer of scheduling to be
    // perturbed. The same invariants should preserved as in the previous test.
    simulate(() -> {
        ExecutorPlus executor = ExecutorFactory.Global.executorFactory().pooled("name", 10);
        int threads = 10;
        for (int i = 0; i < threads; i++) {
            int thread = i;
            executor.submit(() -> {
                for (int iteration = 0; iteration < 10; iteration++) ClassWithSynchronizedMethods.synchronizedMethodWithParams(thread, iteration);
            });
        }
    }, () -> checkInterleavings());
}
Also used : ExecutorPlus(org.apache.cassandra.concurrent.ExecutorPlus) Test(org.junit.Test)

Example 2 with ExecutorPlus

use of org.apache.cassandra.concurrent.ExecutorPlus in project cassandra by apache.

the class AutoSavingCache method loadSavedAsync.

public Future<Integer> loadSavedAsync() {
    final ExecutorPlus es = executorFactory().sequential("loadSavedCache");
    final long start = nanoTime();
    Future<Integer> cacheLoad = es.submit(this::loadSaved);
    cacheLoad.addListener(() -> {
        if (size() > 0)
            logger.info("Completed loading ({} ms; {} keys) {} cache", TimeUnit.NANOSECONDS.toMillis(nanoTime() - start), CacheService.instance.keyCache.size(), cacheType);
        es.shutdown();
    });
    return cacheLoad;
}
Also used : ExecutorPlus(org.apache.cassandra.concurrent.ExecutorPlus)

Example 3 with ExecutorPlus

use of org.apache.cassandra.concurrent.ExecutorPlus in project cassandra by apache.

the class RepairRunnable method repair.

private void repair(String[] cfnames, NeighborsAndRanges neighborsAndRanges) {
    RepairTask task;
    if (options.isPreview()) {
        task = new PreviewRepairTask(options, keyspace, this, parentSession, neighborsAndRanges.filterCommonRanges(keyspace, cfnames), cfnames);
    } else if (options.isIncremental()) {
        task = new IncrementalRepairTask(options, keyspace, this, parentSession, neighborsAndRanges, cfnames);
    } else {
        task = new NormalRepairTask(options, keyspace, this, parentSession, neighborsAndRanges.filterCommonRanges(keyspace, cfnames), cfnames);
    }
    ExecutorPlus executor = createExecutor();
    Future<CoordinatedRepairResult> f = task.perform(executor);
    f.addCallback((result, failure) -> {
        try {
            if (failure != null) {
                notifyError(failure);
                fail(failure.getMessage());
            } else {
                maybeStoreParentRepairSuccess(result.successfulRanges);
                if (result.hasFailed()) {
                    fail(null);
                } else {
                    success(task.name() + " completed successfully");
                    ActiveRepairService.instance.cleanUp(parentSession, neighborsAndRanges.participants);
                }
            }
        } finally {
            executor.shutdownNow();
        }
    });
}
Also used : ExecutorPlus(org.apache.cassandra.concurrent.ExecutorPlus)

Example 4 with ExecutorPlus

use of org.apache.cassandra.concurrent.ExecutorPlus in project cassandra by apache.

the class PendingAntiCompactionTest method testRetries.

@Test
public void testRetries() throws InterruptedException, ExecutionException {
    ColumnFamilyStore cfs = MockSchema.newCFS();
    cfs.addSSTable(MockSchema.sstable(1, true, cfs));
    CountDownLatch cdl = new CountDownLatch(5);
    ExecutorPlus es = executorFactory().sequential("test");
    CompactionInfo.Holder holder = new CompactionInfo.Holder() {

        public CompactionInfo getCompactionInfo() {
            return new CompactionInfo(cfs.metadata(), OperationType.ANTICOMPACTION, 0, 0, UUID.randomUUID(), cfs.getLiveSSTables());
        }

        public boolean isGlobal() {
            return false;
        }
    };
    try {
        PendingAntiCompaction.AntiCompactionPredicate acp = new PendingAntiCompaction.AntiCompactionPredicate(FULL_RANGE, UUID.randomUUID()) {

            @Override
            public boolean apply(SSTableReader sstable) {
                cdl.countDown();
                if (cdl.getCount() > 0)
                    throw new PendingAntiCompaction.SSTableAcquisitionException("blah");
                return true;
            }
        };
        CompactionManager.instance.active.beginCompaction(holder);
        PendingAntiCompaction.AcquisitionCallable acquisitionCallable = new PendingAntiCompaction.AcquisitionCallable(cfs, UUID.randomUUID(), 10, 1, acp);
        Future f = es.submit(acquisitionCallable);
        cdl.await();
        assertNotNull(f.get());
    } finally {
        es.shutdown();
        CompactionManager.instance.active.finishCompaction(holder);
    }
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) ExecutorPlus(org.apache.cassandra.concurrent.ExecutorPlus) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) Future(org.apache.cassandra.utils.concurrent.Future) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) CompactionInfo(org.apache.cassandra.db.compaction.CompactionInfo) AbstractPendingRepairTest(org.apache.cassandra.db.compaction.AbstractPendingRepairTest) Test(org.junit.Test)

Example 5 with ExecutorPlus

use of org.apache.cassandra.concurrent.ExecutorPlus in project cassandra by apache.

the class PendingAntiCompactionTest method testRetriesTimeout.

@Test
public void testRetriesTimeout() throws InterruptedException, ExecutionException {
    ColumnFamilyStore cfs = MockSchema.newCFS();
    cfs.addSSTable(MockSchema.sstable(1, true, cfs));
    ExecutorPlus es = executorFactory().sequential("test");
    CompactionInfo.Holder holder = new CompactionInfo.Holder() {

        public CompactionInfo getCompactionInfo() {
            return new CompactionInfo(cfs.metadata(), OperationType.ANTICOMPACTION, 0, 0, UUID.randomUUID(), cfs.getLiveSSTables());
        }

        public boolean isGlobal() {
            return false;
        }
    };
    try {
        PendingAntiCompaction.AntiCompactionPredicate acp = new PendingAntiCompaction.AntiCompactionPredicate(FULL_RANGE, UUID.randomUUID()) {

            @Override
            public boolean apply(SSTableReader sstable) {
                throw new PendingAntiCompaction.SSTableAcquisitionException("blah");
            }
        };
        CompactionManager.instance.active.beginCompaction(holder);
        PendingAntiCompaction.AcquisitionCallable acquisitionCallable = new PendingAntiCompaction.AcquisitionCallable(cfs, UUID.randomUUID(), 2, 1000, acp);
        Future fut = es.submit(acquisitionCallable);
        assertNull(fut.get());
    } finally {
        es.shutdown();
        CompactionManager.instance.active.finishCompaction(holder);
    }
}
Also used : SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) ExecutorPlus(org.apache.cassandra.concurrent.ExecutorPlus) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) Future(org.apache.cassandra.utils.concurrent.Future) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) CompactionInfo(org.apache.cassandra.db.compaction.CompactionInfo) AbstractPendingRepairTest(org.apache.cassandra.db.compaction.AbstractPendingRepairTest) Test(org.junit.Test)

Aggregations

ExecutorPlus (org.apache.cassandra.concurrent.ExecutorPlus)7 Test (org.junit.Test)4 AbstractPendingRepairTest (org.apache.cassandra.db.compaction.AbstractPendingRepairTest)3 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)2 CompactionInfo (org.apache.cassandra.db.compaction.CompactionInfo)2 SSTableReader (org.apache.cassandra.io.sstable.format.SSTableReader)2 Future (org.apache.cassandra.utils.concurrent.Future)2 UUID (java.util.UUID)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ScheduledExecutorPlus (org.apache.cassandra.concurrent.ScheduledExecutorPlus)1 DatabaseDescriptor (org.apache.cassandra.config.DatabaseDescriptor)1 CompactionInterruptedException (org.apache.cassandra.db.compaction.CompactionInterruptedException)1 FSError (org.apache.cassandra.io.FSError)1 RangesAtEndpoint (org.apache.cassandra.locator.RangesAtEndpoint)1 WrappedRunnable (org.apache.cassandra.utils.WrappedRunnable)1