use of org.apache.jackrabbit.oak.spi.commit.Editor in project jackrabbit-oak by apache.
the class LuceneIndexEditorProviderTest method editorNullInCaseOfReindex.
@Test
public void editorNullInCaseOfReindex() throws Exception {
LuceneIndexEditorProvider editorProvider = new LuceneIndexEditorProvider(null, null, null, null, Mounts.defaultMountInfoProvider());
IndexUpdateCallback callback = new TestCallback("/oak:index/fooIndex", newCommitInfo(), true, false);
NodeBuilder defnBuilder = createIndexDefinition("fooIndex").builder();
Editor editor = editorProvider.getIndexEditor(TYPE_LUCENE, defnBuilder, root, callback);
assertNull(editor);
}
use of org.apache.jackrabbit.oak.spi.commit.Editor in project jackrabbit-oak by apache.
the class IndexUpdate method childNodeAdded.
@Override
@Nonnull
public Editor childNodeAdded(String name, NodeState after) throws CommitFailedException {
List<Editor> children = newArrayListWithCapacity(1 + editors.size());
children.add(new IndexUpdate(this, name));
for (Editor editor : editors) {
Editor child = editor.childNodeAdded(name, after);
if (child != null) {
children.add(child);
}
}
return compose(children);
}
use of org.apache.jackrabbit.oak.spi.commit.Editor in project jackrabbit-oak by apache.
the class IndexUpdate method collectIndexEditors.
private void collectIndexEditors(NodeBuilder definitions, NodeState before) throws CommitFailedException {
for (String name : definitions.getChildNodeNames()) {
NodeBuilder definition = definitions.getChildNode(name);
if (isIncluded(rootState.async, definition)) {
String type = definition.getString(TYPE_PROPERTY_NAME);
if (type == null) {
// probably not an index def
continue;
}
boolean shouldReindex = shouldReindex(definition, before, name);
String indexPath = getIndexPath(getPath(), name);
if (definition.hasProperty(IndexConstants.CORRUPT_PROPERTY_NAME) && !shouldReindex) {
String corruptSince = definition.getProperty(IndexConstants.CORRUPT_PROPERTY_NAME).getValue(Type.DATE);
rootState.corruptIndexHandler.skippingCorruptIndex(rootState.async, indexPath, ISO8601.parse(corruptSince));
continue;
}
Editor editor = rootState.provider.getIndexEditor(type, definition, rootState.root, rootState.newCallback(indexPath, shouldReindex, getEstimatedCount(definition)));
if (editor == null) {
rootState.missingProvider.onMissingIndex(type, definition, indexPath);
} else if (shouldReindex) {
if (definition.getBoolean(REINDEX_ASYNC_PROPERTY_NAME) && definition.getString(ASYNC_PROPERTY_NAME) == null) {
// switch index to an async update mode
definition.setProperty(ASYNC_PROPERTY_NAME, ASYNC_REINDEX_VALUE);
} else {
definition.setProperty(REINDEX_PROPERTY_NAME, false);
incrementReIndexCount(definition);
// beforehand, we'll remove all child nodes
for (String rm : definition.getChildNodeNames()) {
if (NodeStateUtils.isHidden(rm)) {
definition.getChildNode(rm).remove();
}
}
clearCorruptFlag(definition, indexPath);
reindex.put(concat(getPath(), INDEX_DEFINITIONS_NAME, name), editor);
}
} else {
editors.add(editor);
}
}
}
}
use of org.apache.jackrabbit.oak.spi.commit.Editor in project jackrabbit-oak by apache.
the class IndexUpdateTest method testMissingProviderFailsCommit.
/**
* OAK-3505 Provide an optionally stricter policy for missing synchronous
* index editor providers
*/
@Test
public void testMissingProviderFailsCommit() throws Exception {
final IndexUpdateCallback noop = new IndexUpdateCallback() {
@Override
public void indexUpdate() {
}
};
final MissingIndexProviderStrategy mips = new MissingIndexProviderStrategy();
mips.setFailOnMissingIndexProvider(true);
EditorHook hook = new EditorHook(new EditorProvider() {
@Override
public Editor getRootEditor(NodeState before, NodeState after, NodeBuilder builder, CommitInfo info) throws CommitFailedException {
return new IndexUpdate(emptyProvider(), null, after, builder, noop).withMissingProviderStrategy(mips);
}
});
NodeState before = builder.getNodeState();
createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "rootIndex", true, false, ImmutableSet.of("foo"), null);
builder.child(INDEX_DEFINITIONS_NAME).child("azerty");
builder.child("testRoot").setProperty("foo", "abc");
NodeState after = builder.getNodeState();
try {
hook.processCommit(before, after, CommitInfo.EMPTY);
fail("commit should fail on missing index provider");
} catch (CommitFailedException ex) {
// expected
}
}
use of org.apache.jackrabbit.oak.spi.commit.Editor in project jackrabbit-oak by apache.
the class TypeEditorProvider method getRootEditor.
@Override
public Editor getRootEditor(NodeState before, NodeState after, NodeBuilder builder, CommitInfo info) throws CommitFailedException {
NodeState beforeTypes = before.getChildNode(JCR_SYSTEM).getChildNode(JCR_NODE_TYPES);
NodeState afterTypes = after.getChildNode(JCR_SYSTEM).getChildNode(JCR_NODE_TYPES);
String primary = after.getName(JCR_PRIMARYTYPE);
Iterable<String> mixins = after.getNames(JCR_MIXINTYPES);
TypeRegistration registration = new TypeRegistration();
afterTypes.compareAgainstBaseState(beforeTypes, registration);
if (registration.isModified()) {
ReadOnlyNodeTypeManager ntBefore = ReadOnlyNodeTypeManager.getInstance(RootFactory.createReadOnlyRoot(before), NamePathMapper.DEFAULT);
ReadOnlyNodeTypeManager ntAfter = ReadOnlyNodeTypeManager.getInstance(RootFactory.createReadOnlyRoot(after), NamePathMapper.DEFAULT);
afterTypes = registration.apply(builder);
Set<String> modifiedTypes = registration.getModifiedTypes(beforeTypes);
if (!modifiedTypes.isEmpty()) {
boolean modified = false;
for (String t : modifiedTypes) {
boolean mod = !isTrivialChange(ntBefore, ntAfter, t);
modified = modified || mod;
}
if (!modified) {
LOG.info("Node type changes: " + modifiedTypes + " appear to be trivial, repository will not be scanned");
} else {
long start = System.currentTimeMillis();
// Some node types were modified, so scan the repository
// to make sure that the modified definitions still apply.
Editor editor = new VisibleEditor(new TypeEditor(strict, modifiedTypes, afterTypes, primary, mixins, builder));
LOG.info("Node type changes: " + modifiedTypes + " appear not to be trivial, starting repository scan");
CommitFailedException exception = EditorDiff.process(editor, MISSING_NODE, after);
LOG.info("Node type changes: " + modifiedTypes + "; repository scan took " + (System.currentTimeMillis() - start) + "ms" + (exception == null ? "" : "; failed with " + exception.getMessage()));
if (exception != null) {
throw exception;
}
}
}
}
return new VisibleEditor(new TypeEditor(strict, null, afterTypes, primary, mixins, builder));
}
Aggregations