Author: jsedding
Date: Sun Oct 4 13:50:12 2015
New Revision: 1706680
URL: http://svn.apache.org/viewvc?rev=1706680&view=rev
Log:
OAK-3469 - Fix naming in oak-upgrade
- cleaned up the naming by removing "parent" and adding "root" where appropriate
- swapped method arguments to consistently be "source" before "target"
Modified:
jackrabbit/oak/trunk/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/RepositorySidegrade.java
jackrabbit/oak/trunk/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/RepositoryUpgrade.java
jackrabbit/oak/trunk/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/nodestate/NodeStateCopier.java
jackrabbit/oak/trunk/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/version/VersionCopier.java
Modified:
jackrabbit/oak/trunk/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/RepositorySidegrade.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/RepositorySidegrade.java?rev=1706680&r1=1706679&r2=1706680&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/RepositorySidegrade.java
(original)
+++
jackrabbit/oak/trunk/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/RepositorySidegrade.java
Sun Oct 4 13:50:12 2015
@@ -30,7 +30,6 @@ import org.apache.jackrabbit.oak.plugins
import org.apache.jackrabbit.oak.spi.commit.CommitHook;
import org.apache.jackrabbit.oak.spi.commit.CommitInfo;
import org.apache.jackrabbit.oak.spi.commit.EditorHook;
-import org.apache.jackrabbit.oak.spi.commit.EmptyHook;
import org.apache.jackrabbit.oak.spi.lifecycle.RepositoryInitializer;
import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
import org.apache.jackrabbit.oak.spi.state.NodeState;
@@ -206,47 +205,51 @@ public class RepositorySidegrade {
*/
public void copy(RepositoryInitializer initializer) throws
RepositoryException {
try {
- NodeState root = source.getRoot();
- NodeBuilder builder = target.getRoot().builder();
+ NodeState sourceRoot = source.getRoot();
+ NodeBuilder targetRoot = target.getRoot().builder();
- new InitialContent().initialize(builder);
+ new InitialContent().initialize(targetRoot);
if (initializer != null) {
- initializer.initialize(builder);
+ initializer.initialize(targetRoot);
}
- copyState(builder, ReportingNodeState.wrap(root, new
LoggingReporter(LOG, "Copying", 10000, -1)));
+ copyState(
+ ReportingNodeState.wrap(sourceRoot, new
LoggingReporter(LOG, "Copying", 10000, -1)),
+ targetRoot
+ );
- cleanCheckpoints(builder);
} catch (Exception e) {
throw new RepositoryException("Failed to copy content", e);
}
}
- private void cleanCheckpoints(NodeBuilder builder) throws
CommitFailedException {
+ private void removeCheckpointReferences(NodeBuilder builder) throws
CommitFailedException {
// removing references to the checkpoints,
// which don't exist in the new repository
builder.setChildNode(":async");
- target.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
}
- private void copyState(NodeBuilder parent, NodeState state) throws
CommitFailedException {
- copyWorkspace(state, parent);
+ private void copyState(NodeState sourceRoot, NodeBuilder targetRoot)
throws CommitFailedException {
+ copyWorkspace(sourceRoot, targetRoot);
+ removeCheckpointReferences(targetRoot);
if (!versionCopyConfiguration.skipOrphanedVersionsCopy()) {
- copyVersionStorage(state, parent, versionCopyConfiguration);
+ copyVersionStorage(sourceRoot, targetRoot,
versionCopyConfiguration);
}
final List<CommitHook> hooks = new ArrayList<CommitHook>();
hooks.add(new EditorHook(
- new VersionableEditor.Provider(state,
Oak.DEFAULT_WORKSPACE_NAME, versionCopyConfiguration)));
+ new VersionableEditor.Provider(sourceRoot,
Oak.DEFAULT_WORKSPACE_NAME, versionCopyConfiguration)));
if (customCommitHooks != null) {
hooks.addAll(customCommitHooks);
}
- target.merge(parent, new LoggingCompositeHook(hooks, null, false),
CommitInfo.EMPTY);
+
+
+ target.merge(targetRoot, new LoggingCompositeHook(hooks, null, false),
CommitInfo.EMPTY);
}
- private void copyWorkspace(NodeState state, NodeBuilder parent) {
- final Set<String> includes =
calculateEffectiveIncludePaths(includePaths, state);
+ private void copyWorkspace(NodeState sourceRoot, NodeBuilder targetRoot) {
+ final Set<String> includes =
calculateEffectiveIncludePaths(includePaths, sourceRoot);
final Set<String> excludes = union(copyOf(this.excludePaths),
of("/jcr:system/jcr:versionStorage"));
final Set<String> merges = union(copyOf(this.mergePaths),
of("/jcr:system"));
@@ -254,6 +257,6 @@ public class RepositorySidegrade {
.include(includes)
.exclude(excludes)
.merge(merges)
- .copy(state, parent);
+ .copy(sourceRoot, targetRoot);
}
}
\ No newline at end of file
Modified:
jackrabbit/oak/trunk/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/RepositoryUpgrade.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/RepositoryUpgrade.java?rev=1706680&r1=1706679&r2=1706680&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/RepositoryUpgrade.java
(original)
+++
jackrabbit/oak/trunk/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/RepositoryUpgrade.java
Sun Oct 4 13:50:12 2015
@@ -348,9 +348,8 @@ public class RepositoryUpgrade {
RepositoryConfig config = source.getRepositoryConfig();
logger.info("Copying repository content from {} to Oak",
config.getHomeDir());
try {
- NodeState base = target.getRoot();
- NodeBuilder builder = base.builder();
- final Root upgradeRoot = new UpgradeRoot(builder);
+ NodeBuilder targetBuilder = target.getRoot().builder();
+ final Root upgradeRoot = new UpgradeRoot(targetBuilder);
String workspaceName =
source.getRepositoryConfig().getDefaultWorkspaceName();
@@ -359,26 +358,26 @@ public class RepositoryUpgrade {
// init target repository first
logger.info("Initializing initial repository content from {}",
config.getHomeDir());
- new InitialContent().initialize(builder);
+ new InitialContent().initialize(targetBuilder);
if (initializer != null) {
- initializer.initialize(builder);
+ initializer.initialize(targetBuilder);
}
logger.debug("InitialContent completed from {}",
config.getHomeDir());
for (SecurityConfiguration sc : security.getConfigurations()) {
RepositoryInitializer ri = sc.getRepositoryInitializer();
- ri.initialize(builder);
+ ri.initialize(targetBuilder);
logger.debug("Repository initializer '" +
ri.getClass().getName() + "' completed", config.getHomeDir());
}
for (SecurityConfiguration sc : security.getConfigurations()) {
WorkspaceInitializer wi = sc.getWorkspaceInitializer();
- wi.initialize(builder, workspaceName);
+ wi.initialize(targetBuilder, workspaceName);
logger.debug("Workspace initializer '" +
wi.getClass().getName() + "' completed", config.getHomeDir());
}
HashBiMap<String, String> uriToPrefix = HashBiMap.create();
logger.info("Copying registered namespaces");
- copyNamespaces(builder, uriToPrefix);
+ copyNamespaces(targetBuilder, uriToPrefix);
logger.debug("Namespace registration completed.");
logger.info("Copying registered node types");
@@ -406,28 +405,28 @@ public class RepositoryUpgrade {
// Triggers compilation of type information, which we need for
// the type predicates used by the bulk copy operations below.
new TypeEditorProvider(false).getRootEditor(
- base, builder.getNodeState(), builder, null);
+ targetBuilder.getBaseState(),
targetBuilder.getNodeState(), targetBuilder, null);
- NodeState root = builder.getNodeState();
-
- final NodeState sourceState = ReportingNodeState.wrap(
+ final NodeState sourceRoot = ReportingNodeState.wrap(
JackrabbitNodeState.createRootNodeState(
- source, workspaceName, root, uriToPrefix,
copyBinariesByReference, skipOnError),
+ source, workspaceName,
targetBuilder.getNodeState(),
+ uriToPrefix, copyBinariesByReference, skipOnError
+ ),
new LoggingReporter(logger, "Migrating", 10000, -1)
);
final Stopwatch watch = Stopwatch.createStarted();
logger.info("Copying workspace content");
- copyWorkspace(sourceState, builder, workspaceName);
- builder.getNodeState(); // on TarMK this does call triggers the
actual copy
+ copyWorkspace(sourceRoot, targetBuilder, workspaceName);
+ targetBuilder.getNodeState(); // on TarMK this does call triggers
the actual copy
logger.info("Upgrading workspace content completed in {}s ({})",
watch.elapsed(TimeUnit.SECONDS), watch);
if (!versionCopyConfiguration.skipOrphanedVersionsCopy()) {
logger.info("Copying version storage");
watch.reset().start();
- copyVersionStorage(sourceState, builder,
versionCopyConfiguration);
- builder.getNodeState(); // on TarMK this does call triggers
the actual copy
+ copyVersionStorage(sourceRoot, targetBuilder,
versionCopyConfiguration);
+ targetBuilder.getNodeState(); // on TarMK this does call
triggers the actual copy
logger.info("Version storage copied in {}s ({})",
watch.elapsed(TimeUnit.SECONDS), watch);
} else {
logger.info("Skipping the version storage as the
copyOrphanedVersions is set to false");
@@ -449,7 +448,7 @@ public class RepositoryUpgrade {
new RestrictionEditorProvider(),
new GroupEditorProvider(groupsPath),
// copy referenced version histories
- new VersionableEditor.Provider(sourceState, workspaceName,
versionCopyConfiguration)
+ new VersionableEditor.Provider(sourceRoot, workspaceName,
versionCopyConfiguration)
)));
// security-related hooks
@@ -467,7 +466,7 @@ public class RepositoryUpgrade {
createIndexEditorProvider()
)));
- target.merge(builder, new LoggingCompositeHook(hooks, source,
overrideEarlyShutdown()), CommitInfo.EMPTY);
+ target.merge(targetBuilder, new LoggingCompositeHook(hooks,
source, overrideEarlyShutdown()), CommitInfo.EMPTY);
logger.info("Processing commit hooks completed in {}s ({})",
watch.elapsed(TimeUnit.SECONDS), watch);
logger.debug("Repository upgrade completed.");
} catch (Exception e) {
@@ -586,15 +585,15 @@ public class RepositoryUpgrade {
* Copies the registered namespaces to the target repository, and returns
* the internal namespace index mapping used in bundle serialization.
*
- * @param root root builder
+ * @param targetRoot root builder of the target store
* @param uriToPrefix namespace URI to prefix mapping
* @throws RepositoryException
*/
private void copyNamespaces(
- NodeBuilder root,
+ NodeBuilder targetRoot,
Map<String, String> uriToPrefix)
throws RepositoryException {
- NodeBuilder system = root.child(JCR_SYSTEM);
+ NodeBuilder system = targetRoot.child(JCR_SYSTEM);
NodeBuilder namespaces =
system.child(NamespaceConstants.REP_NAMESPACES);
Properties registry = loadProperties("/namespaces/ns_reg.properties");
@@ -839,9 +838,9 @@ public class RepositoryUpgrade {
return tmpl;
}
- private String copyWorkspace(NodeState sourceState, NodeBuilder builder,
String workspaceName)
+ private String copyWorkspace(NodeState sourceRoot, NodeBuilder targetRoot,
String workspaceName)
throws RepositoryException {
- final Set<String> includes =
calculateEffectiveIncludePaths(includePaths, sourceState);
+ final Set<String> includes =
calculateEffectiveIncludePaths(includePaths, sourceRoot);
final Set<String> excludes = union(copyOf(this.excludePaths),
of("/jcr:system/jcr:versionStorage"));
final Set<String> merges = union(copyOf(this.mergePaths),
of("/jcr:system"));
@@ -851,19 +850,19 @@ public class RepositoryUpgrade {
.include(includes)
.exclude(excludes)
.merge(merges)
- .copy(sourceState, builder);
+ .copy(sourceRoot, targetRoot);
return workspaceName;
}
- static Set<String> calculateEffectiveIncludePaths(Set<String>
includePaths, NodeState state) {
+ static Set<String> calculateEffectiveIncludePaths(Set<String>
includePaths, NodeState sourceRoot) {
if (!includePaths.contains("/")) {
return copyOf(includePaths);
}
// include child nodes from source individually to avoid deleting
other initialized content
final Set<String> includes = newHashSet();
- for (String childNodeName : state.getChildNodeNames()) {
+ for (String childNodeName : sourceRoot.getChildNodeNames()) {
includes.add("/" + childNodeName);
}
return includes;
Modified:
jackrabbit/oak/trunk/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/nodestate/NodeStateCopier.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/nodestate/NodeStateCopier.java?rev=1706680&r1=1706679&r2=1706680&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/nodestate/NodeStateCopier.java
(original)
+++
jackrabbit/oak/trunk/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/nodestate/NodeStateCopier.java
Sun Oct 4 13:50:12 2015
@@ -140,15 +140,14 @@ public class NodeStateCopier {
return hasChanges;
}
-
- private boolean copyNodeState(@Nonnull final NodeState source, @Nonnull
final NodeBuilder target) {
- final NodeState wrappedSource = FilteringNodeState.wrap("/", source,
this.includePaths, this.excludePaths);
+ private boolean copyNodeState(@Nonnull final NodeState sourceRoot,
@Nonnull final NodeBuilder targetRoot) {
+ final NodeState wrappedSource = FilteringNodeState.wrap("/",
sourceRoot, this.includePaths, this.excludePaths);
boolean hasChanges = false;
for (String includePath : this.includePaths) {
- hasChanges = copyMissingAncestors(source, target, includePath) ||
hasChanges;
+ hasChanges = copyMissingAncestors(sourceRoot, targetRoot,
includePath) || hasChanges;
final NodeState sourceState =
NodeStateUtils.getNode(wrappedSource, includePath);
if (sourceState.exists()) {
- final NodeBuilder targetBuilder = getChildNodeBuilder(target,
includePath);
+ final NodeBuilder targetBuilder =
getChildNodeBuilder(targetRoot, includePath);
hasChanges = copyNodeState(sourceState, targetBuilder,
includePath, this.mergePaths) || hasChanges;
}
}
@@ -226,16 +225,17 @@ public class NodeStateCopier {
}
/**
- * Ensure that all ancestors of {@code path} are present in {@code
target}. Copies any
- * missing ancestors from {@code source}.
+ * Ensure that all ancestors of {@code path} are present in {@code
targetRoot}. Copies any
+ * missing ancestors from {@code sourceRoot}.
*
- * @param source NodeState to copy from
- * @param target NodeBuilder to copy to
+ * @param sourceRoot NodeState to copy from
+ * @param targetRoot NodeBuilder to copy to
* @param path The path along which ancestors should be copied.
*/
- private static boolean copyMissingAncestors(final NodeState source, final
NodeBuilder target, final String path) {
- NodeState current = source;
- NodeBuilder currentBuilder = target;
+ private static boolean copyMissingAncestors(
+ final NodeState sourceRoot, final NodeBuilder targetRoot, final
String path) {
+ NodeState current = sourceRoot;
+ NodeBuilder currentBuilder = targetRoot;
boolean hasChanges = false;
for (String name : PathUtils.elements(path)) {
if (current.hasChildNode(name)) {
@@ -387,21 +387,21 @@ public class NodeStateCopier {
}
/**
- * Creates a NodeStateCopier to copy the {@code source} NodeState to
the
- * {@code target} NodeBuilder, using any include, exclude and merge
paths
+ * Creates a NodeStateCopier to copy the {@code sourceRoot} NodeState
to the
+ * {@code targetRoot} NodeBuilder, using any include, exclude and
merge paths
* set on this NodeStateCopier.Builder.
* <br>
* It is the responsibility of the caller to persist any changes using
e.g.
* {@link NodeStore#merge(NodeBuilder, CommitHook, CommitInfo)}.
*
- * @param source NodeState to copy from
- * @param target NodeBuilder to copy to
- * @return true if there were any changes, false if source and target
represent
+ * @param sourceRoot NodeState to copy from
+ * @param targetRoot NodeBuilder to copy to
+ * @return true if there were any changes, false if sourceRoot and
targetRoot represent
* the same content
*/
- public boolean copy(@Nonnull final NodeState source, @Nonnull final
NodeBuilder target) {
+ public boolean copy(@Nonnull final NodeState sourceRoot, @Nonnull
final NodeBuilder targetRoot) {
final NodeStateCopier copier = new NodeStateCopier(includePaths,
excludePaths, mergePaths);
- return copier.copyNodeState(checkNotNull(source),
checkNotNull(target));
+ return copier.copyNodeState(checkNotNull(sourceRoot),
checkNotNull(targetRoot));
}
/**
@@ -420,9 +420,9 @@ public class NodeStateCopier {
*/
public boolean copy(@Nonnull final NodeStore source, @Nonnull final
NodeStore target)
throws CommitFailedException {
- final NodeBuilder targetBuilder =
checkNotNull(target).getRoot().builder();
- if (copy(checkNotNull(source).getRoot(), targetBuilder)) {
- target.merge(targetBuilder, EmptyHook.INSTANCE,
CommitInfo.EMPTY);
+ final NodeBuilder targetRoot =
checkNotNull(target).getRoot().builder();
+ if (copy(checkNotNull(source).getRoot(), targetRoot)) {
+ target.merge(targetRoot, EmptyHook.INSTANCE, CommitInfo.EMPTY);
return true;
}
return false;
Modified:
jackrabbit/oak/trunk/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/version/VersionCopier.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/version/VersionCopier.java?rev=1706680&r1=1706679&r2=1706680&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/version/VersionCopier.java
(original)
+++
jackrabbit/oak/trunk/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/version/VersionCopier.java
Sun Oct 4 13:50:12 2015
@@ -48,18 +48,18 @@ public class VersionCopier {
private final NodeState sourceRoot;
- private final NodeBuilder rootBuilder;
+ private final NodeBuilder targetRoot;
- public VersionCopier(NodeState sourceRoot, NodeBuilder rootBuilder) {
- this.isVersion = new TypePredicate(rootBuilder.getNodeState(),
NT_VERSION);
+ public VersionCopier(NodeState sourceRoot, NodeBuilder targetRoot) {
+ this.isVersion = new TypePredicate(targetRoot.getNodeState(),
NT_VERSION);
this.sourceRoot = sourceRoot;
- this.rootBuilder = rootBuilder;
+ this.targetRoot = targetRoot;
}
- public static void copyVersionStorage(NodeState sourceState, NodeBuilder
builder, VersionCopyConfiguration config) {
- final NodeState versionStorage =
sourceState.getChildNode(JCR_SYSTEM).getChildNode(JCR_VERSIONSTORAGE);
+ public static void copyVersionStorage(NodeState sourceRoot, NodeBuilder
targetRoot, VersionCopyConfiguration config) {
+ final NodeState versionStorage =
sourceRoot.getChildNode(JCR_SYSTEM).getChildNode(JCR_VERSIONSTORAGE);
final Iterator<NodeState> versionStorageIterator = new
DescendantsIterator(versionStorage, 3);
- final VersionCopier versionCopier = new VersionCopier(sourceState,
builder);
+ final VersionCopier versionCopier = new VersionCopier(sourceRoot,
targetRoot);
while (versionStorageIterator.hasNext()) {
final NodeState versionHistoryBucket =
versionStorageIterator.next();
@@ -88,7 +88,7 @@ public class VersionCopier {
NodeStateCopier.builder()
.include(versionHistoryPath)
.merge(VERSION_STORE_PATH)
- .copy(sourceRoot, rootBuilder);
+ .copy(sourceRoot, targetRoot);
return true;
}
return false;