use of org.apache.jackrabbit.oak.commons.concurrent.ExecutorCloser in project jackrabbit-oak by apache.
the class CompactionAndCleanupIT method concurrentCleanup.
/**
* Test asserting OAK-4700: Concurrent cleanup must not remove segments that are still reachable
*/
@Test
public void concurrentCleanup() throws Exception {
File fileStoreFolder = getFileStoreFolder();
final FileStore fileStore = fileStoreBuilder(fileStoreFolder).withMaxFileSize(1).build();
final SegmentNodeStore nodeStore = SegmentNodeStoreBuilders.builder(fileStore).build();
ExecutorService executorService = newFixedThreadPool(50);
final AtomicInteger counter = new AtomicInteger();
try {
Callable<Void> concurrentWriteTask = new Callable<Void>() {
@Override
public Void call() throws Exception {
NodeBuilder builder = nodeStore.getRoot().builder();
builder.setProperty("blob-" + counter.getAndIncrement(), createBlob(nodeStore, 512 * 512));
nodeStore.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
fileStore.flush();
return null;
}
};
final Callable<Void> concurrentCleanTask = new Callable<Void>() {
@Override
public Void call() throws Exception {
fileStore.cleanup();
return null;
}
};
List<Future<?>> results = newArrayList();
for (int i = 0; i < 50; i++) {
if (i % 2 == 0) {
results.add(executorService.submit(concurrentWriteTask));
} else {
results.add(executorService.submit(concurrentCleanTask));
}
}
for (Future<?> result : results) {
assertNull(result.get());
}
for (String fileName : fileStoreFolder.list()) {
if (fileName.endsWith(".tar")) {
int pos = fileName.length() - "a.tar".length();
char generation = fileName.charAt(pos);
assertEquals("Expected nothing to be cleaned but generation '" + generation + "' for file " + fileName + " indicates otherwise.", "a", valueOf(generation));
}
}
} finally {
new ExecutorCloser(executorService).close();
fileStore.close();
}
}
use of org.apache.jackrabbit.oak.commons.concurrent.ExecutorCloser in project jackrabbit-oak by apache.
the class CompactionAndCleanupIT method concurrentWritesCleanupNoNewGen.
/**
* Test asserting OAK-4669: No new generation of tar should be created when the segments are the same
* and when various indices are created.
*/
@Test
public void concurrentWritesCleanupNoNewGen() throws Exception {
ScheduledExecutorService scheduler = newSingleThreadScheduledExecutor();
StatisticsProvider statsProvider = new DefaultStatisticsProvider(scheduler);
final FileStoreGCMonitor fileStoreGCMonitor = new FileStoreGCMonitor(Clock.SIMPLE);
File fileStoreFolder = getFileStoreFolder();
final FileStore fileStore = fileStoreBuilder(fileStoreFolder).withGCOptions(defaultGCOptions().setRetainedGenerations(2)).withGCMonitor(fileStoreGCMonitor).withStatisticsProvider(statsProvider).withMaxFileSize(1).withMemoryMapping(false).build();
final SegmentNodeStore nodeStore = SegmentNodeStoreBuilders.builder(fileStore).build();
ExecutorService executorService = newFixedThreadPool(5);
final AtomicInteger counter = new AtomicInteger();
try {
Callable<Void> concurrentWriteTask = new Callable<Void>() {
@Override
public Void call() throws Exception {
NodeBuilder builder = nodeStore.getRoot().builder();
builder.setProperty("blob-" + counter.getAndIncrement(), createBlob(nodeStore, 512 * 512));
nodeStore.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
fileStore.flush();
return null;
}
};
List<Future<?>> results = newArrayList();
for (int i = 0; i < 5; i++) {
results.add(executorService.submit(concurrentWriteTask));
}
for (Future<?> result : results) {
assertNull(result.get());
}
fileStore.cleanup();
for (String fileName : fileStoreFolder.list()) {
if (fileName.endsWith(".tar")) {
int pos = fileName.length() - "a.tar".length();
char generation = fileName.charAt(pos);
assertTrue("Expected generation is 'a', but instead was: '" + generation + "' for file " + fileName, generation == 'a');
}
}
} finally {
new ExecutorCloser(executorService).close();
fileStore.close();
new ExecutorCloser(scheduler).close();
}
}
use of org.apache.jackrabbit.oak.commons.concurrent.ExecutorCloser in project jackrabbit-oak by apache.
the class ActiveDeletedBlobCollectionIT method after.
@After
public void after() {
new ExecutorCloser(executorService).close();
executorService.shutdown();
IndexDefinition.setDisableStoredIndexDefinition(false);
}
use of org.apache.jackrabbit.oak.commons.concurrent.ExecutorCloser in project jackrabbit-oak by apache.
the class LucenePropertyIndexTest method after.
@After
public void after() {
new ExecutorCloser(executorService).close();
IndexDefinition.setDisableStoredIndexDefinition(false);
}
use of org.apache.jackrabbit.oak.commons.concurrent.ExecutorCloser in project jackrabbit-oak by apache.
the class UploadStagingCacheTest method testConcurrentPutDelete.
private void testConcurrentPutDelete(int diff) throws Exception {
ListeningExecutorService executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(2));
closer.register(new ExecutorCloser(executorService));
//start immediately
taskLatch.countDown();
// Add immediately
List<ListenableFuture<Integer>> futures = put(folder);
// New task to put another file
File f2 = copyToFile(randomStream(diff, 4 * 1024), folder.newFile());
CountDownLatch putThreadLatch = new CountDownLatch(1);
CountDownLatch triggerLatch = new CountDownLatch(1);
SettableFuture<Optional<SettableFuture<Integer>>> future1 = putThread(executorService, diff, f2, stagingCache, putThreadLatch, triggerLatch);
putThreadLatch.countDown();
// wait for put thread to go ahead
callbackLatch.countDown();
ScheduledFuture<?> scheduledFuture = removeExecutor.schedule(stagingCache.new RemoveJob(), 0, TimeUnit.MILLISECONDS);
triggerLatch.await();
if (future1.get().isPresent()) {
futures.add(future1.get().get());
}
ListenableFuture<List<Integer>> listListenableFuture = Futures.successfulAsList(futures);
try {
listListenableFuture.get();
scheduledFuture.get();
} catch (Exception e) {
e.printStackTrace();
}
assertTrue(Files.equal(copyToFile(randomStream(0, 4 * 1024), folder.newFile()), uploader.read(ID_PREFIX + 0)));
assertTrue(Files.equal(copyToFile(randomStream(diff, 4 * 1024), folder.newFile()), uploader.read(ID_PREFIX + diff)));
}
Aggregations