Index: src/main/java/org/apache/jackrabbit/oak/plugins/segment/Compactor.java =================================================================== --- src/main/java/org/apache/jackrabbit/oak/plugins/segment/Compactor.java (revision 1701615) +++ src/main/java/org/apache/jackrabbit/oak/plugins/segment/Compactor.java (working copy) @@ -65,6 +65,8 @@ private final PartialCompactionMap map; + private final ProgressTracker progress = new ProgressTracker(); + /** * Map from {@link #getBlobKey(Blob) blob keys} to matching compacted * blob record identifiers. Used to de-duplicate copies of the same @@ -111,8 +113,10 @@ * @return the compacted state */ public SegmentNodeState compact(NodeState before, NodeState after) { + progress.start(); SegmentNodeState compacted = process(before, after, before).getNodeState(); writer.flush(); + progress.stop(); return compacted; } @@ -125,8 +129,10 @@ * @return the compacted state */ public SegmentNodeState compact(NodeState before, NodeState after, NodeState onto) { + progress.start(); SegmentNodeState compacted = process(before, after, onto).getNodeState(); writer.flush(); + progress.stop(); return compacted; } @@ -167,6 +173,7 @@ if (path != null) { log.trace("propertyAdded {}/{}", path, after.getName()); } + progress.onProperty(); return super.propertyAdded(compact(after)); } @@ -175,6 +182,7 @@ if (path != null) { log.trace("propertyChanged {}/{}", path, after.getName()); } + progress.onProperty(); return super.propertyChanged(before, compact(after)); } @@ -183,6 +191,7 @@ if (path != null) { log.trace("childNodeAdded {}/{}", path, name); } + progress.onNode(); RecordId id = null; if (after instanceof SegmentNodeState) { id = ((SegmentNodeState) after).getRecordId(); @@ -214,6 +223,7 @@ if (path != null) { log.trace("childNodeChanged {}/{}", path, name); } + progress.onNode(); RecordId id = null; if (after instanceof SegmentNodeState) { @@ -269,7 +279,7 @@ private Blob compact(Blob blob) { if (blob instanceof SegmentBlob) { SegmentBlob sb = (SegmentBlob) blob; - + progress.onBinary(); try { // else check if we've already cloned this specific record RecordId id = sb.getRecordId(); @@ -328,4 +338,54 @@ } } + private class ProgressTracker { + + private final int logAt = Integer.getInteger("compaction-progress-log", + 15000); + + private long start = 0; + + private long nodes = 0; + private long properties = 0; + private long binaries = 0; + + void start() { + nodes = 0; + properties = 0; + binaries = 0; + start = System.currentTimeMillis(); + } + + void onNode() { + if (++nodes % logAt == 0) { + logProgress(start, false); + start = System.currentTimeMillis(); + } + } + + void onProperty() { + properties++; + } + + void onBinary() { + binaries++; + } + + void stop() { + logProgress(start, true); + } + + private void logProgress(long start, boolean done) { + log.debug( + "Compacted {} nodes, {} properties, {} binaries in {} ms.", + nodes, properties, binaries, System.currentTimeMillis() + - start); + if (done) { + log.info( + "Finished compaction: {} nodes, {} properties, {} binaries.", + nodes, properties, binaries); + } + } + } + }