Author: mduerig
Date: Wed Mar 25 17:50:13 2015
New Revision: 1669183

URL: http://svn.apache.org/r1669183
Log:
OAK-2680: Report a full observation queue situation to the logfile
Credits to Mark Pfaff for the patch

Modified:
    
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/BackgroundObserver.java

Modified: 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/BackgroundObserver.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/BackgroundObserver.java?rev=1669183&r1=1669182&r2=1669183&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/BackgroundObserver.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/BackgroundObserver.java
 Wed Mar 25 17:50:13 2015
@@ -51,6 +51,7 @@ import org.slf4j.LoggerFactory;
  * to just one change.
  */
 public class BackgroundObserver implements Observer, Closeable {
+    private static final Logger LOG = 
LoggerFactory.getLogger(BackgroundObserver.class);
 
     /**
      * Signal for the background thread to stop processing changes.
@@ -77,6 +78,11 @@ public class BackgroundObserver implemen
      */
     private final BlockingQueue<ContentChange> queue;
 
+    /**
+     * The max queue length used for this observer's queue
+     */
+    private final int maxQueueLength;
+
     private static class ContentChange {
         private final NodeState root;
         private final CommitInfo info;
@@ -144,7 +150,8 @@ public class BackgroundObserver implemen
         this.observer = checkNotNull(observer);
         this.executor = checkNotNull(executor);
         this.exceptionHandler = checkNotNull(exceptionHandler);
-        this.queue = newArrayBlockingQueue(queueLength);
+        this.maxQueueLength = queueLength;
+        this.queue = newArrayBlockingQueue(maxQueueLength);
     }
 
     public BackgroundObserver(
@@ -172,6 +179,18 @@ public class BackgroundObserver implemen
     protected void added(int queueSize) { }
 
     /**
+     * Private utility to report queue size to observers
+     * @param queueSize current size of the queue
+     */
+    private void reportAdded(int queueSize){
+        if(queueSize == maxQueueLength ){
+            LOG.warn("Revision queue for observer {} is full (max = {}). 
Further revisions will be compacted.",
+                    observer != null ? observer.getClass().getName(): "", 
maxQueueLength);
+        }
+        added(queueSize);
+    }
+
+    /**
      * Clears the change queue and signals the background thread to stop
      * without making any further {@link #contentChanged(NodeState, 
CommitInfo)}
      * calls to the background observer. If the thread is currently in the
@@ -232,7 +251,7 @@ public class BackgroundObserver implemen
         // to onComplete are not a problem here since we always pass the same 
value.
         // Thus there is no question as to which of the handlers will 
effectively run.
         currentTask.onComplete(completionHandler);
-        added(queue.size());
+        reportAdded(queue.size());
     }
 
     //------------------------------------------------------------< internal 
>---


Reply via email to