Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ private void processDocs(String indexPath, Iterable<LuceneDoc> docs, boolean doc
doc.markProcessed();
}
if (doc.delete) {
writer.deleteDocuments(doc.docPath);
writer.deleteDocumentTree(doc.docPath);
} else {
writer.updateDocument(doc.docPath, doc.doc);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,18 @@ public void updateDocument(String path, Iterable<? extends IndexableField> doc)
}

@Override
public void deleteDocuments(String path) throws IOException {
public void deleteDocumentTree(String path) throws IOException {
//Hybrid index logic drops the deletes. So no use to
//add them to the list
//addLuceneDoc(LuceneDoc.forDelete(definition.getIndexPathFromConfig(), path));
}

@Override
public void deleteDocument(String path) throws IOException {
//Hybrid index logic drops the deletes. So no use to
//add them to the list
}

@Override
public boolean close(long timestamp) throws IOException {
documentHolder.done(indexPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,12 @@ public void updateDocument(String path, Iterable<? extends IndexableField> doc)
}

@Override
public void deleteDocuments(String path) throws IOException {
public void deleteDocumentTree(String path) throws IOException {
//Do not delete documents. Query side would handle it
}

@Override
public void deleteDocument(String path) throws IOException {
//Do not delete documents. Query side would handle it
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,16 @@ public void updateDocument(String path, Iterable<? extends IndexableField> doc)
}

@Override
public void deleteDocuments(String path) throws IOException {
public void deleteDocumentTree(String path) throws IOException {
getWriter().deleteDocuments(newPathTerm(path));
getWriter().deleteDocuments(new PrefixQuery(newPathTerm(path + "/")));
}

@Override
public void deleteDocument(String path) throws IOException {
getWriter().deleteDocuments(newPathTerm(path));
}

void deleteAll() throws IOException {
getWriter().deleteAll();
indexUpdated = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,31 @@ public void execute() throws IOException {
}
}

private static class DeleteOperation extends Operation {
private static class DeleteTreeOperation extends Operation {
private final String path;

DeleteOperation(LuceneIndexWriter delegate, String path) {
DeleteTreeOperation(LuceneIndexWriter delegate, String path) {
super(delegate);
this.path = path;
}

@Override
public void execute() throws IOException {
delegate.deleteDocuments(path);
delegate.deleteDocumentTree(path);
}
}

private static class DeleteDocumentOperation extends Operation {
private final String path;

DeleteDocumentOperation(LuceneIndexWriter delegate, String path) {
super(delegate);
this.path = path;
}

@Override
public void execute() throws IOException {
delegate.deleteDocument(path);
}
}

Expand Down Expand Up @@ -280,10 +294,16 @@ public void updateDocument(LuceneIndexWriter writer, String path, Iterable<? ext
enqueueOperation(new UpdateOperation(writer, path, doc));
}

public void deleteDocuments(LuceneIndexWriter writer, String path) throws IOException {
public void deleteDocumentTree(LuceneIndexWriter writer, String path) throws IOException {
checkOpen();
this.deleteCount++;
enqueueOperation(new DeleteTreeOperation(writer, path));
}

public void deleteDocument(LuceneIndexWriter writer, String path) throws IOException {
checkOpen();
this.deleteCount++;
enqueueOperation(new DeleteOperation(writer, path));
enqueueOperation(new DeleteDocumentOperation(writer, path));
}

public boolean closeWriter(LuceneIndexWriter writer, long timestamp) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ public void updateDocument(String path, Iterable<? extends IndexableField> doc)
}

@Override
public void deleteDocuments(String path) throws IOException {
public void deleteDocumentTree(String path) throws IOException {
Mount mount = mountInfoProvider.getMountByPath(path);
getWriter(mount).deleteDocuments(path);
getWriter(mount).deleteDocumentTree(path);

//In case of default mount look for other mounts with roots under this path
//Note that one mount cannot be part of another mount
Expand All @@ -76,6 +76,13 @@ public void deleteDocuments(String path) throws IOException {
}
}

@Override
public void deleteDocument(String path) throws IOException {
// Single-document delete: no mount-under-path cleanup needed
Mount mount = mountInfoProvider.getMountByPath(path);
getWriter(mount).deleteDocument(path);
}

@Override
public boolean close(long timestamp) throws IOException {
// explicitly get writers for mounts which haven't got writers even at close.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,14 @@ public void updateDocument(String path, Iterable<? extends IndexableField> doc)
}

@Override
public void deleteDocuments(String path) throws IOException {
writerPool.deleteDocuments(delegateWriter, path);
public void deleteDocumentTree(String path) throws IOException {
writerPool.deleteDocumentTree(delegateWriter, path);
deleteCount++;
}

@Override
public void deleteDocument(String path) throws IOException {
writerPool.deleteDocument(delegateWriter, path);
deleteCount++;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public void nodeLosesMixinTriggersDocumentDeletion() throws Exception {
builder = before.builder();
builder.child("a").removeProperty(JcrConstants.JCR_MIXINTYPES);
hook.processCommit(before, builder.getNodeState(), CommitInfo.EMPTY);
assertTrue("Removing mixin should trigger deleteDocuments for the node", writer.deletedPaths.contains("/a"));
assertTrue("Removing mixin should trigger deleteDocument for the node", writer.deletedPaths.contains("/a"));
}

@Test
Expand Down Expand Up @@ -305,7 +305,7 @@ public void nodeLosesMixinDoesNotTriggerDocumentDeletionWhenToggleDisabled() thr
builder = before.builder();
builder.child("a").removeProperty(JcrConstants.JCR_MIXINTYPES);
hook.processCommit(before, builder.getNodeState(), CommitInfo.EMPTY);
assertFalse("Mixin tracking disabled: removing mixin should not trigger deleteDocuments", writer.deletedPaths.contains("/a"));
assertFalse("Mixin tracking disabled: removing mixin should not trigger deleteDocument", writer.deletedPaths.contains("/a"));
}

private void updateBefore(LuceneIndexDefinitionBuilder defnb) {
Expand Down Expand Up @@ -417,7 +417,12 @@ public void updateDocument(String path, Iterable<? extends IndexableField> doc)
}

@Override
public void deleteDocuments(String path) {
public void deleteDocumentTree(String path) {
deletedPaths.add(path);
}

@Override
public void deleteDocument(String path) {
deletedPaths.add(path);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,13 @@ public void updateDocument(String path, Iterable<? extends IndexableField> doc)
}

@Override
public void deleteDocuments(String path) {
public void deleteDocumentTree(String path) {
delay();
deletedPaths.add(path);
}

@Override
public void deleteDocument(String path) {
delay();
deletedPaths.add(path);
}
Expand Down Expand Up @@ -106,7 +112,7 @@ public void testSingleWriter() throws IOException {
TestWriter writer = new TestWriter();
Document doc = TestUtil.newDoc("value");
indexWriterPool.updateDocument(writer, "test", doc);
indexWriterPool.deleteDocuments(writer, "test");
indexWriterPool.deleteDocumentTree(writer, "test");
boolean closeResult = indexWriterPool.closeWriter(writer, 30);
indexWriterPool.close();

Expand Down Expand Up @@ -163,7 +169,7 @@ public void testCloseWriterPoolWithoutClosingWriters() throws IOException {
TestWriter writer = new TestWriter(100);
Document doc = TestUtil.newDoc("value");
indexWriterPool.updateDocument(writer, "test", doc);
indexWriterPool.deleteDocuments(writer, "test-deletion");
indexWriterPool.deleteDocumentTree(writer, "test-deletion");
indexWriterPool.close();

assertEquals(Map.of("test", doc), writer.docs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,14 @@ public void deletes() throws Exception{
assertEquals(2, numDocs(defaultMount));

writer = factory.newInstance(defn, builder, null, true);
writer.deleteDocuments("/libs/config");
writer.deleteDocumentTree("/libs/config");
writer.close(0);

assertEquals(1, numDocs(fooMount));
assertEquals(2, numDocs(defaultMount));

writer = factory.newInstance(defn, builder, null, true);
writer.deleteDocuments("/content");
writer.deleteDocumentTree("/content");
writer.close(0);

assertEquals(1, numDocs(fooMount));
Expand All @@ -240,7 +240,7 @@ public void deleteIncludingMount() throws Exception{
assertEquals(2, numDocs(defaultMount));

writer = factory.newInstance(defn, builder, null, true);
writer.deleteDocuments("/content");
writer.deleteDocumentTree("/content");
writer.close(0);

assertEquals(0, numDocs(fooMount));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
import java.util.Hashtable;
import java.util.List;

import org.apache.jackrabbit.oak.plugins.index.search.spi.editor.FulltextIndexEditor;

import static java.util.Collections.emptyMap;

import static org.apache.jackrabbit.oak.spi.whiteboard.WhiteboardUtils.registerMBean;
Expand Down Expand Up @@ -227,6 +229,9 @@ private void activate(BundleContext bundleContext, Config config) {
oakRegs.add(whiteboard.register(FeatureToggle.class,
new FeatureToggle(ElasticConnection.FT_OAK_12234, ElasticConnection.FT_OAK_12234_DISABLE),
emptyMap()));
oakRegs.add(whiteboard.register(FeatureToggle.class,
new FeatureToggle(FulltextIndexEditor.FT_OAK_12244, FulltextIndexEditor.FT_OAK_12244_DISABLE),
emptyMap()));
if (System.getProperty(QueryEngineSettings.OAK_INFERENCE_ENABLED) != null) {
this.isInferenceEnabled = Boolean.parseBoolean(System.getProperty(QueryEngineSettings.OAK_INFERENCE_ENABLED));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public void updateDocument(String path, ElasticDocument doc) throws IOException
}

@Override
public void deleteDocuments(String path) throws IOException {
public void deleteDocumentTree(String path) throws IOException {
retryPolicy.withRetries(() -> bulkProcessorHandler.delete(indexName, ElasticIndexUtils.idFromPath(path)));
if (!ElasticIndexEditorProvider.FT_OAK_12206_DISABLE.get()) {
// Delete all descendants: mirrors Lucene's PrefixQuery on the path term.
Expand All @@ -187,6 +187,12 @@ public void deleteDocuments(String path) throws IOException {
}
}

@Override
public void deleteDocument(String path) throws IOException {
// Exact-document delete: no descendant sweep
retryPolicy.withRetries(() -> bulkProcessorHandler.delete(indexName, ElasticIndexUtils.idFromPath(path)));
}

@Override
public boolean close(long timestamp) throws IOException {
boolean updateStatus = bulkProcessorHandler.flushIndex(indexName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public void singleUpdateDocument() throws IOException {

@Test
public void singleDeleteDocument() throws IOException {
indexWriter.deleteDocuments("/bar");
indexWriter.deleteDocumentTree("/bar");

ArgumentCaptor<String> idCaptor = ArgumentCaptor.forClass(String.class);
verify(bulkProcessorHandlerMock).delete(eq(indexAlias), idCaptor.capture());
Expand All @@ -127,8 +127,8 @@ public void singleDeleteDocument() throws IOException {
public void multiRequests() throws IOException {
indexWriter.updateDocument("/foo", new ElasticDocument("/foo"));
indexWriter.updateDocument("/bar", new ElasticDocument("/bar"));
indexWriter.deleteDocuments("/foo");
indexWriter.deleteDocuments("/bar");
indexWriter.deleteDocumentTree("/foo");
indexWriter.deleteDocumentTree("/bar");

verify(bulkProcessorHandlerMock, times(2)).index(eq(indexAlias), anyString(), any(ElasticDocument.class));
verify(bulkProcessorHandlerMock, times(2)).delete(eq(indexAlias), anyString());
Expand Down Expand Up @@ -182,7 +182,7 @@ public void splitLargeString() {
@Test
public void ft_oak_12206_toggleShouldBeRemoved() {
// Time-bombed: if this test fails, the feature toggle FT_OAK-12206 and its guard in
// ElasticIndexWriter#deleteDocuments should be removed — the fix has been in production long enough.
// ElasticIndexWriter#deleteDocumentTree should be removed — the fix has been in production long enough.
assertTrue("Feature toggle " + ElasticIndexEditorProvider.FT_OAK_12206 + " is overdue for removal",
LocalDate.now().isBefore(LocalDate.of(2027, 5, 6)));
}
Expand Down
Loading