Author: mreutegg
Date: Wed Sep 28 11:01:01 2016
New Revision: 1762632
URL: http://svn.apache.org/viewvc?rev=1762632&view=rev
Log:
OAK-4826: Auto removal of orphaned checkpoints
Preserve checkpoints within lease time frame
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexUpdate.java
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexUpdateTest.java
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexUpdate.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexUpdate.java?rev=1762632&r1=1762631&r2=1762632&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexUpdate.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexUpdate.java
Wed Sep 28 11:01:01 2016
@@ -553,7 +553,8 @@ public class AsyncIndexUpdate implements
// remove unreferenced AsyncIndexUpdate checkpoints:
// - without 'created' info (checkpoint created before OAK-4826)
// or
- // - 'created' value older than the current reference
+ // - 'created' value older than the current reference and
+ // not within the lease time frame
long current = ISO8601.parse(value).getTimeInMillis();
for (String checkpoint : store.checkpoints()) {
info = store.checkpointInfo(checkpoint);
@@ -563,7 +564,7 @@ public class AsyncIndexUpdate implements
if (!keep.contains(checkpoint)
&& this.name.equals(name)
&&
AsyncIndexUpdate.class.getSimpleName().equals(creator)
- && (created == null ||
ISO8601.parse(created).getTimeInMillis() < current)) {
+ && (created == null ||
ISO8601.parse(created).getTimeInMillis() + leaseTimeOut < current)) {
if (store.release(checkpoint)) {
log.info("Removed orphaned checkpoint '{}' {}",
checkpoint, info);
@@ -712,6 +713,10 @@ public class AsyncIndexUpdate implements
return this;
}
+ protected long getLeaseTimeOut() {
+ return leaseTimeOut;
+ }
+
protected AsyncIndexUpdate setCloseTimeOut(int timeOutInSec) {
this.softTimeOutSecs = timeOutInSec;
return this;
Modified:
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexUpdateTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexUpdateTest.java?rev=1762632&r1=1762631&r2=1762632&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexUpdateTest.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexUpdateTest.java
Wed Sep 28 11:01:01 2016
@@ -35,6 +35,7 @@ import static org.junit.Assert.assertTru
import static org.junit.Assert.fail;
import java.util.ArrayList;
+import java.util.Calendar;
import java.util.Collections;
import java.util.List;
import java.util.Map;
@@ -74,6 +75,7 @@ import org.apache.jackrabbit.oak.spi.sta
import org.apache.jackrabbit.oak.spi.state.NodeStore;
import org.apache.jackrabbit.oak.spi.state.ProxyNodeStore;
import org.apache.jackrabbit.oak.stats.Clock;
+import org.apache.jackrabbit.util.ISO8601;
import org.junit.Test;
import ch.qos.logback.classic.Level;
@@ -717,7 +719,12 @@ public class AsyncIndexUpdateTest {
cp = store.listCheckpoints().iterator().next();
// create a new checkpoint with the info from the first checkpoint
- // this simulates an orphaned checkpoint that should be cleaned up
+ // this simulates an orphaned checkpoint that should be cleaned up.
+ // the created timestamp is set back in time because cleanup preserves
+ // checkpoints within the lease time frame.
+ Calendar c = Calendar.getInstance();
+ c.setTimeInMillis(clock.getTime() - 2 * async.getLeaseTimeOut());
+ info.put("created", ISO8601.format(c));
assertNotNull(store.checkpoint(TimeUnit.HOURS.toMillis(1), info));
assertTrue("Expecting two checkpoints",
store.listCheckpoints().size() == 2);