From 86befafe6711576c4801141a9069b899f0d69425 Mon Sep 17 00:00:00 2001 From: mbaedke Date: Wed, 8 May 2024 12:27:45 +0200 Subject: [PATCH] OAK-10784: o.a.j.o.plugins.migration.version.VersionableEditor should create the version storage node, if needed (#1438) Implemented; improved logging. --- .../oak/plugins/migration/version/VersionableEditor.java | 9 +++++---- .../migration/version/VersionablePropertiesEditor.java | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/migration/version/VersionableEditor.java b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/migration/version/VersionableEditor.java index 5a84a04caa3..e9f41720683 100644 --- a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/migration/version/VersionableEditor.java +++ b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/migration/version/VersionableEditor.java @@ -37,6 +37,7 @@ import static org.apache.jackrabbit.JcrConstants.JCR_UUID; import static org.apache.jackrabbit.JcrConstants.MIX_REFERENCEABLE; import static org.apache.jackrabbit.JcrConstants.MIX_VERSIONABLE; +import static org.apache.jackrabbit.oak.plugins.migration.version.VersionHistoryUtil.createVersionStorage; import static org.apache.jackrabbit.oak.spi.version.VersionConstants.MIX_REP_VERSIONABLE_PATHS; import static org.apache.jackrabbit.oak.plugins.migration.version.VersionHistoryUtil.addMixin; import static org.apache.jackrabbit.oak.plugins.migration.version.VersionHistoryUtil.getVersionHistoryBuilder; @@ -79,7 +80,7 @@ public class VersionableEditor extends DefaultEditor { private VersionableEditor(Provider provider, NodeBuilder rootBuilder) { this.rootBuilder = rootBuilder; - this.versionStorage = getVersionStorage(rootBuilder); + this.versionStorage = createVersionStorage(rootBuilder); this.vMgr = new ReadWriteVersionManager(versionStorage, rootBuilder); this.provider = provider; @@ -140,8 +141,8 @@ public Editor childNodeAdded(String name, NodeState after) throws CommitFailedEx NodeBuilder versionableBuilder = getNodeBuilder(rootBuilder, this.path); removeVersionProperties(versionableBuilder, isReferenceable); if (isVersionable.test(versionableBuilder.getNodeState())) { - logger.warn("Node {} is still versionable. Creating initial version history.", path); - createEmptyHistory(versionableBuilder); + logger.warn("Node {} is still versionable due to node type constraints. Creating initial version history.", path); + createInitialHistory(versionableBuilder); } } } @@ -169,7 +170,7 @@ private boolean isVersionHistoryExists(String versionableUuid) { return getVersionHistoryBuilder(versionStorage, versionableUuid).exists(); } - private void createEmptyHistory(NodeBuilder versionable) throws CommitFailedException { + private void createInitialHistory(NodeBuilder versionable) throws CommitFailedException { vMgr.getOrCreateVersionHistory(versionable, Collections.emptyMap()); } diff --git a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/migration/version/VersionablePropertiesEditor.java b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/migration/version/VersionablePropertiesEditor.java index 4016dfb810a..257852116e5 100644 --- a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/migration/version/VersionablePropertiesEditor.java +++ b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/migration/version/VersionablePropertiesEditor.java @@ -49,8 +49,8 @@ import static org.apache.jackrabbit.oak.api.Type.REFERENCE; import static org.apache.jackrabbit.oak.api.Type.REFERENCES; import static org.apache.jackrabbit.oak.plugins.memory.MultiGenericPropertyState.nameProperty; +import static org.apache.jackrabbit.oak.plugins.migration.version.VersionHistoryUtil.createVersionStorage; import static org.apache.jackrabbit.oak.plugins.migration.version.VersionHistoryUtil.getVersionHistoryNodeState; -import static org.apache.jackrabbit.oak.plugins.migration.version.VersionHistoryUtil.getVersionStorage; /** * The VersionablePropertiesEditor adds missing versionable properties. @@ -76,7 +76,7 @@ public final class VersionablePropertiesEditor extends DefaultEditor { private VersionablePropertiesEditor(NodeBuilder rootBuilder) { this.builder = rootBuilder; this.rootBuilder = rootBuilder; - this.versionStorage = getVersionStorage(rootBuilder); + this.versionStorage = createVersionStorage(rootBuilder); this.isVersionable = new TypePredicate(rootBuilder.getNodeState(), MIX_VERSIONABLE); this.isNtVersion = new TypePredicate(rootBuilder.getNodeState(), NT_VERSION); this.isFrozenNode = new TypePredicate(rootBuilder.getNodeState(), NT_FROZENNODE);