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