use of org.apache.jackrabbit.oak.plugins.index.lucene.directory.ActiveDeletedBlobCollectorFactory.BlobDeletionCallback in project jackrabbit-oak by apache.
the class ActiveDeletedBlobCollectorTest method simpleCase.
@Test
public void simpleCase() throws Exception {
BlobDeletionCallback bdc = adbc.getBlobDeletionCallback();
bdc.deleted("blobId", Collections.singleton("/a"));
bdc.commitProgress(COMMIT_SUCCEDED);
adbc.purgeBlobsDeleted(clock.getTimeIncreasing(), blobStore);
verifyBlobsDeleted("blobId");
}
use of org.apache.jackrabbit.oak.plugins.index.lucene.directory.ActiveDeletedBlobCollectorFactory.BlobDeletionCallback in project jackrabbit-oak by apache.
the class LuceneIndexEditorProvider method getIndexEditor.
@Override
public Editor getIndexEditor(@Nonnull String type, @Nonnull NodeBuilder definition, @Nonnull NodeState root, @Nonnull IndexUpdateCallback callback) throws CommitFailedException {
if (TYPE_LUCENE.equals(type)) {
checkArgument(callback instanceof ContextAwareCallback, "callback instance not of type " + "ContextAwareCallback [%s]", callback);
IndexingContext indexingContext = ((ContextAwareCallback) callback).getIndexingContext();
BlobDeletionCallback blobDeletionCallback = activeDeletedBlobCollector.getBlobDeletionCallback();
indexingContext.registerIndexCommitCallback(blobDeletionCallback);
indexWriterFactory = new DefaultIndexWriterFactory(mountInfoProvider, getDirectoryFactory(blobDeletionCallback));
LuceneIndexWriterFactory writerFactory = indexWriterFactory;
IndexDefinition indexDefinition = null;
boolean asyncIndexing = true;
if (!indexingContext.isAsync() && IndexDefinition.supportsSyncOrNRTIndexing(definition)) {
//incremental indexing
if (indexingContext.isReindexing()) {
return null;
}
CommitContext commitContext = getCommitContext(indexingContext);
if (commitContext == null) {
//Logically there should not be any commit without commit context. But
//some initializer code does the commit with out it. So ignore such calls with
//warning now
//TODO Revisit use of warn level once all such cases are analyzed
log.warn("No CommitContext found for commit", new Exception());
return null;
}
//TODO Also check if index has been done once
writerFactory = new LocalIndexWriterFactory(getDocumentHolder(commitContext), indexingContext.getIndexPath());
//creating definition instance for each commit as this gets executed for each commit
if (indexTracker != null) {
indexDefinition = indexTracker.getIndexDefinition(indexingContext.getIndexPath());
if (indexDefinition != null && !indexDefinition.hasMatchingNodeTypeReg(root)) {
log.debug("Detected change in NodeType registry for index {}. Would not use " + "existing index definition", indexDefinition.getIndexPath());
indexDefinition = null;
}
}
//Pass on a read only builder to ensure that nothing gets written
//at all to NodeStore for local indexing.
//TODO [hybrid] This would cause issue with Facets as for faceted fields
//some stuff gets written to NodeBuilder. That logic should be refactored
//to be moved to LuceneIndexWriter
definition = new ReadOnlyBuilder(definition.getNodeState());
asyncIndexing = false;
}
LuceneIndexEditorContext context = new LuceneIndexEditorContext(root, definition, indexDefinition, callback, writerFactory, extractedTextCache, augmentorFactory, indexingContext, asyncIndexing);
return new LuceneIndexEditor(context);
}
return null;
}
use of org.apache.jackrabbit.oak.plugins.index.lucene.directory.ActiveDeletedBlobCollectorFactory.BlobDeletionCallback in project jackrabbit-oak by apache.
the class ActiveDeletedBlobCollectorTest method multiThreadedCommits.
@Test
public void multiThreadedCommits() throws Exception {
clock = Clock.SIMPLE;
ExecutorService executorService = Executors.newFixedThreadPool(3);
adbc = ActiveDeletedBlobCollectorFactory.newInstance(new File(blobCollectionRoot.getRoot(), "b"), executorService);
int numThreads = 4;
int numBlobsPerThread = 500;
List<Thread> threads = new ArrayList<>(numThreads);
final AtomicInteger threadIndex = new AtomicInteger(0);
for (; threadIndex.get() < numThreads; threadIndex.incrementAndGet()) {
threads.add(new Thread(new Runnable() {
private int thisThreadNum = threadIndex.get();
@Override
public void run() {
int blobCnt = 0;
while (blobCnt < numBlobsPerThread) {
BlobDeletionCallback bdc = adbc.getBlobDeletionCallback();
for (; blobCnt < numBlobsPerThread; ) {
String id = "Thread" + thisThreadNum + "Blob" + blobCnt;
bdc.deleted(id, Collections.singleton(id));
blobCnt++;
if (Math.random() > 0.5) {
break;
}
}
bdc.commitProgress(COMMIT_SUCCEDED);
try {
Thread.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}));
}
for (Thread t : threads) {
t.start();
}
for (Thread t : threads) {
t.join();
}
// Push one more commit to flush out any remaining ones
adbc.getBlobDeletionCallback().commitProgress(COMMIT_SUCCEDED);
executorService.awaitTermination(100, TimeUnit.MILLISECONDS);
List<String> deletedChunks = new ArrayList<>(numThreads * numBlobsPerThread * 2);
for (int threadNum = 0; threadNum < numThreads; threadNum++) {
for (int blobCnt = 0; blobCnt < numBlobsPerThread; blobCnt++) {
String id = "Thread" + threadNum + "Blob" + blobCnt;
Iterators.addAll(deletedChunks, blobStore.resolveChunks(id));
}
}
adbc.purgeBlobsDeleted(clock.getTimeIncreasing(), blobStore);
assertThat(blobStore.deletedChunkIds, containsInAnyOrder(deletedChunks.toArray()));
}
use of org.apache.jackrabbit.oak.plugins.index.lucene.directory.ActiveDeletedBlobCollectorFactory.BlobDeletionCallback in project jackrabbit-oak by apache.
the class ActiveDeletedBlobCollectorTest method blobTimestampMustBeBiggerThanFileTimestamp.
@Test
public void blobTimestampMustBeBiggerThanFileTimestamp() throws Exception {
BlobDeletionCallback bdc1 = adbc.getBlobDeletionCallback();
bdc1.deleted("blobId1", Collections.singleton("/a"));
bdc1.commitProgress(COMMIT_SUCCEDED);
BlobDeletionCallback bdc2 = adbc.getBlobDeletionCallback();
bdc2.deleted("blobId2", Collections.singleton("/b"));
BlobDeletionCallback bdc3 = adbc.getBlobDeletionCallback();
bdc3.deleted("blobId3", Collections.singleton("/c"));
bdc3.commitProgress(COMMIT_SUCCEDED);
long time = clock.getTimeIncreasing();
clock.waitUntil(clock.getTime() + TimeUnit.MINUTES.toMillis(1));
bdc2.commitProgress(COMMIT_SUCCEDED);
adbc.purgeBlobsDeleted(time, blobStore);
//blobId2 is committed later
verifyBlobsDeleted("blobId1", "blobId3");
}
use of org.apache.jackrabbit.oak.plugins.index.lucene.directory.ActiveDeletedBlobCollectorFactory.BlobDeletionCallback in project jackrabbit-oak by apache.
the class ActiveDeletedBlobCollectorTest method noopDoesNothing.
@Test
public void noopDoesNothing() throws Exception {
adbc = ActiveDeletedBlobCollectorFactory.NOOP;
BlobDeletionCallback bdc = adbc.getBlobDeletionCallback();
bdc.deleted("blobId", Collections.singleton("/a"));
bdc.commitProgress(COMMIT_SUCCEDED);
adbc.purgeBlobsDeleted(clock.getTimeIncreasing(), blobStore);
verifyBlobsDeleted();
}
Aggregations