jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r1308743 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core: cluster/ journal/ persistence/bundle/ state/ value/
Date Tue, 03 Apr 2012 08:25:21 GMT
Author: mreutegg
Date: Tue Apr  3 08:25:20 2012
New Revision: 1308743

URL: http://svn.apache.org/viewvc?rev=1308743&view=rev
Log:
JCR-3275: Audit log

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/journal/AppendRecord.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/ReadRecord.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/Record.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/AbstractBundlePersistenceManager.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ChangeLog.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInDataStore.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?rev=1308743&r1=1308742&r2=1308743&view=diff
==============================================================================
--- 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
Tue Apr  3 08:25:20 2012
@@ -80,7 +80,12 @@ public class ClusterNode implements Runn
     private static final int STOPPED = 2;
 
     /**
-     * Logger.
+     * Audit logger.
+     */
+    private static Logger auditLogger = LoggerFactory.getLogger("org.apache.jackrabbit.core.audit");
+
+    /**
+     * Default Logger.
      */
     private static Logger log = LoggerFactory.getLogger(ClusterNode.class);
 
@@ -120,6 +125,11 @@ public class ClusterNode implements Runn
     private final Mutex syncLock = new Mutex();
 
     /**
+     * Update counter, used in displaying the number of updates in audit log.
+     */
+    private final AtomicInteger updateCount = new AtomicInteger();
+
+    /**
      * Latch used to communicate a stop request to the synchronization thread.
      */
     private final Latch stopLatch = new Latch();
@@ -573,6 +583,11 @@ public class ClusterNode implements Runn
         private static final String ATTRIBUTE_RECORD = "record";
 
         /**
+         * Attribute name used to store the size of the update.
+         */
+        private static final String ATTRIBUTE_UPDATE_SIZE = "updateSize";
+
+        /**
          * Workspace name.
          */
         private final String workspace;
@@ -660,9 +675,19 @@ public class ClusterNode implements Runn
                 return;
             }
             try {
-                record.update();
-                setRevision(record.getRevision());
-                log.debug("revision {} {}", record.getRevision(), path);
+                long journalUpdateSize = record.update();
+
+                long recordRevision = record.getRevision();
+                setRevision(recordRevision);
+
+                log.debug("Stored record '{}' to Journal ({})", recordRevision, journalUpdateSize);
+
+                long updateSize = (Long)update.getAttribute(ATTRIBUTE_UPDATE_SIZE);
+                updateCount.compareAndSet(Integer.MAX_VALUE, 0);
+
+                auditLogger.info("[{}] {} {} ({})", new Object[]{updateCount.incrementAndGet(),

+                        record.getRevision(), path, updateSize});
+
             } catch (JournalException e) {
                 String msg = "Unable to commit log entry.";
                 log.error(msg, e);

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/AppendRecord.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/AppendRecord.java?rev=1308743&r1=1308742&r2=1308743&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/AppendRecord.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/AppendRecord.java
Tue Apr  3 08:25:20 2012
@@ -253,7 +253,7 @@ public class AppendRecord extends Abstra
     /**
      * {@inheritDoc}
      */
-    public void update() throws JournalException {
+    public long update() throws JournalException {
         boolean succeeded = false;
 
         try {
@@ -265,6 +265,7 @@ public class AppendRecord extends Abstra
             try {
                 journal.append(this, in, length);
                 succeeded = true;
+                return length;
             } finally {
                 try {
                     in.close();

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/ReadRecord.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/ReadRecord.java?rev=1308743&r1=1308742&r2=1308743&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/ReadRecord.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/ReadRecord.java
Tue Apr  3 08:25:20 2012
@@ -271,7 +271,7 @@ public class ReadRecord extends Abstract
         throw unsupported();
     }
 
-    public void update() throws JournalException {
+    public long update() throws JournalException {
         throw unsupported();
     }
 

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/Record.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/Record.java?rev=1308743&r1=1308742&r2=1308743&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/Record.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/Record.java
Tue Apr  3 08:25:20 2012
@@ -277,10 +277,11 @@ public interface Record {
      * Update the changes made to an appended record. This will also update
      * this record's revision.
      *
+     * @returns The update size in bytes.
      * @throws JournalException if this record has not been appended,
      *                          or if another error occurs
      */
-    void update() throws JournalException;
+    long update() throws JournalException;
 
     /**
      * Cancel the changes made to an appended record.

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/AbstractBundlePersistenceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/AbstractBundlePersistenceManager.java?rev=1308743&r1=1308742&r2=1308743&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/AbstractBundlePersistenceManager.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/AbstractBundlePersistenceManager.java
Tue Apr  3 08:25:20 2012
@@ -93,6 +93,9 @@ import org.slf4j.LoggerFactory;
 public abstract class AbstractBundlePersistenceManager implements
     PersistenceManager, CachingPersistenceManager, IterablePersistenceManager, CacheAccessListener,
ConsistencyChecker {
 
+    /** the audit logger */
+    private static Logger auditLogger = LoggerFactory.getLogger("org.apache.jackrabbit.core.audit");
+
     /** the default logger */
     private static Logger log = LoggerFactory.getLogger(AbstractBundlePersistenceManager.class);
 
@@ -683,9 +686,12 @@ public abstract class AbstractBundlePers
         }
 
         // now store all modified bundles
+        long updateSize = 0;
         for (NodePropBundle bundle : modified.values()) {
             putBundle(bundle);
+            updateSize += bundle.getSize();
         }
+        changeLog.setUpdateSize(updateSize);
 
         // store the refs
         for (NodeReferences refs : changeLog.modifiedRefs()) {
@@ -768,6 +774,7 @@ public abstract class AbstractBundlePers
         long time = System.nanoTime();
         log.debug("Storing bundle {}", bundle.getId());
         storeBundle(bundle);
+        auditLogger.debug("Stored bundle '{}' to PM ({})", bundle.getId(), bundle.getSize());
         writeDuration.addAndGet(System.nanoTime() - time);
         writeCounter.incrementAndGet();
 

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ChangeLog.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ChangeLog.java?rev=1308743&r1=1308742&r2=1308743&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ChangeLog.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ChangeLog.java
Tue Apr  3 08:25:20 2012
@@ -53,6 +53,8 @@ public class ChangeLog {
     @SuppressWarnings("unchecked")
     private final Map<NodeId, NodeReferences> modifiedRefs = (Map<NodeId, NodeReferences>)
new LinkedMap();
 
+    private long updateSize;
+
     /**
      * Checks whether this change log contains any changes. This method is
      * used to avoid extra work on updates that contain no changes.
@@ -369,6 +371,24 @@ public class ChangeLog {
     }
 
     /**
+     * Returns the update size of the change log.
+     * 
+     * @return The update size.
+     */
+    public long getUpdateSize() {
+        return updateSize;
+    }
+
+    /**
+     * Sets the update size of the change log.
+     * 
+     * @param updateSize The update size.
+     */
+    public void setUpdateSize(long updateSize) {
+        this.updateSize = updateSize;
+    }
+
+    /**
      * Returns a string representation of this change log for diagnostic
      * purposes.
      *

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?rev=1308743&r1=1308742&r2=1308743&view=diff
==============================================================================
--- 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
Tue Apr  3 08:25:20 2012
@@ -493,6 +493,11 @@ public class SharedItemStateManager
     class Update implements org.apache.jackrabbit.core.cluster.Update {
 
         /**
+         * Attribute name used to store the size of the update.
+         */
+        private static final String ATTRIBUTE_UPDATE_SIZE = "updateSize";
+
+        /**
          * Local change log.
          */
         private final ChangeLog local;
@@ -768,6 +773,7 @@ public class SharedItemStateManager
                 /* Store items in the underlying persistence manager */
                 long t0 = System.currentTimeMillis();
                 persistMgr.store(shared);
+                setAttribute(ATTRIBUTE_UPDATE_SIZE, shared.getUpdateSize());
                 succeeded = true;
                 if (log.isDebugEnabled()) {
                     long t1 = System.currentTimeMillis();
@@ -805,8 +811,10 @@ public class SharedItemStateManager
                 // always gets released, even if a post-store() exception
                 // is thrown from the code above. See also JCR-2272.
                 String path = events.getSession().getUserID()
-                        + "@" + events.getCommonPath();
+                        + "@" + events.getSession().getWorkspace().getName()
+                        + ":" + events.getCommonPath();
                 eventChannel.updateCommitted(this, path);
+                setAttribute(ATTRIBUTE_UPDATE_SIZE, null);
 
                 if (writeLock != null) {
                     // exception occurred before downgrading lock

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInDataStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInDataStore.java?rev=1308743&r1=1308742&r2=1308743&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInDataStore.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInDataStore.java
Tue Apr  3 08:25:20 2012
@@ -45,6 +45,8 @@ class BLOBInDataStore extends BLOBFileVa
      */
     private static Logger log = LoggerFactory.getLogger(BLOBInDataStore.class);
 
+    /** the audit logger */
+    private static Logger auditLogger = LoggerFactory.getLogger("org.apache.jackrabbit.core.audit");
 
     private BLOBInDataStore(DataStore store, DataIdentifier identifier) {
         assert store != null;
@@ -118,6 +120,9 @@ class BLOBInDataStore extends BLOBFileVa
     static BLOBInDataStore getInstance(DataStore store, InputStream in) throws DataStoreException
{
         DataRecord rec = store.addRecord(in);
         DataIdentifier identifier = rec.getIdentifier();
+        if (auditLogger.isDebugEnabled()) {
+            auditLogger.debug("Stored {} to DataStore ({})", identifier, rec.getLength());
+        }
         return new BLOBInDataStore(store, identifier);
     }
 



Mime
View raw message