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 al...@apache.org on 2015/12/09 11:19:05 UTC

svn commit: r1718802 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexUpdate.java test/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexUpdateLeaseTest.java

Author: alexparvulescu
Date: Wed Dec  9 10:19:04 2015
New Revision: 1718802

URL: http://svn.apache.org/viewvc?rev=1718802&view=rev
Log:
OAK-3436 Prevent missing checkpoint due to unstable topology from causing complete reindexing
 - added tests for reindexing+lease expired scenario, fixed a loophole related to reindexing and lease checks

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/AsyncIndexUpdateLeaseTest.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=1718802&r1=1718801&r2=1718802&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 Dec  9 10:19:04 2015
@@ -502,7 +502,8 @@ public class AsyncIndexUpdate implements
                     throws CommitFailedException {
                 // check for concurrent updates by this async task
                 NodeState async = before.getChildNode(ASYNC);
-                if (checkpoint == null || Objects.equal(checkpoint, async.getString(name))
+                if ((checkpoint == null || Objects.equal(checkpoint,
+                        async.getString(name)))
                         && lease == async.getLong(leasify(name))) {
                     return after;
                 } else {

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexUpdateLeaseTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexUpdateLeaseTest.java?rev=1718802&r1=1718801&r2=1718802&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexUpdateLeaseTest.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexUpdateLeaseTest.java Wed Dec  9 10:19:04 2015
@@ -239,7 +239,6 @@ public class AsyncIndexUpdateLeaseTest e
 
     @Test
     public void testPrePrepareRexindex() throws Exception {
-
         final IndexStatusListener l1 = new IndexStatusListener() {
 
             @Override
@@ -293,6 +292,66 @@ public class AsyncIndexUpdateLeaseTest e
         assertRunOk(new SpecialAsyncIndexUpdate(name, store, provider, l1));
     }
 
+    @Test
+    public void testPostPrepareReindexLeaseExpired() throws Exception {
+        final long lease = 50;
+        final IndexStatusListener l1 = new IndexStatusListener() {
+
+            @Override
+            protected void postPrepare() {
+                executed.set(true);
+                try {
+                    TimeUnit.MILLISECONDS.sleep(lease * 3);
+                } catch (InterruptedException e) {
+                    //
+                }
+                assertRunOk(new AsyncIndexUpdate(name, store, provider));
+            }
+        };
+        assertRunKo(new SpecialAsyncIndexUpdate(name, store, provider, l1)
+                .setLeaseTimeOut(lease));
+    }
+
+    @Test
+    public void testPreIndexUpdateReindexLeaseExpired() throws Exception {
+        final long lease = 50;
+        final IndexStatusListener l1 = new IndexStatusListener() {
+
+            @Override
+            protected void preIndexUpdate() {
+                executed.set(true);
+                try {
+                    TimeUnit.MILLISECONDS.sleep(lease * 3);
+                } catch (InterruptedException e) {
+                    //
+                }
+                assertRunOk(new AsyncIndexUpdate(name, store, provider));
+            }
+        };
+        assertRunKo(new SpecialAsyncIndexUpdate(name, store, provider, l1)
+                .setLeaseTimeOut(lease));
+    }
+
+    @Test
+    public void testPostIndexUpdateReindexLeaseExpired() throws Exception {
+        final long lease = 50;
+        final IndexStatusListener l1 = new IndexStatusListener() {
+
+            @Override
+            protected void postIndexUpdate() {
+                executed.set(true);
+                try {
+                    TimeUnit.MILLISECONDS.sleep(lease * 3);
+                } catch (InterruptedException e) {
+                    //
+                }
+                assertRunOk(new AsyncIndexUpdate(name, store, provider));
+            }
+        };
+        assertRunKo(new SpecialAsyncIndexUpdate(name, store, provider, l1)
+                .setLeaseTimeOut(lease));
+    }
+
     // -------------------------------------------------------------------
 
     private static String getReferenceCp(NodeStore store, String name) {
@@ -309,9 +368,9 @@ public class AsyncIndexUpdateLeaseTest e
         assertConcurrentUpdate(a.getIndexStats());
     }
 
-    private void assertRun(AsyncIndexUpdate a, boolean status) {
+    private void assertRun(AsyncIndexUpdate a, boolean failing) {
         a.run();
-        assertEquals("Unexpected failiure flag", status, a.isFailing());
+        assertEquals("Unexpected failiure flag", failing, a.isFailing());
     }
 
     private void assertConcurrentUpdate(AsyncIndexStats stats) {