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 ju...@apache.org on 2013/12/02 23:22:37 UTC

svn commit: r1547220 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment: AbstractStore.java SegmentNodeStore.java

Author: jukka
Date: Mon Dec  2 22:22:37 2013
New Revision: 1547220

URL: http://svn.apache.org/r1547220
Log:
OAK-593: Segment-based MK

Avoid extra notifyAll() calls when nobody is waiting

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/AbstractStore.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStore.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/AbstractStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/AbstractStore.java?rev=1547220&r1=1547219&r2=1547220&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/AbstractStore.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/AbstractStore.java Mon Dec  2 22:22:37 2013
@@ -91,8 +91,8 @@ public abstract class AbstractStore impl
             segment = segments.getIfPresent(id);
             // ... or currently being loaded
             while (segment == null && currentlyLoading.contains(id)) {
+                currentlyWaiting++;
                 try {
-                    currentlyWaiting++;
                     wait(); // for another thread to load the segment
                 } catch (InterruptedException e) {
                     throw new RuntimeException("Interrupted", e);

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStore.java?rev=1547220&r1=1547219&r2=1547220&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStore.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStore.java Mon Dec  2 22:22:37 2013
@@ -56,8 +56,17 @@ public class SegmentNodeStore implements
 
     volatile SegmentNodeState head;
 
+    /**
+     * Whether a thread is currently processing a local commit.
+     */
     private boolean inLocalCommit = false;
 
+    /**
+     * Number of threads waiting to make a local commit.
+     * Used to avoid extra {@link #notifyAll()} calls when nobody is waiting.
+     */
+    private long waitingToCommit = 0;
+
     private long maximumBackoff = MILLISECONDS.convert(10, SECONDS);
 
     public SegmentNodeStore(SegmentStore store, String journal) {
@@ -97,7 +106,12 @@ public class SegmentNodeStore implements
             throws InterruptedException {
         if (start) {
             while (inLocalCommit) {
-                wait();
+                waitingToCommit++;
+                try {
+                    wait();
+                } finally {
+                    waitingToCommit--;
+                }
             }
             inLocalCommit = true;
         } else {
@@ -109,7 +123,9 @@ public class SegmentNodeStore implements
         } finally {
             if (!start) {
                 inLocalCommit = false;
-                notifyAll();
+                if (waitingToCommit > 0) {
+                    notifyAll();
+                }
             }
         }
     }