@Override public Editor getIndexEditor(@NotNull String type, @NotNull NodeBuilder definition, @NotNull NodeState root, @NotNull IndexUpdateCallback callback) { IndexingContext context = ((ContextAwareCallback)callback).getIndexingContext(); if (indexPathToFail != null && indexPathToFail.equals(context.getIndexPath())){ RuntimeException e = new RuntimeException(); context.indexUpdateFailed(e); throw e; } return super.getIndexEditor(type, definition, root, callback); }
private static CommitContext getCommitContext(IndexingContext indexingContext) { return (CommitContext) indexingContext.getCommitInfo().getInfo().get(CommitContext.NAME); } }
@Nullable @Override public Editor getIndexEditor(@NotNull String type, @NotNull NodeBuilder definition, @NotNull NodeState root, @NotNull IndexUpdateCallback callback) throws CommitFailedException { ContextAwareCallback ccb = (ContextAwareCallback) callback; if (semaphore != null && ccb.getIndexingContext().isAsync()) { semaphore.acquireUninterruptibly(); } return null; }
@Test public void contextAwareCallback() throws Exception{ NodeState before = builder.getNodeState(); createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "rootIndex", true, false, ImmutableSet.of("foo"), null); NodeState after = builder.getNodeState(); CallbackCapturingProvider provider = new CallbackCapturingProvider(); EditorHook hook = new EditorHook(new IndexUpdateProvider(provider)); CommitInfo info = new CommitInfo("foo", "bar"); NodeState indexed = hook.processCommit(before, after, info); assertNotNull(provider.callback); assertThat(provider.callback, instanceOf(ContextAwareCallback.class)); ContextAwareCallback contextualCallback = (ContextAwareCallback) provider.callback; IndexingContext context = contextualCallback.getIndexingContext(); assertNotNull(context); assertEquals("/oak:index/rootIndex", context.getIndexPath()); assertTrue(context.isReindexing()); assertFalse(context.isAsync()); assertSame(info, context.getCommitInfo()); before = indexed; builder = indexed.builder(); builder.child("a").setProperty("foo", "bar"); after = builder.getNodeState(); hook.processCommit(before, after, info); assertFalse(((ContextAwareCallback)provider.callback).getIndexingContext().isReindexing()); }
IndexingContext indexingContext = ((ContextAwareCallback)callback).getIndexingContext(); BlobDeletionCallback blobDeletionCallback = activeDeletedBlobCollector.getBlobDeletionCallback(); indexingContext.registerIndexCommitCallback(blobDeletionCallback); FulltextIndexWriterFactory writerFactory = null; LuceneIndexDefinition indexDefinition = null; boolean asyncIndexing = true; String indexPath = indexingContext.getIndexPath(); Collection<PropertyUpdateCallback> callbacks = new LinkedList<>(); PropertyIndexUpdateCallback propertyIndexUpdateCallback = null; if (nrtIndexingEnabled() && !indexingContext.isAsync() && IndexDefinition.supportsSyncOrNRTIndexing(definition)) { if (indexingContext.isReindexing()){ return null;
@Override @Nullable public Editor getIndexEditor(@NotNull String type, @NotNull NodeBuilder definition, @NotNull NodeState root, @NotNull IndexUpdateCallback callback) throws CommitFailedException { if (OrderedIndex.TYPE.equals(type)) { if (hit() % threshold == 0) { if (callback instanceof ContextAwareCallback) { LOG.warn(DEPRECATION_MESSAGE, ((ContextAwareCallback)callback).getIndexingContext().getIndexPath()); } else { LOG.warn(OrderedIndex.DEPRECATION_MESSAGE, definition); } } } return null; }
private boolean addOrUpdate(String path, NodeState state, boolean isUpdate) throws CommitFailedException { try { Document d = makeDocument(path, state, isUpdate); if (d != null) { if (log.isTraceEnabled()) { log.trace("[{}] Indexed document for {} is {}", getIndexName(), path, d); } context.indexUpdate(); context.getWriter().updateDocument(path, d); return true; } } catch (IOException e) { CommitFailedException ce = new CommitFailedException("Lucene", 3, "Failed to index the node " + path, e); context.getIndexingContext().indexUpdateFailed(ce); throw ce; } catch (IllegalArgumentException ie) { log.warn("Failed to index the node [{}]", path, ie); } return false; }
@Test public void shouldNotReindexAsyncIndexInSyncMode() throws Exception{ String indexPath = "/oak:index/rootIndex"; CallbackCapturingProvider provider = new CallbackCapturingProvider(); IndexUpdateProvider indexUpdate = new IndexUpdateProvider(provider); EditorHook hook = new EditorHook(indexUpdate); NodeState before = builder.getNodeState(); NodeBuilder idx = createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "rootIndex", true, false, ImmutableSet.of("foo"), null); idx.setProperty("async", asList("async", "sync"), Type.STRINGS); builder.child("a").setProperty("foo", "abc"); NodeState after = builder.getNodeState(); NodeState indexed = hook.processCommit(before, after, CommitInfo.EMPTY); assertFalse(provider.getContext(indexPath).isReindexing()); }
context.registerIndexCommitCallback(callback1); context.registerIndexCommitCallback(callback2); context.registerIndexCommitCallback(callback1);//intentionally adding same one twice
IndexingContext indexingContext = ((ContextAwareCallback)callback).getIndexingContext(); BlobDeletionCallback blobDeletionCallback = activeDeletedBlobCollector.getBlobDeletionCallback(); indexingContext.registerIndexCommitCallback(blobDeletionCallback); FulltextIndexWriterFactory writerFactory = null; LuceneIndexDefinition indexDefinition = null; boolean asyncIndexing = true; String indexPath = indexingContext.getIndexPath(); Collection<PropertyUpdateCallback> callbacks = new LinkedList<>(); PropertyIndexUpdateCallback propertyIndexUpdateCallback = null; if (nrtIndexingEnabled() && !indexingContext.isAsync() && IndexDefinition.supportsSyncOrNRTIndexing(definition)) { if (indexingContext.isReindexing()){ return null;
@Override @CheckForNull public Editor getIndexEditor(@Nonnull String type, @Nonnull NodeBuilder definition, @Nonnull NodeState root, @Nonnull IndexUpdateCallback callback) throws CommitFailedException { if (OrderedIndex.TYPE.equals(type)) { if (hit() % threshold == 0) { if (callback instanceof ContextAwareCallback) { LOG.warn(DEPRECATION_MESSAGE, ((ContextAwareCallback)callback).getIndexingContext().getIndexPath()); } else { LOG.warn(OrderedIndex.DEPRECATION_MESSAGE, definition); } } } return null; }
private boolean addOrUpdate(String path, NodeState state, boolean isUpdate) throws CommitFailedException { try { D d = makeDocument(path, state, isUpdate); if (d != null) { if (log.isTraceEnabled()) { log.trace("[{}] Indexed document for {} is {}", getIndexName(), path, d); } context.indexUpdate(); context.getWriter().updateDocument(path, d); return true; } } catch (IOException e) { CommitFailedException ce = new CommitFailedException("Fulltext", 3, "Failed to index the node " + path, e); context.getIndexingContext().indexUpdateFailed(ce); throw ce; } catch (IllegalArgumentException ie) { log.warn("Failed to index the node [{}]", path, ie); } return false; }
@Test public void ignoreReindexingFlag() throws Exception{ String indexPath = "/oak:index/rootIndex"; CallbackCapturingProvider provider = new CallbackCapturingProvider(); IndexUpdateProvider indexUpdate = new IndexUpdateProvider(provider); EditorHook hook = new EditorHook(indexUpdate); NodeState before = builder.getNodeState(); createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "rootIndex", true, false, ImmutableSet.of("foo"), null); builder.child("a").setProperty("foo", "abc"); NodeState after = builder.getNodeState(); NodeState indexed = hook.processCommit(before, after, CommitInfo.EMPTY); assertTrue(provider.getContext(indexPath).isReindexing()); before = indexed; builder = before.builder(); builder.child("b").setProperty("foo", "xyz"); child(builder, indexPath).setProperty(IndexConstants.REINDEX_PROPERTY_NAME, true); after = builder.getNodeState(); provider.reset(); indexed = hook.processCommit(before, after, CommitInfo.EMPTY); assertTrue(provider.getContext(indexPath).isReindexing()); //Now set IndexUpdate to ignore the reindex flag indexUpdate.setIgnoreReindexFlags(true); indexed = hook.processCommit(before, after, CommitInfo.EMPTY); assertFalse(provider.getContext(indexPath).isReindexing()); //Despite reindex flag set to true and reindexing not done new //content should still get picked up PropertyIndexLookup lookup = new PropertyIndexLookup(indexed); assertFalse(find(lookup, "foo", "xyz").isEmpty()); }
@Test public void indexUpdateToleratesMalignCommitProgressCallback() throws Exception { final IndexUpdateCallback noop = new IndexUpdateCallback() { @Override public void indexUpdate() { } }; NodeState before = builder.getNodeState(); createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "rootIndex", true, false, ImmutableSet.of("foo"), null); NodeState after = builder.getNodeState(); CallbackCapturingProvider provider = new CallbackCapturingProvider(); IndexUpdate indexUpdate = new IndexUpdate(provider, null, after, builder, noop); indexUpdate.enter(before, after); ContextAwareCallback contextualCallback = (ContextAwareCallback) provider.callback; IndexingContext context = contextualCallback.getIndexingContext(); context.registerIndexCommitCallback(new IndexCommitCallback() { @Override public void commitProgress(IndexProgress indexProgress) { throw new NullPointerException("Malign callback"); } }); indexUpdate.commitProgress(IndexCommitCallback.IndexProgress.COMMIT_SUCCEDED); }
@Override public Editor childNodeDeleted(String name, NodeState before) throws CommitFailedException { PathFilter.Result filterResult = getPathFilterResult(name); if (filterResult == PathFilter.Result.EXCLUDE) { return null; } if (!isDeleted) { // tree deletion is handled on the parent node String path = concat(getPath(), name); try { FulltextIndexWriter writer = context.getWriter(); // Remove all index entries in the removed subtree writer.deleteDocuments(path); this.context.indexUpdate(); } catch (IOException e) { CommitFailedException ce = new CommitFailedException("Fulltext", 5, "Failed to remove the index entries of" + " the removed subtree " + path + "for index " + context.getIndexingContext().getIndexPath(), e); context.getIndexingContext().indexUpdateFailed(ce); throw ce; } } MatcherState ms = getMatcherState(name, before); if (!ms.isEmpty()){ return new FulltextIndexEditor<>(this, name, ms, filterResult, true); } return null; // no need to recurse down the removed subtree }
@Override @Nullable public Editor getIndexEditor(@NotNull String type, @NotNull NodeBuilder definition, @NotNull NodeState root, @NotNull IndexUpdateCallback callback) throws CommitFailedException { if (OrderedIndex.TYPE.equals(type)) { if (hit() % threshold == 0) { if (callback instanceof ContextAwareCallback) { LOG.warn(DEPRECATION_MESSAGE, ((ContextAwareCallback)callback).getIndexingContext().getIndexPath()); } else { LOG.warn(OrderedIndex.DEPRECATION_MESSAGE, definition); } } } return null; }
private static CommitContext getCommitContext(IndexingContext indexingContext) { return (CommitContext) indexingContext.getCommitInfo().getInfo().get(CommitContext.NAME); } }
private boolean addOrUpdate(String path, NodeState state, boolean isUpdate) throws CommitFailedException { try { Document d = makeDocument(path, state, isUpdate); if (d != null) { if (log.isTraceEnabled()) { log.trace("[{}] Indexed document for {} is {}", getIndexName(), path, d); } context.indexUpdate(); context.getWriter().updateDocument(path, d); return true; } } catch (IOException e) { CommitFailedException ce = new CommitFailedException("Lucene", 3, "Failed to index the node " + path, e); context.getIndexingContext().indexUpdateFailed(ce); throw ce; } catch (IllegalArgumentException ie) { log.warn("Failed to index the node [{}]", path, ie); } return false; }
@Test public void contextAwareCallback_async() throws Exception{ NodeState before = builder.getNodeState(); NodeBuilder idx = createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "rootIndex", true, false, ImmutableSet.of("foo"), null); idx.setProperty("async", asList("sync", "async"), Type.STRINGS); NodeState after = builder.getNodeState(); CallbackCapturingProvider provider = new CallbackCapturingProvider(); EditorHook hook = new EditorHook(new IndexUpdateProvider(provider, "async", false)); hook.processCommit(before, after, CommitInfo.EMPTY); assertTrue(((ContextAwareCallback)provider.callback).getIndexingContext().isAsync()); }
} catch (IOException e) { CommitFailedException ce = new CommitFailedException("Lucene", 4, "Failed to close the Lucene index " + context.getIndexingContext().getIndexPath(), e); context.getIndexingContext().indexUpdateFailed(ce); throw ce;