jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dpfis...@apache.org
Subject svn commit: r486054 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core: cluster/ClusterNode.java cluster/FileJournal.java cluster/Journal.java cluster/UpdateEventChannel.java state/SharedItemStateManager.java
Date Tue, 12 Dec 2006 07:52:31 GMT
Author: dpfister
Date: Mon Dec 11 23:52:31 2006
New Revision: 486054

URL: http://svn.apache.org/viewvc?view=rev&rev=486054
Log:
JCR-623 - Clustering
+ Synchronize journal before updating
+ Leave journal in valid state, when error occurs

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterNode.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/FileJournal.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/Journal.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/UpdateEventChannel.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterNode.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterNode.java?view=diff&rev=486054&r1=486053&r2=486054
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterNode.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterNode.java
Mon Dec 11 23:52:31 2006
@@ -217,17 +217,24 @@
      * @param owner lock owner
      */
     private void locked(String workspace, NodeId nodeId, boolean deep, String owner) {
+        boolean succeeded = false;
+
         try {
             journal.begin(workspace);
             journal.log(nodeId, deep, owner);
             journal.prepare();
             journal.commit();
+            succeeded = true;
         } catch (JournalException e) {
             String msg = "Unable to create log entry: " + e.getMessage();
             log.error(msg);
         } catch (Throwable e) {
             String msg = "Unexpected error while creating log entry.";
             log.error(msg, e);
+        } finally {
+            if (!succeeded) {
+                journal.cancel();
+            }
         }
     }
 
@@ -238,17 +245,24 @@
      * @param nodeId node id
      */
     private void unlocked(String workspace, NodeId nodeId) {
+        boolean succeeded = false;
+
         try {
             journal.begin(workspace);
             journal.log(nodeId);
             journal.prepare();
             journal.commit();
+            succeeded = true;
         } catch (JournalException e) {
             String msg = "Unable to create log entry: " + e.getMessage();
             log.error(msg);
         } catch (Throwable e) {
             String msg = "Unexpected error while creating log entry.";
             log.error(msg, e);
+        } finally {
+            if (!succeeded) {
+                journal.cancel();
+            }
         }
     }
 
@@ -308,46 +322,54 @@
 
     /**
      * {@inheritDoc}
+     */
+    public void updateCreated() {
+        try {
+            sync();
+        } catch (ClusterException e) {
+            String msg = "Unable to sync with journal: " + e.getMessage();
+            log.error(msg);
+        } catch (Throwable e) {
+            String msg = "Unexpected error while creating log entry.";
+            log.error(msg, e);
+        }
+    }
+
+    /**
+     * {@inheritDoc}
      * <p/>
-     * Invoked when an update has been created inside versioning. Delegate
+     * Invoked when an update has been prepared inside versioning. Delegate
      * to common method with <code>null</code> workspace.
      */
-    public void updateCreated(ChangeLog changes, EventStateCollection esc) {
-        updateCreated(null, changes, esc);
+    public void updatePrepared(ChangeLog changes, EventStateCollection esc) {
+        updatePrepared(null, changes, esc);
     }
 
     /**
-     * Called when an a update operation has been created.
+     * Called when an a update operation has been prepared.
      *
      * @param workspace workspace to use when writing journal entry
      * @param changes changes
      * @param esc events as they will be delivered on success
      */
-    private void updateCreated(String workspace, ChangeLog changes, EventStateCollection
esc) {
+    private void updatePrepared(String workspace, ChangeLog changes, EventStateCollection
esc) {
+        boolean succeeded = false;
+
         try {
             journal.begin(workspace);
             journal.log(changes, esc);
-        } catch (JournalException e) {
-            String msg = "Unable to create log entry: " + e.getMessage();
-            log.error(msg);
-        } catch (Throwable e) {
-            String msg = "Unexpected error while creating log entry.";
-            log.error(msg, e);
-        }
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public void updatePrepared() {
-        try {
             journal.prepare();
+            succeeded = true;
         } catch (JournalException e) {
             String msg = "Unable to create log entry: " + e.getMessage();
             log.error(msg);
         } catch (Throwable e) {
             String msg = "Unexpected error while preparing log entry.";
             log.error(msg, e);
+        } finally {
+            if (!succeeded) {
+                journal.cancel();
+            }
         }
     }
 
@@ -370,15 +392,7 @@
      * {@inheritDoc}
      */
     public void updateCancelled() {
-        try {
-            journal.cancel();
-        } catch (JournalException e) {
-            String msg = "Unable to create log entry: " + e.getMessage();
-            log.error(msg);
-        } catch (Throwable e) {
-            String msg = "Unexpected error while cancelling log entry.";
-            log.error(msg, e);
-        }
+        journal.cancel();
     }
 
     /**
@@ -396,17 +410,24 @@
      * {@inheritDoc}
      */
     public void remapped(String oldPrefix, String newPrefix, String uri) {
+        boolean succeeded = false;
+
         try {
             journal.begin(null);
             journal.log(oldPrefix, newPrefix, uri);
             journal.prepare();
             journal.commit();
+            succeeded = true;
         } catch (JournalException e) {
             String msg = "Unable to create log entry: " + e.getMessage();
             log.error(msg);
         } catch (Throwable e) {
             String msg = "Unexpected error while creating log entry.";
             log.error(msg, e);
+        } finally {
+            if (!succeeded) {
+                journal.cancel();
+            }
         }
     }
 
@@ -420,17 +441,24 @@
      * {@inheritDoc}
      */
     public void registered(Collection ntDefs) {
+        boolean succeeded = false;
+
         try {
             journal.begin(null);
             journal.log(ntDefs);
             journal.prepare();
             journal.commit();
+            succeeded = true;
         } catch (JournalException e) {
             String msg = "Unable to create log entry: " + e.getMessage();
             log.error(msg);
         } catch (Throwable e) {
             String msg = "Unexpected error while creating log entry.";
             log.error(msg, e);
+        } finally {
+            if (!succeeded) {
+                journal.cancel();
+            }
         }
     }
 
@@ -464,15 +492,15 @@
         /**
          * {@inheritDoc}
          */
-        public void updateCreated(ChangeLog changes, EventStateCollection esc) {
-            ClusterNode.this.updateCreated(workspace, changes, esc);
+        public void updateCreated() {
+            ClusterNode.this.updateCreated();
         }
 
         /**
          * {@inheritDoc}
          */
-        public void updatePrepared() {
-            ClusterNode.this.updatePrepared();
+        public void updatePrepared(ChangeLog changes, EventStateCollection esc) {
+            ClusterNode.this.updatePrepared(workspace, changes, esc);
         }
 
         /**

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/FileJournal.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/FileJournal.java?view=diff&rev=486054&r1=486053&r2=486054
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/FileJournal.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/FileJournal.java
Mon Dec 11 23:52:31 2006
@@ -670,6 +670,7 @@
             String msg = "Unable to close journal log " + tempLog + ": " + e.getMessage();
             throw new JournalException(msg);
         } finally {
+            out = null;
             globalRevision.unlock();
             writeMutex.release();
         }
@@ -678,16 +679,19 @@
     /**
      * {@inheritDoc}
      */
-    public void cancel() throws JournalException {
-        try {
-            out.close();
-            tempLog.delete();
-        } catch (IOException e) {
-            String msg = "Unable to close journal log " + tempLog + ": " + e.getMessage();
-            log.warn(msg);
-        } finally {
-            globalRevision.unlock();
-            writeMutex.release();
+    public void cancel() {
+        if (out != null) {
+            try {
+                out.close();
+                tempLog.delete();
+            } catch (IOException e) {
+                String msg = "Unable to close journal log " + tempLog + ": " + e.getMessage();
+                log.warn(msg);
+            } finally {
+                out = null;
+                globalRevision.unlock();
+                writeMutex.release();
+            }
         }
     }
 

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/Journal.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/Journal.java?view=diff&rev=486054&r1=486053&r2=486054
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/Journal.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/Journal.java
Mon Dec 11 23:52:31 2006
@@ -117,8 +117,6 @@
 
     /**
      * End this update operation and discards changes made to the journal.
-     *
-     * @throws JournalException if an error occurs
      */
-    public void cancel() throws JournalException;
+    public void cancel();
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/UpdateEventChannel.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/UpdateEventChannel.java?view=diff&rev=486054&r1=486053&r2=486054
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/UpdateEventChannel.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/UpdateEventChannel.java
Mon Dec 11 23:52:31 2006
@@ -26,16 +26,16 @@
 
     /**
      * Called when an a update operation has been created.
-     *
-     * @param changes changes
-     * @param esc events as they will be delivered on success
      */
-    public void updateCreated(ChangeLog changes, EventStateCollection esc);
+    public void updateCreated();
 
     /**
      * Called when an a update operation has been prepared.
+     *
+     * @param changes changes
+     * @param esc events as they will be delivered on success
      */
-    public void updatePrepared();
+    public void updatePrepared(ChangeLog changes, EventStateCollection esc);
 
     /**
      * Called when an a update operation has been committed.

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java?view=diff&rev=486054&r1=486053&r2=486054
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
Mon Dec 11 23:52:31 2006
@@ -518,7 +518,12 @@
 
             virtualNodeReferences = new List[virtualProviders.length];
 
+            /* let listener know about change */
+            if (eventChannel != null) {
+                eventChannel.updateCreated();
+            }
             acquireWriteLock();
+
             holdingWriteLock = true;
 
             boolean succeeded = false;
@@ -639,11 +644,9 @@
 
                 /* let listener know about change */
                 if (eventChannel != null) {
-                    eventChannel.updateCreated(local, events);
+                    eventChannel.updatePrepared(local, events);
                 }
 
-                //todo check whether local states are now stale...
-
                 /* Push all changes from the local items to the shared items */
                 local.push();
 
@@ -667,11 +670,6 @@
             boolean succeeded = false;
 
             try {
-                /* let listener know about preparation */
-                if (eventChannel != null) {
-                    eventChannel.updatePrepared();
-                }
-
                 /* Store items in the underlying persistence manager */
                 long t0 = System.currentTimeMillis();
                 persistMgr.store(shared);
@@ -831,7 +829,9 @@
                 state = cache.retrieve(state.getId());
                 if (state != null) {
                     try {
-                        state.copy(loadItemState(state.getId()));
+                        ItemState currentState = loadItemState(state.getId());
+                        state.copy(currentState);
+                        state.setModCount(currentState.getModCount());
                         shared.modified(state);
                     } catch (ItemStateException e) {
                         String msg = "Unable to retrieve state: " + state.getId();



Mime
View raw message