Index: oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/RepositoryUpgrade.java =================================================================== --- oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/RepositoryUpgrade.java (revision 1667877) +++ oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/RepositoryUpgrade.java (working copy) @@ -177,6 +177,11 @@ private boolean copyBinariesByReference = false; /** + * Flag to control early shutdown of the source repository. + */ + private boolean earlyShutdown = false; + + /** * Copies the contents of the repository in the given source directory * to the given target node store. * @@ -308,7 +313,8 @@ createIndexEditorProvider() ))); - target.merge(builder, new LoggingCompositeHook(hooks), CommitInfo.EMPTY); + target.merge(builder, new LoggingCompositeHook(hooks, source, + earlyShutdown), CommitInfo.EMPTY); } catch (Exception e) { throw new RepositoryException("Failed to copy content", e); } @@ -867,24 +873,47 @@ } private static class LoggingCompositeHook implements CommitHook { + private final Collection hooks; - public LoggingCompositeHook(Collection hooks) { + private boolean started = false; + private final boolean earlyShutdown; + private final RepositoryContext source; + + public LoggingCompositeHook(Collection hooks, + RepositoryContext source, boolean earlyShutdown) { this.hooks = hooks; + this.earlyShutdown = earlyShutdown; + this.source = source; } @Nonnull @Override - public NodeState processCommit(NodeState before, NodeState after, CommitInfo info) throws CommitFailedException { + public NodeState processCommit(NodeState before, NodeState after, + CommitInfo info) throws CommitFailedException { NodeState newState = after; Stopwatch watch = Stopwatch.createStarted(); + if (earlyShutdown && !started) { + logger.info("Shutting down source repository."); + source.getRepository().shutdown(); + started = true; + } for (CommitHook hook : hooks) { logger.info("Processing commit via {}", hook); newState = hook.processCommit(before, newState, info); - logger.info("Commit hook {} processed commit in {}", hook, watch); + logger.info("Commit hook {} processed commit in {}", hook, + watch); watch.reset().start(); } return newState; } } + + public void setEarlyShutdown(boolean earlyShutdown) { + this.earlyShutdown = earlyShutdown; + } + + public boolean isEarlyShutdown() { + return earlyShutdown; + } }