jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r1387021 - /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/AbstractJournal.java
Date Tue, 18 Sep 2012 07:31:59 GMT
Author: mreutegg
Date: Tue Sep 18 07:31:59 2012
New Revision: 1387021

URL: http://svn.apache.org/viewvc?rev=1387021&view=rev
Log:
JCR-3427: JCR-3138 may cause resource starvation

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/AbstractJournal.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/AbstractJournal.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/AbstractJournal.java?rev=1387021&r1=1387020&r2=1387021&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/AbstractJournal.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/AbstractJournal.java
Tue Sep 18 07:31:59 2012
@@ -181,16 +181,30 @@ public abstract class AbstractJournal im
      * {@inheritDoc}
      */
     public void sync() throws JournalException {
-        if (internalVersionManager != null) {
-            VersioningLock.ReadLock lock =
-                internalVersionManager.acquireReadLock();
-            try {
+        for (;;) {
+            if (internalVersionManager != null) {
+                VersioningLock.ReadLock lock =
+                        internalVersionManager.acquireReadLock();
+                try {
+                    internalSync();
+                } finally {
+                    lock.release();
+                }
+            } else {
                 internalSync();
-            } finally {
-                lock.release();
             }
-        } else {
-            internalSync();
+            if (syncAgainOnNewRecords()) {
+                // sync again if there are more records available
+                RecordIterator it = getRecords(getMinimalRevision());
+                try {
+                    if (it.hasNext()) {
+                        continue;
+                    }
+                } finally {
+                    it.close();
+                }
+            }
+            break;
         }
     }
 
@@ -215,46 +229,37 @@ public abstract class AbstractJournal im
      * @throws JournalException if an error occurs
      */
     protected void doSync(long startRevision) throws JournalException {
-        for (;;) {
-            RecordIterator iterator = getRecords(startRevision);
-            long stopRevision = Long.MIN_VALUE;
-    
-            try {
-                while (iterator.hasNext()) {
-                    Record record = iterator.nextRecord();
-                    if (record.getJournalId().equals(id)) {
-                        log.info("Record with revision '" + record.getRevision()
-                                + "' created by this journal, skipped.");
-                    } else {
-                        RecordConsumer consumer = getConsumer(record.getProducerId());
-                        if (consumer != null) {
-                            try {
-                                consumer.consume(record);
-                            } catch (IllegalStateException e) {
-                                log.error("Could not synchronize to revision: " + record.getRevision()
+ " due illegal state of RecordConsumer.");
-                                return;
-                            }
+        RecordIterator iterator = getRecords(startRevision);
+        long stopRevision = Long.MIN_VALUE;
+
+        try {
+            while (iterator.hasNext()) {
+                Record record = iterator.nextRecord();
+                if (record.getJournalId().equals(id)) {
+                    log.info("Record with revision '" + record.getRevision()
+                            + "' created by this journal, skipped.");
+                } else {
+                    RecordConsumer consumer = getConsumer(record.getProducerId());
+                    if (consumer != null) {
+                        try {
+                            consumer.consume(record);
+                        } catch (IllegalStateException e) {
+                            log.error("Could not synchronize to revision: " + record.getRevision()
+ " due illegal state of RecordConsumer.");
+                            return;
                         }
                     }
-                    stopRevision = record.getRevision();
                 }
-            } finally {
-                iterator.close();
+                stopRevision = record.getRevision();
             }
-    
-            if (stopRevision > 0) {
-                for (RecordConsumer consumer : consumers.values()) {
-                    consumer.setRevision(stopRevision);
-                }
-                log.info("Synchronized to revision: " + stopRevision);
+        } finally {
+            iterator.close();
+        }
 
-                if (syncAgainOnNewRecords()) {
-                    // changes detected, sync again
-                    startRevision = stopRevision;
-                    continue;
-                }
+        if (stopRevision > 0) {
+            for (RecordConsumer consumer : consumers.values()) {
+                consumer.setRevision(stopRevision);
             }
-            break;
+            log.info("Synchronized to revision: " + stopRevision);
         }
     }
     



Mime
View raw message