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 md...@apache.org on 2016/12/21 14:59:05 UTC
svn commit: r1775464 -
/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/FileStore.java
Author: mduerig
Date: Wed Dec 21 14:59:04 2016
New Revision: 1775464
URL: http://svn.apache.org/viewvc?rev=1775464&view=rev
Log:
OAK-4873: Avoid running GC too frequently
Introduce a backoff time within which gc cannot be triggered to guard against transient SNFEs
Modified:
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/FileStore.java
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=1775464&r1=1775463&r2=1775464&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 Wed Dec 21 14:59:04 2016
@@ -23,6 +23,7 @@ import static com.google.common.collect.
import static com.google.common.collect.Lists.newLinkedList;
import static com.google.common.collect.Maps.newLinkedHashMap;
import static com.google.common.collect.Sets.newHashSet;
+import static java.lang.Integer.getInteger;
import static java.lang.String.format;
import static java.lang.System.currentTimeMillis;
import static java.lang.Thread.currentThread;
@@ -96,9 +97,15 @@ import org.slf4j.LoggerFactory;
* The storage implementation for tar files.
*/
public class FileStore extends AbstractFileStore {
-
private static final Logger log = LoggerFactory.getLogger(FileStore.class);
+ /**
+ * Minimal interval in milli seconds between subsequent garbage collection cycles.
+ * Garbage collection invoked via {@link #gc()} will be skipped unless at least
+ * the specified time has passed since its last successful invocation.
+ */
+ private static final long GC_BACKOFF = getInteger("gc.backoff", 10*3600*1000);
+
private static final int MB = 1024 * 1024;
static final String LOCK_FILE_NAME = "repo.lock";
@@ -712,11 +719,14 @@ public class FileStore extends AbstractF
@Nonnull
private final WriterCacheManager cacheManager;
- private volatile boolean cancelled;
-
@Nonnull
private final GCNodeWriteMonitor compactionMonitor;
+ private volatile boolean cancelled;
+
+ /** Timestamp of the last time {@link #gc()} was successfully invoked. 0 if never. */
+ private long lastSuccessfullGC;
+
GarbageCollector(
@Nonnull SegmentGCOptions gcOptions,
@Nonnull GCListener gcListener,
@@ -732,6 +742,14 @@ public class FileStore extends AbstractF
synchronized void run() throws IOException {
try {
gcListener.info("TarMK GC #{}: started", GC_COUNT.incrementAndGet());
+
+ 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);
+ return;
+ }
+
GCMemoryBarrier gcMemoryBarrier = new GCMemoryBarrier(
sufficientMemory, gcListener, GC_COUNT.get(), gcOptions);
@@ -772,6 +790,7 @@ public class FileStore extends AbstractF
int gen = compact();
if (gen > 0) {
fileReaper.add(cleanupOldGenerations(gen));
+ lastSuccessfullGC = System.currentTimeMillis();
} else if (gen < 0) {
gcListener.info("TarMK GC #{}: cleaning up after failed compaction", GC_COUNT);
fileReaper.add(cleanupGeneration(-gen));
Re: svn commit: r1775464 -
/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/FileStore.java
Posted by Michael Dürig <md...@apache.org>.
On 21.12.16 4:17 , Chetan Mehrotra wrote:
> On Wed, Dec 21, 2016 at 8:29 PM, <md...@apache.org> wrote:
>> + */
>> + private static final long GC_BACKOFF = getInteger("gc.backoff", 10*3600*1000);
>> +
>
> Would be good to prefix the system property with "oak" .
Good catch, done at http://svn.apache.org/viewvc?rev=1775476&view=rev
Michael
Re: svn commit: r1775464 - /jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/FileStore.java
Posted by Chetan Mehrotra <ch...@gmail.com>.
On Wed, Dec 21, 2016 at 8:29 PM, <md...@apache.org> wrote:
> + */
> + private static final long GC_BACKOFF = getInteger("gc.backoff", 10*3600*1000);
> +
Would be good to prefix the system property with "oak" .
Chetan Mehrotra