Index: oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/CheckpointCompactor.java =================================================================== --- oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/CheckpointCompactor.java (revision 1818032) +++ oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/CheckpointCompactor.java (working copy) @@ -33,7 +33,6 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; -import java.util.concurrent.atomic.AtomicLong; import javax.annotation.CheckForNull; import javax.annotation.Nonnull; @@ -63,9 +62,6 @@ private final GCMonitor gcListener; @Nonnull - private final AtomicLong gcCount; - - @Nonnull private final Map cpCache = newHashMap(); @Nonnull @@ -90,14 +86,12 @@ */ public CheckpointCompactor( @Nonnull GCMonitor gcListener, - @Nonnull AtomicLong gcCount, @Nonnull SegmentReader reader, @Nonnull SegmentWriter writer, @Nullable BlobStore blobStore, @Nonnull Supplier cancel, @Nonnull GCNodeWriteMonitor compactionMonitor) { this.gcListener = gcListener; - this.gcCount = gcCount; this.compactor = new Compactor(reader, writer, blobStore, cancel, compactionMonitor); this.nodeWriter = (node, stableId) -> { RecordId nodeId = writer.writeNode(node, stableId); @@ -204,8 +198,8 @@ for (ChildNodeEntry checkpoint : checkpoints) { String name = checkpoint.getName(); NodeState node = checkpoint.getNodeState(); - gcListener.info("TarMK GC #{}: Found checkpoint {} created at {}.", - gcCount, name, new Date(node.getLong("created"))); + gcListener.info("found checkpoint {} created at {}.", + name, new Date(node.getLong("created"))); roots.put("checkpoints/" + name + "/root", node.getChildNode("root")); } roots.put("root", superRoot.getChildNode("root")); @@ -245,7 +239,7 @@ @Nonnull NodeState onto, @Nonnull String path) throws IOException { - gcListener.info("TarMK GC #{}: compacting {}.", gcCount, path); + gcListener.info("compacting {}.", path); NodeState compacted = cpCache.get(after); if (compacted == null) { compacted = compactor.compact(before, after, onto); @@ -256,7 +250,7 @@ return new Result(compacted, after, compacted); } } else { - gcListener.info("TarMK GC #{}: Found {} in cache.", gcCount, path); + gcListener.info("found {} in cache.", path); return new Result(compacted, before, onto); } } Index: oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/FileStore.java =================================================================== --- oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/FileStore.java (revision 1818032) +++ oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/FileStore.java (working copy) @@ -36,6 +36,7 @@ import static org.apache.jackrabbit.oak.segment.compaction.SegmentGCStatus.COMPACTION_RETRY; import static org.apache.jackrabbit.oak.segment.compaction.SegmentGCStatus.ESTIMATION; import static org.apache.jackrabbit.oak.segment.compaction.SegmentGCStatus.IDLE; +import static org.apache.jackrabbit.oak.segment.file.PrintableBytes.newPrintableBytes; import static org.apache.jackrabbit.oak.segment.file.TarRevisions.EXPEDITE_OPTION; import static org.apache.jackrabbit.oak.segment.file.TarRevisions.timeout; @@ -62,11 +63,10 @@ import com.google.common.base.Function; import com.google.common.base.Joiner; import com.google.common.base.Predicate; -import com.google.common.base.Stopwatch; import com.google.common.base.Supplier; import com.google.common.io.Closer; -import org.apache.jackrabbit.oak.segment.CheckpointCompactor; import com.google.common.util.concurrent.UncheckedExecutionException; +import org.apache.jackrabbit.oak.segment.CheckpointCompactor; import org.apache.jackrabbit.oak.segment.RecordId; import org.apache.jackrabbit.oak.segment.Segment; import org.apache.jackrabbit.oak.segment.SegmentId; @@ -212,11 +212,10 @@ } }); - log.info("TarMK opened at {}, mmap={}, size={} ({} bytes)", + log.info("TarMK opened at {}, mmap={}, size={}", directory, memoryMapping, - humanReadableByteCount(size), - size + newPrintableBytes(size) ); log.debug("TAR files: {}", tarFiles); } @@ -451,7 +450,7 @@ Closer closer = Closer.create(); closer.register(lockFile); closer.register(lock::release); - closer.register(tarFiles) ; + closer.register(tarFiles); closer.register(revisions); closeAndLogOnFail(closer); @@ -582,7 +581,7 @@ @Nonnull GCJournal gcJournal, @Nonnull WriterCacheManager cacheManager) { this.gcOptions = gcOptions; - this.gcListener = gcListener; + this.gcListener = gcListener.withLogPrefix("TarMK GC #%s: ", GC_COUNT); this.gcJournal = gcJournal; this.cacheManager = cacheManager; } @@ -614,53 +613,49 @@ private void run(boolean full, Supplier compact) throws IOException { try { - gcListener.info("TarMK GC #{}: started", GC_COUNT.incrementAndGet()); + GC_COUNT.incrementAndGet(); + + gcListener.info("started"); long dt = System.currentTimeMillis() - lastSuccessfullGC; if (dt < GC_BACKOFF) { - gcListener.skipped("TarMK GC #{}: skipping garbage collection as it already ran " + - "less than {} hours ago ({} s).", GC_COUNT, GC_BACKOFF/3600000, dt/1000); + gcListener.skipped("skipping garbage collection as it already ran " + + "less than {} hours ago ({} s).", GC_BACKOFF / 3600000, dt / 1000); return; } boolean sufficientEstimatedGain = true; if (gcOptions.isEstimationDisabled()) { - gcListener.info("TarMK GC #{}: estimation skipped because it was explicitly disabled", GC_COUNT); + gcListener.info("estimation skipped because it was explicitly disabled"); } else if (gcOptions.isPaused()) { - gcListener.info("TarMK GC #{}: estimation skipped because compaction is paused", GC_COUNT); + gcListener.info("estimation skipped because compaction is paused"); } else { - gcListener.info("TarMK GC #{}: estimation started", GC_COUNT); + gcListener.info("estimation started"); gcListener.updateStatus(ESTIMATION.message()); - - Stopwatch watch = Stopwatch.createStarted(); + + PrintableStopwatch watch = PrintableStopwatch.createStarted(); GCEstimationResult estimation = estimateCompactionGain(full); sufficientEstimatedGain = estimation.isGcNeeded(); String gcLog = estimation.getGcLog(); if (sufficientEstimatedGain) { - gcListener.info( - "TarMK GC #{}: estimation completed in {} ({} ms). {}", - GC_COUNT, watch, watch.elapsed(MILLISECONDS), gcLog); + gcListener.info("estimation completed in {}. {}", watch, gcLog); } else { - gcListener.skipped( - "TarMK GC #{}: estimation completed in {} ({} ms). {}", - GC_COUNT, watch, watch.elapsed(MILLISECONDS), gcLog); + gcListener.skipped("estimation completed in {}. {}", watch, gcLog); } } - + if (sufficientEstimatedGain) { - try (GCMemoryBarrier gcMemoryBarrier = new GCMemoryBarrier( - sufficientMemory, gcListener, GC_COUNT.get(), gcOptions)) - { + try (GCMemoryBarrier ignored = new GCMemoryBarrier(sufficientMemory, gcListener, gcOptions)) { if (gcOptions.isPaused()) { - gcListener.skipped("TarMK GC #{}: compaction paused", GC_COUNT); + gcListener.skipped("compaction paused"); } else if (!sufficientMemory.get()) { - gcListener.skipped("TarMK GC #{}: compaction skipped. Not enough memory", GC_COUNT); + gcListener.skipped("compaction skipped. Not enough memory"); } else { CompactionResult compactionResult = compact.get(); if (compactionResult.isSuccess()) { lastSuccessfullGC = System.currentTimeMillis(); } else { - gcListener.info("TarMK GC #{}: cleaning up after failed compaction", GC_COUNT); + gcListener.info("cleaning up after failed compaction"); } fileReaper.add(cleanup(compactionResult)); } @@ -705,23 +700,23 @@ node.getPropertyCount(); // Resilience: fail early with a SNFE if the segment is not there return node; } catch (SegmentNotFoundException snfe) { - gcListener.error("TarMK GC #" + GC_COUNT + ": Base state " + rootId + " is not accessible", snfe); + gcListener.error("base state " + rootId + " is not accessible", snfe); return null; } } synchronized CompactionResult compactFull() { - gcListener.info("TarMK GC #{}: running full compaction", GC_COUNT); + gcListener.info("running full compaction"); return compact(EMPTY_NODE, getGcGeneration().nextFull()); } synchronized CompactionResult compactTail() { - gcListener.info("TarMK GC #{}: running tail compaction", GC_COUNT); + gcListener.info("running tail compaction"); SegmentNodeState base = getBase(); if (base != null) { return compact(base, getGcGeneration().nextTail()); } - gcListener.info("TarMK GC #{}: no base state available, running full compaction instead", GC_COUNT); + gcListener.info("no base state available, running full compaction instead"); return compact(EMPTY_NODE, getGcGeneration().nextFull()); } @@ -729,8 +724,8 @@ @Nonnull NodeState base, @Nonnull GCGeneration newGeneration) { try { - Stopwatch watch = Stopwatch.createStarted(); - gcListener.info("TarMK GC #{}: compaction started, gc options={}", GC_COUNT, gcOptions); + PrintableStopwatch watch = PrintableStopwatch.createStarted(); + gcListener.info("compaction started, gc options={}", gcOptions); gcListener.updateStatus(COMPACTION.message()); GCJournalEntry gcEntry = gcJournal.read(); @@ -745,20 +740,20 @@ CancelCompactionSupplier cancel = new CancelCompactionSupplier(FileStore.this); compactionMonitor = new GCNodeWriteMonitor(gcOptions.getGcLogInterval(), gcListener); - compactionMonitor.init(GC_COUNT.get(), gcEntry.getRepoSize(), gcEntry.getNodes(), initialSize); + compactionMonitor.init(gcEntry.getRepoSize(), gcEntry.getNodes(), initialSize); - CheckpointCompactor compactor = new CheckpointCompactor(gcListener, GC_COUNT, - segmentReader, writer, getBlobStore(), cancel, compactionMonitor); + CheckpointCompactor compactor = new CheckpointCompactor(gcListener, + segmentReader, writer, getBlobStore(), cancel, compactionMonitor); SegmentNodeState head = getHead(); SegmentNodeState compacted = compactor.compact(base, head, base); if (compacted == null) { - gcListener.warn("TarMK GC #{}: compaction cancelled: {}.", GC_COUNT, cancel); + gcListener.warn("compaction cancelled: {}.", cancel); return compactionAborted(newGeneration); } - gcListener.info("TarMK GC #{}: compaction cycle 0 completed in {} ({} ms). Compacted {} to {}", - GC_COUNT, watch, watch.elapsed(MILLISECONDS), head.getRecordId(), compacted.getRecordId()); + gcListener.info("compaction cycle 0 completed in {}. Compacted {} to {}", + watch, head.getRecordId(), compacted.getRecordId()); int cycles = 0; boolean success = false; @@ -769,53 +764,51 @@ // Rebase (and compact) those changes on top of the // compacted state before retrying to set the head. cycles++; - gcListener.info("TarMK GC #{}: compaction detected concurrent commits while compacting. " + - "Compacting these commits. Cycle {} of {}", - GC_COUNT, cycles, gcOptions.getRetryCount()); + gcListener.info("compaction detected concurrent commits while compacting. " + + "Compacting these commits. Cycle {} of {}", + cycles, gcOptions.getRetryCount()); gcListener.updateStatus(COMPACTION_RETRY.message() + cycles); - Stopwatch cycleWatch = Stopwatch.createStarted(); + PrintableStopwatch cycleWatch = PrintableStopwatch.createStarted(); head = getHead(); compacted = compactor.compact(previousHead, head, compacted); if (compacted == null) { - gcListener.warn("TarMK GC #{}: compaction cancelled: {}.", GC_COUNT, cancel); + gcListener.warn("compaction cancelled: {}.", cancel); return compactionAborted(newGeneration); } - gcListener.info("TarMK GC #{}: compaction cycle {} completed in {} ({} ms). Compacted {} against {} to {}", - GC_COUNT, cycles, cycleWatch, cycleWatch.elapsed(MILLISECONDS), - head.getRecordId(), previousHead.getRecordId(), compacted.getRecordId()); + gcListener.info("compaction cycle {} completed in {}. Compacted {} against {} to {}", + cycles, cycleWatch, head.getRecordId(), previousHead.getRecordId(), compacted.getRecordId()); previousHead = head; } if (!success) { - gcListener.info("TarMK GC #{}: compaction gave up compacting concurrent commits after {} cycles.", - GC_COUNT, cycles); + gcListener.info("compaction gave up compacting concurrent commits after {} cycles.", + cycles); int forceTimeout = gcOptions.getForceTimeout(); if (forceTimeout > 0) { - gcListener.info("TarMK GC #{}: trying to force compact remaining commits for {} seconds. " + + gcListener.info("trying to force compact remaining commits for {} seconds. " + "Concurrent commits to the store will be blocked.", - GC_COUNT, forceTimeout); + forceTimeout); gcListener.updateStatus(COMPACTION_FORCE_COMPACT.message()); - Stopwatch forceWatch = Stopwatch.createStarted(); - + PrintableStopwatch forceWatch = PrintableStopwatch.createStarted(); + cycles++; cancel.timeOutAfter(forceTimeout, SECONDS); compacted = forceCompact(previousHead, compacted, compactor); success = compacted != null; if (success) { - gcListener.info("TarMK GC #{}: compaction succeeded to force compact remaining commits " + - "after {} ({} ms).", - GC_COUNT, forceWatch, forceWatch.elapsed(MILLISECONDS)); + gcListener.info("compaction succeeded to force compact remaining commits " + + "after {}.", forceWatch); } else { if (cancel.get()) { - gcListener.warn("TarMK GC #{}: compaction failed to force compact remaining commits " + - "after {} ({} ms). Compaction was cancelled: {}.", - GC_COUNT, forceWatch, forceWatch.elapsed(MILLISECONDS), cancel); + gcListener.warn("compaction failed to force compact remaining commits " + + "after {}. Compaction was cancelled: {}.", + forceWatch, cancel); } else { - gcListener.warn("TarMK GC #{}: compaction failed to force compact remaining commits. " + - "after {} ({} ms). Could not acquire exclusive access to the node store.", - GC_COUNT, forceWatch, forceWatch.elapsed(MILLISECONDS)); + gcListener.warn("compaction failed to force compact remaining commits. " + + "after {}. Could not acquire exclusive access to the node store.", + forceWatch); } } } @@ -824,20 +817,18 @@ if (success) { writer.flush(); flush(); - gcListener.info("TarMK GC #{}: compaction succeeded in {} ({} ms), after {} cycles", - GC_COUNT, watch, watch.elapsed(MILLISECONDS), cycles); + gcListener.info("compaction succeeded in {}, after {} cycles", watch, cycles); return compactionSucceeded(newGeneration, compacted.getRecordId()); } else { - gcListener.info("TarMK GC #{}: compaction failed after {} ({} ms), and {} cycles", - GC_COUNT, watch, watch.elapsed(MILLISECONDS), cycles); + gcListener.info("compaction failed after {}, and {} cycles", watch, cycles); return compactionAborted(newGeneration); } } catch (InterruptedException e) { - gcListener.error("TarMK GC #" + GC_COUNT + ": compaction interrupted", e); + gcListener.error("compaction interrupted", e); currentThread().interrupt(); return compactionAborted(newGeneration); } catch (IOException e) { - gcListener.error("TarMK GC #" + GC_COUNT + ": compaction encountered an error", e); + gcListener.error("compaction encountered an error", e); return compactionAborted(newGeneration); } } @@ -854,16 +845,16 @@ try { long t0 = currentTimeMillis(); SegmentNodeState after = compactor.compact( - base, segmentReader.readNode(headId), onto); + base, segmentReader.readNode(headId), onto); if (after == null) { - gcListener.info("TarMK GC #{}: compaction cancelled after {} seconds", - GC_COUNT, (currentTimeMillis() - t0) / 1000); + gcListener.info("compaction cancelled after {} seconds", + (currentTimeMillis() - t0) / 1000); return null; } else { return after.getRecordId(); } } catch (IOException e) { - gcListener.error("TarMK GC #{" + GC_COUNT + "}: Error during forced compaction.", e); + gcListener.error("error during forced compaction.", e); return null; } } @@ -915,10 +906,10 @@ */ @Nonnull private List cleanup(@Nonnull CompactionResult compactionResult) - throws IOException { - Stopwatch watch = Stopwatch.createStarted(); + throws IOException { + PrintableStopwatch watch = PrintableStopwatch.createStarted(); - gcListener.info("TarMK GC #{}: cleanup started.", GC_COUNT); + gcListener.info("cleanup started."); gcListener.updateStatus(CLEANUP.message()); segmentCache.clear(); @@ -928,10 +919,10 @@ CleanupResult cleanupResult = tarFiles.cleanup(newCleanupContext(compactionResult.reclaimer())); if (cleanupResult.isInterrupted()) { - gcListener.info("TarMK GC #{}: cleanup interrupted", GC_COUNT); + gcListener.info("cleanup interrupted"); } tracker.clearSegmentIdTables(cleanupResult.getReclaimedSegmentIds(), compactionResult.gcInfo()); - gcListener.info("TarMK GC #{}: cleanup marking files for deletion: {}", GC_COUNT, toFileNames(cleanupResult.getRemovableFiles())); + gcListener.info("cleanup marking files for deletion: {}", toFileNames(cleanupResult.getRemovableFiles())); long finalSize = size(); long reclaimedSize = cleanupResult.getReclaimedSize(); @@ -940,11 +931,11 @@ compactionMonitor.getCompactedNodes(), compactionResult.getCompactedRootId().toString10()); gcListener.cleaned(reclaimedSize, finalSize); - gcListener.info("TarMK GC #{}: cleanup completed in {} ({} ms). Post cleanup size is {} ({} bytes)" + - " and space reclaimed {} ({} bytes).", - GC_COUNT, watch, watch.elapsed(MILLISECONDS), - humanReadableByteCount(finalSize), finalSize, - humanReadableByteCount(reclaimedSize), reclaimedSize); + gcListener.info( + "cleanup completed in {}. Post cleanup size is {} and space reclaimed {}.", + watch, + newPrintableBytes(finalSize), + newPrintableBytes(reclaimedSize)); return cleanupResult.getRemovableFiles(); } Index: oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/GCListener.java =================================================================== --- oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/GCListener.java (revision 1818032) +++ oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/GCListener.java (working copy) @@ -42,4 +42,64 @@ * @param failedGeneration the generation number that could not be created */ void compactionFailed(@Nonnull GCGeneration failedGeneration); + + /** + * Creates a new {@link GCListener} equivalent to this one that adds a + * prefix to every message passed to its logging methods. + * + * @param prefixMessage The content of the prefix. + * @param prefixArguments The arguments of the prefix message. + * @return A new instance of {@link GCListener}. + */ + default GCListener withLogPrefix(String prefixMessage, Object... prefixArguments) { + return new GCListener() { + + @Override + public void compactionSucceeded(@Nonnull GCGeneration newGeneration) { + GCListener.this.compactionSucceeded(newGeneration); + } + + @Override + public void compactionFailed(@Nonnull GCGeneration failedGeneration) { + GCListener.this.compactionFailed(failedGeneration); + } + + @Override + public void info(String message, Object... arguments) { + GCListener.this.info(String.format(prefixMessage, prefixArguments) + message, arguments); + } + + @Override + public void warn(String message, Object... arguments) { + GCListener.this.warn(String.format(prefixMessage, prefixArguments) + message, arguments); + } + + @Override + public void error(String message, Exception exception) { + GCListener.this.error(String.format(prefixMessage, prefixArguments) + message, exception); + } + + @Override + public void skipped(String reason, Object... arguments) { + GCListener.this.skipped(String.format(prefixMessage, prefixArguments) + reason, arguments); + } + + @Override + public void compacted() { + GCListener.this.compacted(); + } + + @Override + public void cleaned(long reclaimedSize, long currentSize) { + GCListener.this.cleaned(reclaimedSize, currentSize); + } + + @Override + public void updateStatus(String status) { + GCListener.this.updateStatus(status); + } + + }; + } + } Index: oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/GCMemoryBarrier.java =================================================================== --- oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/GCMemoryBarrier.java (revision 1818032) +++ oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/GCMemoryBarrier.java (working copy) @@ -21,7 +21,7 @@ import static java.lang.management.ManagementFactory.getMemoryMXBean; import static java.lang.management.ManagementFactory.getMemoryPoolMXBeans; import static java.lang.management.MemoryType.HEAP; -import static org.apache.jackrabbit.oak.commons.IOUtils.humanReadableByteCount; +import static org.apache.jackrabbit.oak.segment.file.PrintableBytes.newPrintableBytes; import java.io.Closeable; import java.io.IOException; @@ -58,27 +58,22 @@ @Nonnull private final SegmentGCOptions gcOptions; - private final long gcCount; - private final NotificationEmitter emitter; private final MemoryListener listener; public GCMemoryBarrier(@Nonnull AtomicBoolean sufficientMemory, - @Nonnull GCListener gcListener, long gcCount, - @Nonnull SegmentGCOptions gcOptions) { + @Nonnull GCListener gcListener, + @Nonnull SegmentGCOptions gcOptions) { this.sufficientMemory = sufficientMemory; this.gcListener = gcListener; this.gcOptions = gcOptions; - this.gcCount = gcCount; MemoryPoolMXBean pool = null; int percentage = gcOptions.getMemoryThreshold(); if (percentage > 0) { pool = getMemoryPool(); if (pool == null) { - gcListener - .warn("TarMK GC #{}: Unable to setup monitoring of available memory.", - gcCount); + gcListener.warn("unable to setup monitoring of available memory."); } } if (pool != null) { @@ -89,9 +84,9 @@ long maxMemory = usage.getMax(); long required = maxMemory * percentage / 100; gcListener - .info("TarMK GC #{}: setting up a listener to cancel compaction if available memory on pool '{}' drops below {}%, {} ({} bytes).", - gcCount, pool.getName(), percentage, - humanReadableByteCount(required), required); + .info("setting up a listener to cancel compaction if available memory on pool '{}' drops below {}%.", + pool.getName(), percentage, + newPrintableBytes(required)); long warningThreshold = maxMemory - required; long current = pool.getCollectionUsageThreshold(); @@ -132,15 +127,15 @@ long required = maxMemory * percentage / 100; if (avail <= required) { gcListener - .warn("TarMK GC #{}: canceling compaction because available memory level {} ({} bytes) is too low, expecting at least {} ({} bytes)", - gcCount, humanReadableByteCount(avail), avail, - humanReadableByteCount(required), required); + .warn("canceling compaction because available memory level {} is too low, expecting at least {}", + newPrintableBytes(avail), + newPrintableBytes(required)); sufficientMemory.set(false); } else { gcListener - .info("TarMK GC #{}: available memory level {} ({} bytes) is good, expecting at least {} ({} bytes)", - gcCount, humanReadableByteCount(avail), avail, - humanReadableByteCount(required), required); + .info("available memory level {} is good, expecting at least {}", + newPrintableBytes(avail), + newPrintableBytes(required)); sufficientMemory.set(true); } } Index: oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/GCNodeWriteMonitor.java =================================================================== --- oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/GCNodeWriteMonitor.java (revision 1818032) +++ oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/GCNodeWriteMonitor.java (working copy) @@ -65,16 +65,12 @@ private boolean running = false; - private long gcCount; - public GCNodeWriteMonitor(long gcProgressLog, @Nonnull GCMonitor gcMonitor) { this.gcProgressLog = gcProgressLog; this.gcMonitor = gcMonitor; } /** - * @param gcCount - * current gc run * @param prevSize * size from latest successful compaction * @param prevCompactedNodes @@ -82,16 +78,15 @@ * @param currentSize * current repository size */ - public synchronized void init(long gcCount, long prevSize, long prevCompactedNodes, long currentSize) { - this.gcCount = gcCount; + public synchronized void init(long prevSize, long prevCompactedNodes, long currentSize) { if (prevCompactedNodes > 0) { estimated = (long) (((double) currentSize / prevSize) * prevCompactedNodes); gcMonitor.info( - "TarMK GC #{}: estimated number of nodes to compact is {}, based on {} nodes compacted to {} bytes " - + "on disk in previous compaction and current size of {} bytes on disk.", - this.gcCount, estimated, prevCompactedNodes, prevSize, currentSize); + "estimated number of nodes to compact is {}, based on {} nodes compacted to {} bytes " + + "on disk in previous compaction and current size of {} bytes on disk.", + estimated, prevCompactedNodes, prevSize, currentSize); } else { - gcMonitor.info("TarMK GC #{}: unable to estimate number of nodes for compaction, missing gc history.", gcCount); + gcMonitor.info("unable to estimate number of nodes for compaction, missing gc history."); } nodes = 0; start = System.currentTimeMillis(); @@ -101,8 +96,8 @@ public synchronized void onNode() { nodes++; if (gcProgressLog > 0 && nodes % gcProgressLog == 0) { - gcMonitor.info("TarMK GC #{}: compacted {} nodes, {} properties, {} binaries in {} ms. {}", - gcCount, nodes, properties, binaries, System.currentTimeMillis() - start, getPercentageDone()); + gcMonitor.info("compacted {} nodes, {} properties, {} binaries in {} ms. {}", + nodes, properties, binaries, System.currentTimeMillis() - start, getPercentageDone()); } } Index: oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/PrintableBytes.java =================================================================== --- oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/PrintableBytes.java (nonexistent) +++ oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/PrintableBytes.java (working copy) @@ -0,0 +1,31 @@ +package org.apache.jackrabbit.oak.segment.file; + +import static org.apache.jackrabbit.oak.commons.IOUtils.humanReadableByteCount; + +/** + * An amount of bytes that is also pretty-printable for usage in logs. + */ +class PrintableBytes { + + /** + * Create a new instance a {@link PrintableBytes}. + * + * @param bytes The amount of bytes. + * @return A new instance of {@link PrintableBytes}. + */ + static PrintableBytes newPrintableBytes(long bytes) { + return new PrintableBytes(bytes); + } + + private final long bytes; + + private PrintableBytes(long bytes) { + this.bytes = bytes; + } + + @Override + public String toString() { + return String.format("%s (%d bytes)", humanReadableByteCount(bytes), bytes); + } + +} Property changes on: oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/PrintableBytes.java ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/PrintableStopwatch.java =================================================================== --- oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/PrintableStopwatch.java (nonexistent) +++ oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/PrintableStopwatch.java (working copy) @@ -0,0 +1,32 @@ +package org.apache.jackrabbit.oak.segment.file; + +import java.util.concurrent.TimeUnit; + +import com.google.common.base.Stopwatch; + +/** + * A stopwatch that is also pretty-printable for usage in log messages. + */ +class PrintableStopwatch { + + /** + * Create a new {@link PrintableStopwatch} and starts it. + * + * @return A new instance of {@link PrintableStopwatch}. + */ + static PrintableStopwatch createStarted() { + return new PrintableStopwatch(Stopwatch.createStarted()); + } + + private final Stopwatch stopwatch; + + private PrintableStopwatch(Stopwatch stopwatch) { + this.stopwatch = stopwatch; + } + + @Override + public String toString() { + return String.format("%s (%d ms)", stopwatch, stopwatch.elapsed(TimeUnit.MILLISECONDS)); + } + +} Property changes on: oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/PrintableStopwatch.java ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/SizeDeltaGcEstimation.java =================================================================== --- oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/SizeDeltaGcEstimation.java (revision 1818032) +++ oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/SizeDeltaGcEstimation.java (working copy) @@ -22,7 +22,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.collect.Lists.newArrayList; import static java.lang.String.format; -import static org.apache.jackrabbit.oak.commons.IOUtils.humanReadableByteCount; +import static org.apache.jackrabbit.oak.segment.file.PrintableBytes.newPrintableBytes; import java.util.ArrayList; import java.util.List; @@ -68,21 +68,22 @@ long gain = currentSize - previousSize; boolean gcNeeded = gain > delta; String gcInfo = format( - "Segmentstore size has increased since the last %s garbage collection from %s (%s bytes) to %s (%s bytes), an increase of %s (%s bytes) or %s%%. ", + "Segmentstore size has increased since the last %s garbage collection from %s to %s, an increase of %s or %s%%. ", full ? "full" : "tail", - humanReadableByteCount(previousSize), previousSize, - humanReadableByteCount(currentSize), currentSize, - humanReadableByteCount(gain), gain, 100 * gain / previousSize + newPrintableBytes(previousSize), + newPrintableBytes(currentSize), + newPrintableBytes(gain), + 100 * gain / previousSize ); if (gcNeeded) { gcInfo = gcInfo + format( - "This is greater than sizeDeltaEstimation=%s (%s bytes), so running garbage collection", - humanReadableByteCount(delta), delta + "This is greater than sizeDeltaEstimation=%s, so running garbage collection", + newPrintableBytes(delta) ); } else { gcInfo = gcInfo + format( - "This is less than sizeDeltaEstimation=%s (%s bytes), so skipping garbage collection", - humanReadableByteCount(delta), delta + "This is less than sizeDeltaEstimation=%s, so skipping garbage collection", + newPrintableBytes(delta) ); } return new GCEstimationResult(gcNeeded, gcInfo); Index: oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/CheckpointCompactorTest.java =================================================================== --- oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/CheckpointCompactorTest.java (revision 1818032) +++ oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/CheckpointCompactorTest.java (working copy) @@ -35,7 +35,6 @@ import java.io.IOException; import java.util.List; import java.util.Random; -import java.util.concurrent.atomic.AtomicLong; import javax.annotation.Nonnull; @@ -171,7 +170,6 @@ return new CheckpointCompactor( GCMonitor.EMPTY, - new AtomicLong(), fileStore.getReader(), writer, fileStore.getBlobStore(),