jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1547211 - /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/AbstractStore.java
Date Mon, 02 Dec 2013 22:17:09 GMT
Author: jukka
Date: Mon Dec  2 22:17:08 2013
New Revision: 1547211

URL: http://svn.apache.org/r1547211
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

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=1547211&r1=1547210&r2=1547211&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:17:08 2013
@@ -18,7 +18,6 @@ package org.apache.jackrabbit.oak.plugin
 
 import static com.google.common.collect.Sets.newHashSet;
 import static org.apache.jackrabbit.oak.plugins.segment.SegmentIdFactory.isBulkSegmentId;
-import static org.apache.jackrabbit.oak.plugins.segment.SegmentIdFactory.isDataSegmentId;
 
 import java.util.Set;
 import java.util.UUID;
@@ -41,6 +40,12 @@ public abstract class AbstractStore impl
      */
     private final Set<UUID> currentlyLoading = newHashSet();
 
+    /**
+     * Number of threads that are currently waiting for segments to be loaded.
+     * Used to avoid extra {@link #notifyAll()} calls when nobody is waiting.
+     */
+    private int currentlyWaiting = 0;
+
     private final Cache<RecordId, Object> records =
             CacheLIRS.newBuilder().maximumSize(1000).build();
 
@@ -87,9 +92,12 @@ public abstract class AbstractStore impl
             // ... or currently being loaded
             while (segment == null && currentlyLoading.contains(id)) {
                 try {
+                    currentlyWaiting++;
                     wait(); // for another thread to load the segment
                 } catch (InterruptedException e) {
                     throw new RuntimeException("Interrupted", e);
+                } finally {
+                    currentlyWaiting--;
                 }
                 segment = segments.getIfPresent(id);
             }
@@ -108,7 +116,9 @@ public abstract class AbstractStore impl
         } finally {
             synchronized (this) {
                 currentlyLoading.remove(id);
-                notifyAll();
+                if (currentlyWaiting > 0) {
+                    notifyAll();
+                }
             }
         }
     }



Mime
View raw message