You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by fr...@apache.org on 2017/12/15 10:13:49 UTC
svn commit: r1818258 - in /jackrabbit/oak/trunk/oak-segment-tar/src:
main/java/org/apache/jackrabbit/oak/segment/
main/java/org/apache/jackrabbit/oak/segment/file/
test/java/org/apache/jackrabbit/oak/segment/
Author: frm
Date: Fri Dec 15 10:13:48 2017
New Revision: 1818258
URL: http://svn.apache.org/viewvc?rev=1818258&view=rev
Log:
OAK-7064 - Remove duplicated code from the FileStore logging implementation
Added:
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/PrefixedGCListener.java (with props)
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/PrintableBytes.java (with props)
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/PrintableStopwatch.java (with props)
Modified:
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/CheckpointCompactor.java
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/FileStore.java
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/GCMemoryBarrier.java
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/GCNodeWriteMonitor.java
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/SizeDeltaGcEstimation.java
jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/CheckpointCompactorTest.java
Modified: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/CheckpointCompactor.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/CheckpointCompactor.java?rev=1818258&r1=1818257&r2=1818258&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/CheckpointCompactor.java (original)
+++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/CheckpointCompactor.java Fri Dec 15 10:13:48 2017
@@ -33,7 +33,6 @@ import java.util.LinkedHashMap;
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 @@ public class CheckpointCompactor {
private final GCMonitor gcListener;
@Nonnull
- private final AtomicLong gcCount;
-
- @Nonnull
private final Map<NodeState, NodeState> cpCache = newHashMap();
@Nonnull
@@ -90,14 +86,12 @@ public class CheckpointCompactor {
*/
public CheckpointCompactor(
@Nonnull GCMonitor gcListener,
- @Nonnull AtomicLong gcCount,
@Nonnull SegmentReader reader,
@Nonnull SegmentWriter writer,
@Nullable BlobStore blobStore,
@Nonnull Supplier<Boolean> 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 @@ public class CheckpointCompactor {
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 @@ public class CheckpointCompactor {
@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 @@ public class CheckpointCompactor {
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);
}
}
Modified: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/FileStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/FileStore.java?rev=1818258&r1=1818257&r2=1818258&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/FileStore.java (original)
+++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/FileStore.java Fri Dec 15 10:13:48 2017
@@ -36,6 +36,7 @@ import static org.apache.jackrabbit.oak.
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 javax.annotation.Nullable;
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 @@ public class FileStore extends AbstractF
}
});
- 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 @@ public class FileStore extends AbstractF
Closer closer = Closer.create();
closer.register(lockFile);
closer.register(lock::release);
- closer.register(tarFiles) ;
+ closer.register(tarFiles);
closer.register(revisions);
closeAndLogOnFail(closer);
@@ -550,6 +549,7 @@ public class FileStore extends AbstractF
}
private class GarbageCollector {
+
@Nonnull
private final SegmentGCOptions gcOptions;
@@ -557,7 +557,7 @@ public class FileStore extends AbstractF
* {@code GcListener} listening to this instance's gc progress
*/
@Nonnull
- private final GCListener gcListener;
+ private final PrefixedGCListener gcListener;
@Nonnull
private final GCJournal gcJournal;
@@ -582,7 +582,7 @@ public class FileStore extends AbstractF
@Nonnull GCJournal gcJournal,
@Nonnull WriterCacheManager cacheManager) {
this.gcOptions = gcOptions;
- this.gcListener = gcListener;
+ this.gcListener = new PrefixedGCListener(gcListener, GC_COUNT);
this.gcJournal = gcJournal;
this.cacheManager = cacheManager;
}
@@ -614,53 +614,49 @@ public class FileStore extends AbstractF
private void run(boolean full, Supplier<CompactionResult> 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 +701,23 @@ public class FileStore extends AbstractF
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 +725,8 @@ public class FileStore extends AbstractF
@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 +741,20 @@ public class FileStore extends AbstractF
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 +765,51 @@ public class FileStore extends AbstractF
// 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 +818,18 @@ public class FileStore extends AbstractF
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 +846,16 @@ public class FileStore extends AbstractF
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 +907,10 @@ public class FileStore extends AbstractF
*/
@Nonnull
private List<File> 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 +920,10 @@ public class FileStore extends AbstractF
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 +932,11 @@ public class FileStore extends AbstractF
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();
}
Modified: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/GCMemoryBarrier.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/GCMemoryBarrier.java?rev=1818258&r1=1818257&r2=1818258&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/GCMemoryBarrier.java (original)
+++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/GCMemoryBarrier.java Fri Dec 15 10:13:48 2017
@@ -21,7 +21,7 @@ package org.apache.jackrabbit.oak.segmen
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 @@ public class GCMemoryBarrier implements
@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 @@ public class GCMemoryBarrier implements
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 @@ public class GCMemoryBarrier implements
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);
}
}
Modified: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/GCNodeWriteMonitor.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/GCNodeWriteMonitor.java?rev=1818258&r1=1818257&r2=1818258&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/GCNodeWriteMonitor.java (original)
+++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/GCNodeWriteMonitor.java Fri Dec 15 10:13:48 2017
@@ -65,16 +65,12 @@ public class GCNodeWriteMonitor {
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 @@ public class GCNodeWriteMonitor {
* @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 class GCNodeWriteMonitor {
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());
}
}
Added: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/PrefixedGCListener.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/PrefixedGCListener.java?rev=1818258&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/PrefixedGCListener.java (added)
+++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/PrefixedGCListener.java Fri Dec 15 10:13:48 2017
@@ -0,0 +1,74 @@
+package org.apache.jackrabbit.oak.segment.file;
+
+import java.util.concurrent.atomic.AtomicLong;
+
+import javax.annotation.Nonnull;
+
+import org.apache.jackrabbit.oak.segment.file.tar.GCGeneration;
+
+/**
+ * A {@link GCListener} that adds a prefix to every log message and delegates to
+ * another {@link GCListener}. The message prefix includes a number, which can
+ * be used as a unique counter to group together related log messages.
+ */
+class PrefixedGCListener implements GCListener {
+
+ private final GCListener listener;
+
+ private final AtomicLong counter;
+
+ PrefixedGCListener(GCListener listener, AtomicLong counter) {
+ this.listener = listener;
+ this.counter = counter;
+ }
+
+ private String prefixed(String message) {
+ return String.format("TarMK GC #%s: %s", counter, message);
+ }
+
+ @Override
+ public void compactionSucceeded(@Nonnull GCGeneration newGeneration) {
+ listener.compactionSucceeded(newGeneration);
+ }
+
+ @Override
+ public void compactionFailed(@Nonnull GCGeneration failedGeneration) {
+ listener.compactionFailed(failedGeneration);
+ }
+
+ @Override
+ public void info(String message, Object... arguments) {
+ listener.info(prefixed(message), arguments);
+ }
+
+ @Override
+ public void warn(String message, Object... arguments) {
+ listener.warn(prefixed(message), arguments);
+ }
+
+ @Override
+ public void error(String message, Exception exception) {
+ listener.error(prefixed(message), exception);
+ }
+
+ @Override
+ public void skipped(String reason, Object... arguments) {
+ listener.skipped(prefixed(reason), arguments);
+ }
+
+ @Override
+ public void compacted() {
+ listener.compacted();
+ }
+
+ @Override
+ public void cleaned(long reclaimedSize, long currentSize) {
+ listener.cleaned(reclaimedSize, currentSize);
+ }
+
+ @Override
+ public void updateStatus(String status) {
+ listener.updateStatus(status);
+ }
+
+}
Propchange: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/PrefixedGCListener.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/PrintableBytes.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/PrintableBytes.java?rev=1818258&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/PrintableBytes.java (added)
+++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/PrintableBytes.java Fri Dec 15 10:13:48 2017
@@ -0,0 +1,32 @@
+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);
+ }
+
+}
+
Propchange: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/PrintableBytes.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/PrintableStopwatch.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/PrintableStopwatch.java?rev=1818258&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/PrintableStopwatch.java (added)
+++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/PrintableStopwatch.java Fri Dec 15 10:13:48 2017
@@ -0,0 +1,33 @@
+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));
+ }
+
+}
+
Propchange: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/PrintableStopwatch.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/SizeDeltaGcEstimation.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/SizeDeltaGcEstimation.java?rev=1818258&r1=1818257&r2=1818258&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/SizeDeltaGcEstimation.java (original)
+++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/SizeDeltaGcEstimation.java Fri Dec 15 10:13:48 2017
@@ -22,7 +22,7 @@ package org.apache.jackrabbit.oak.segmen
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 @@ class SizeDeltaGcEstimation implements G
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);
Modified: jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/CheckpointCompactorTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/CheckpointCompactorTest.java?rev=1818258&r1=1818257&r2=1818258&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/CheckpointCompactorTest.java (original)
+++ jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/CheckpointCompactorTest.java Fri Dec 15 10:13:48 2017
@@ -35,7 +35,6 @@ import java.io.File;
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 @@ public class CheckpointCompactorTest {
return new CheckpointCompactor(
GCMonitor.EMPTY,
- new AtomicLong(),
fileStore.getReader(),
writer,
fileStore.getBlobStore(),