jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1593250 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/plugins/document/Revision.java test/java/org/apache/jackrabbit/oak/plugins/document/RevisionTest.java
Date Thu, 08 May 2014 12:29:52 GMT
Author: thomasm
Date: Thu May  8 12:29:52 2014
New Revision: 1593250

URL: http://svn.apache.org/r1593250
Log:
OAK-1807 ConstraintViolationException seen with multiple Oak/Mongo with ConcurrentCreateNodesTest

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Revision.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/RevisionTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Revision.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Revision.java?rev=1593250&r1=1593249&r2=1593250&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Revision.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Revision.java
Thu May  8 12:29:52 2014
@@ -156,6 +156,12 @@ public class Revision {
         long timestamp = getCurrentTimestamp();
         int c;
         synchronized (Revision.class) {
+            // need to check again, because threads
+            // could arrive inside the synchronized block
+            // out of order
+            if (timestamp < lastRevisionTimestamp) {
+                timestamp = lastRevisionTimestamp;
+            }
             if (timestamp == lastRevisionTimestamp) {
                 c = ++lastRevisionCount;
             } else {

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/RevisionTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/RevisionTest.java?rev=1593250&r1=1593249&r2=1593250&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/RevisionTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/RevisionTest.java
Thu May  8 12:29:52 2014
@@ -17,6 +17,8 @@
 package org.apache.jackrabbit.oak.plugins.document;
 
 import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 import java.util.concurrent.BlockingQueue;
@@ -35,8 +37,6 @@ import com.google.common.collect.Queues;
 import com.google.common.collect.Sets;
 import com.google.common.util.concurrent.Uninterruptibles;
 import org.apache.jackrabbit.oak.plugins.document.Revision.RevisionComparator;
-import org.apache.jackrabbit.oak.stats.Clock;
-import org.junit.Ignore;
 import org.junit.Test;
 
 /**
@@ -297,7 +297,44 @@ public class RevisionTest {
         assertEquals(new Revision(0x30, 0, 0), comp.getRevisionSeen(r21));
     }
 
-    @Ignore("OAK-1807")
+    @Test
+    public void uniqueRevision2() throws Exception {
+        List<Thread> threads = new ArrayList<Thread>();
+        final AtomicBoolean stop = new AtomicBoolean();
+        final Set<Revision> set = Collections
+                .synchronizedSet(new HashSet<Revision>());
+        final Revision[] duplicate = new Revision[1];
+        for (int i = 0; i < 20; i++) {
+            Thread thread = new Thread(new Runnable() {
+                @Override
+                public void run() {
+                    Revision[] last = new Revision[1024];
+                    while (!stop.get()) {
+                        for (Revision r : last) {
+                            set.remove(r);
+                        }
+                        for (int i = 0; i < last.length; i++) {
+                            last[i] = Revision.newRevision(1);
+                        }
+                        for (Revision r : last) {
+                            if (!set.add(r)) {
+                                duplicate[0] = r;
+                            }
+                        }
+                    }
+                }
+            });
+            thread.start();
+            threads.add(thread);
+        }
+        Thread.sleep(200);
+        stop.set(true);
+        for (Thread t : threads) {
+            t.join();
+        }
+        assertNull("Duplicate revision", duplicate[0]);
+    }
+
     @Test
     public void uniqueRevision() throws Exception {
         //Revision.setClock(new Clock.Virtual());



Mime
View raw message