incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1141439 - in /sling/trunk/bundles/extensions/event/src: main/java/org/apache/sling/event/impl/jobs/ main/java/org/apache/sling/event/impl/jobs/jcr/ main/java/org/apache/sling/event/impl/jobs/queues/ test/java/org/apache/sling/event/impl/jo...
Date Thu, 30 Jun 2011 08:33:44 GMT
Author: cziegeler
Date: Thu Jun 30 08:33:44 2011
New Revision: 1141439

URL: http://svn.apache.org/viewvc?rev=1141439&view=rev
Log:
SLING-2119 : Add a periodic sanity check to the internal job cache

Modified:
    sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/DefaultJobManager.java
    sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/JobEvent.java
    sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/jcr/JCRJobEvent.java
    sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/jcr/PersistenceHandler.java
    sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/queues/AbstractJobQueue.java
    sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/impl/jobs/config/InternalQueueConfigurationTest.java

Modified: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/DefaultJobManager.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/DefaultJobManager.java?rev=1141439&r1=1141438&r2=1141439&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/DefaultJobManager.java
(original)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/DefaultJobManager.java
Thu Jun 30 08:33:44 2011
@@ -213,6 +213,8 @@ public class DefaultJobManager
      * @see java.lang.Runnable#run()
      */
     private void cleanup() {
+        logger.debug("cleanup: Starting #{}", this.schedulerRuns + 1);
+
         // check for unprocessed jobs first
         for(final AbstractJobQueue jbq : this.queues.values() ) {
             jbq.checkForUnprocessedJobs();
@@ -224,6 +226,8 @@ public class DefaultJobManager
 
         if ( doFullCleanUp ) {
             // check for idle queue
+            logger.debug("cleanup: doing full cleanup");
+
            // we synchronize to avoid creating a queue which is about to be removed during
cleanup
             synchronized ( queuesLock ) {
                 final Iterator<Map.Entry<String, AbstractJobQueue>> i = this.queues.entrySet().iterator();
@@ -231,6 +235,7 @@ public class DefaultJobManager
                     final Map.Entry<String, AbstractJobQueue> current = i.next();
                     final AbstractJobQueue jbq = current.getValue();
                     if ( jbq.isMarkedForRemoval() ) {
+                        logger.debug("cleanup: Removing idle Job Queue {}", jbq);
                         // close
                         jbq.close();
                         // copy statistics
@@ -244,6 +249,42 @@ public class DefaultJobManager
                 }
             }
         }
+
+        // we do a sanity check every 12th run
+        final boolean doSanityCheck = (schedulerRuns % 12 == 0);
+        if ( doSanityCheck ) {
+            logger.debug("cleanup: running sanity check");
+            final List<JobEvent> removedEvents = new ArrayList<JobEvent>();
+
+            final Map<String, JobEvent> currentEvents;
+            synchronized (this.allEvents) {
+                currentEvents = new HashMap<String, JobEvent>(this.allEvents);
+            }
+
+            for (final Map.Entry<String, JobEvent> entry : currentEvents.entrySet())
{
+                final JobEvent job = entry.getValue();
+                if (!job.isAlive()) {
+                    synchronized (this.allEvents) {
+                        logger.debug("cleanup: Removing dead job {}", job);
+                        this.allEvents.remove(entry.getKey());
+                    }
+                    removedEvents.add(job);
+                }
+            }
+
+            for(final JobEvent removedJob : removedEvents) {
+                final String topic = (String)removedJob.event.getProperty(JobUtil.PROPERTY_JOB_TOPIC);
+                final List<JobEvent> l;
+                synchronized ( this.allEventsByTopic ) {
+                    l = this.allEventsByTopic.get(topic);
+                }
+                if ( l != null ) {
+                    synchronized ( l ) {
+                        l.remove(removedJob);
+                    }
+                }
+            }
+        }
     }
 
     /**

Modified: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/JobEvent.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/JobEvent.java?rev=1141439&r1=1141438&r2=1141439&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/JobEvent.java
(original)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/JobEvent.java
Thu Jun 30 08:33:44 2011
@@ -44,6 +44,7 @@ public abstract class JobEvent {
     public abstract boolean reschedule();
     public abstract boolean remove();
     public abstract void restart();
+    public abstract boolean isAlive();
 
     @Override
     public int hashCode() {

Modified: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/jcr/JCRJobEvent.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/jcr/JCRJobEvent.java?rev=1141439&r1=1141438&r2=1141439&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/jcr/JCRJobEvent.java
(original)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/jcr/JCRJobEvent.java
Thu Jun 30 08:33:44 2011
@@ -63,4 +63,9 @@ public class JCRJobEvent extends JobEven
     public void restart() {
         this.handler.restart(this);
     }
+
+    @Override
+    public boolean isAlive() {
+        return this.handler.isAlive(this);
+    }
 }
\ No newline at end of file

Modified: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/jcr/PersistenceHandler.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/jcr/PersistenceHandler.java?rev=1141439&r1=1141438&r2=1141439&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/jcr/PersistenceHandler.java
(original)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/jcr/PersistenceHandler.java
Thu Jun 30 08:33:44 2011
@@ -1331,4 +1331,25 @@ public class PersistenceHandler implemen
             }
         }
     }
+
+    /**
+     * Check if the job is still alive = unfinished node in repository
+     */
+    public boolean isAlive(final JCRJobEvent info) {
+        final String path = this.getNodePath(info.uniqueId);
+        synchronized ( this.backgroundLock ) {
+            try {
+                if ( this.backgroundSession.itemExists(path) ) {
+                    final String finishedPath = path + '/' + JCRHelper.NODE_PROPERTY_FINISHED;
+                    if ( !this.backgroundSession.itemExists(finishedPath) ) {
+                        return true;
+                    }
+                }
+            } catch (final RepositoryException re) {
+                // there is nothing we can do
+                this.ignoreException(re);
+            }
+        }
+        return false;
+    }
 }

Modified: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/queues/AbstractJobQueue.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/queues/AbstractJobQueue.java?rev=1141439&r1=1141438&r2=1141439&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/queues/AbstractJobQueue.java
(original)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/queues/AbstractJobQueue.java
Thu Jun 30 08:33:44 2011
@@ -171,6 +171,7 @@ public abstract class AbstractJobQueue
             }
             public boolean remove() { return true; }
             public boolean reschedule() { return false; }
+            public boolean isAlive() { return false; }
             });
 
         this.processsingJobsLists.clear();

Modified: sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/impl/jobs/config/InternalQueueConfigurationTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/impl/jobs/config/InternalQueueConfigurationTest.java?rev=1141439&r1=1141438&r2=1141439&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/impl/jobs/config/InternalQueueConfigurationTest.java
(original)
+++ sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/impl/jobs/config/InternalQueueConfigurationTest.java
Thu Jun 30 08:33:44 2011
@@ -55,6 +55,7 @@ public class InternalQueueConfigurationT
             public void restart() {
                 // dummy
             }
+            public boolean isAlive() { return false; }
         };
     }
     @org.junit.Test public void testMaxParallel() {



Mime
View raw message