jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aasoj j <aas....@gmail.com>
Subject Patch to limit number of updates while synchronization
Date Tue, 02 Feb 2010 08:19:09 GMT
Hi,

We have been using Jackrabbit in our web application for a while now. In
cluster deployment, we face synchronization issues when the number of
revisions to be synced is very high. To fix this we decided to limit the
number of revisions returned from the getRecords method of DatabaseJournal.
We also modified the doSync method of Abstract journal, it now loops till
some records are returned from getRecords. The following patch solves our
problem. Please let me know if you foresee any other issues with this.
Thanks in advance.


Index: src/main/java/org/apache/jackrabbit/core/journal/DatabaseJournal.java
===================================================================
--- src/main/java/org/apache/jackrabbit/core/journal/DatabaseJournal.java
(revision
905538)
+++ src/main/java/org/apache/jackrabbit/core/journal/DatabaseJournal.java
(working
copy)
@@ -911,7 +911,7 @@
     protected void buildSQLStatements() {
         selectRevisionsStmtSQL =
             "select REVISION_ID, JOURNAL_ID, PRODUCER_ID, REVISION_DATA
from "
-            + schemaObjectPrefix + "JOURNAL where REVISION_ID > ? order by
REVISION_ID";
+            + schemaObjectPrefix + "JOURNAL where REVISION_ID > ? order by
REVISION_ID *limit 100*";
         updateGlobalStmtSQL =
             "update " + schemaObjectPrefix + "GLOBAL_REVISION"
             + " set REVISION_ID = REVISION_ID + 1";
Index: src/main/java/org/apache/jackrabbit/core/journal/AbstractJournal.java
===================================================================
--- src/main/java/org/apache/jackrabbit/core/journal/AbstractJournal.java
(revision
905538)
+++ src/main/java/org/apache/jackrabbit/core/journal/AbstractJournal.java
(working
copy)
@@ -198,40 +198,44 @@
      * @throws JournalException if an error occurs
      */
     protected void doSync(long startRevision) throws JournalException {
-        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;
+        do {
+            RecordIterator iterator = getRecords(startRevision);
+            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();
                 }
-                stopRevision = record.getRevision();
+            } finally {
+                iterator.close();
             }
-        } finally {
-            iterator.close();
-        }
-
-        if (stopRevision > 0) {
-            Iterator iter = consumers.values().iterator();
-            while (iter.hasNext()) {
-                RecordConsumer consumer = (RecordConsumer) iter.next();
-                consumer.setRevision(stopRevision);
+
+            if (stopRevision > 0) {
+                Iterator iter = consumers.values().iterator();
+                while (iter.hasNext()) {
+                    RecordConsumer consumer = (RecordConsumer) iter.next();
+                    consumer.setRevision(stopRevision);
+                }
+                log.info("Synchronized to revision: " + stopRevision);
+                startRevision = stopRevision;
             }
-            log.info("Synchronized to revision: " + stopRevision);
-        }
+        } while (stopRevision > 0);
     }

     /**

Regards
aasoj

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message