jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r1527959 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk: MongoMK.java util/LoggingDocumentStoreWrapper.java
Date Tue, 01 Oct 2013 07:46:34 GMT
Author: mreutegg
Date: Tue Oct  1 07:46:34 2013
New Revision: 1527959

URL: http://svn.apache.org/r1527959
Log:
OAK-1057: Configurable DocumentStore logging wrapper

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoMK.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/util/LoggingDocumentStoreWrapper.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoMK.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoMK.java?rev=1527959&r1=1527958&r2=1527959&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoMK.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoMK.java
Tue Oct  1 07:46:34 2013
@@ -54,6 +54,7 @@ import org.apache.jackrabbit.oak.commons
 import org.apache.jackrabbit.oak.plugins.mongomk.Node.Children;
 import org.apache.jackrabbit.oak.plugins.mongomk.Revision.RevisionComparator;
 import org.apache.jackrabbit.oak.plugins.mongomk.blob.MongoBlobStore;
+import org.apache.jackrabbit.oak.plugins.mongomk.util.LoggingDocumentStoreWrapper;
 import org.apache.jackrabbit.oak.plugins.mongomk.util.TimingDocumentStoreWrapper;
 import org.apache.jackrabbit.oak.plugins.mongomk.util.Utils;
 import org.slf4j.Logger;
@@ -248,6 +249,9 @@ public class MongoMK implements MicroKer
         if (builder.getTiming()) {
             s = new TimingDocumentStoreWrapper(s);
         }
+        if (builder.getLogging()) {
+            s = new LoggingDocumentStoreWrapper(s);
+        }
         this.store = s;
         this.blobStore = builder.getBlobStore();
         int cid = builder.getClusterId();
@@ -1458,6 +1462,7 @@ public class MongoMK implements MicroKer
         private int clusterId  = Integer.getInteger("oak.mongoMK.clusterId", 0);
         private int asyncDelay = 1000;
         private boolean timing;
+        private boolean logging;
         private Weigher<String, CacheValue> weigher = new EmpiricalWeigher();
         private long nodeCacheSize;
         private long childrenCacheSize;
@@ -1500,6 +1505,15 @@ public class MongoMK implements MicroKer
             return timing;
         }
 
+        public Builder setLogging(boolean logging) {
+            this.logging = logging;
+            return this;
+        }
+
+        public boolean getLogging() {
+            return logging;
+        }
+
         /**
          * Set the document store to use. By default an in-memory store is used.
          * 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/util/LoggingDocumentStoreWrapper.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/util/LoggingDocumentStoreWrapper.java?rev=1527959&r1=1527958&r2=1527959&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/util/LoggingDocumentStoreWrapper.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/util/LoggingDocumentStoreWrapper.java
Tue Oct  1 07:46:34 2013
@@ -17,6 +17,7 @@
 package org.apache.jackrabbit.oak.plugins.mongomk.util;
 
 import java.util.List;
+import java.util.concurrent.Callable;
 
 import javax.annotation.Nonnull;
 
@@ -45,10 +46,16 @@ public class LoggingDocumentStoreWrapper
     }
 
     @Override
-    public <T extends Document> T find(Collection<T> collection, String key)
{
+    public <T extends Document> T find(final Collection<T> collection,
+                                       final String key) {
         try {
             logMethod("find", collection, key);
-            return logResult(store.find(collection, key));
+            return logResult(new Callable<T>() {
+                @Override
+                public T call() throws Exception {
+                    return store.find(collection, key);
+                }
+            });
         } catch (Exception e) {
             logException(e);
             throw convert(e);
@@ -56,10 +63,17 @@ public class LoggingDocumentStoreWrapper
     }
 
     @Override
-    public <T extends Document> T find(Collection<T> collection, String key,
int maxCacheAge) {
+    public <T extends Document> T find(final Collection<T> collection,
+                                       final String key,
+                                       final int maxCacheAge) {
         try {
             logMethod("find", collection, key, maxCacheAge);
-            return logResult(store.find(collection, key, maxCacheAge));
+            return logResult(new Callable<T>() {
+                @Override
+                public T call() throws Exception {
+                    return store.find(collection, key, maxCacheAge);
+                }
+            });
         } catch (Exception e) {
             logException(e);
             throw convert(e);
@@ -68,13 +82,18 @@ public class LoggingDocumentStoreWrapper
 
     @Nonnull
     @Override
-    public <T extends Document> List<T> query(Collection<T> collection,
-                                String fromKey,
-                                String toKey,
-                                int limit) {
+    public <T extends Document> List<T> query(final Collection<T> collection,
+                                final String fromKey,
+                                final String toKey,
+                                final int limit) {
         try {
             logMethod("query", collection, fromKey, toKey, limit);
-            return logResult(store.query(collection, fromKey, toKey, limit));
+            return logResult(new Callable<List<T>>() {
+                @Override
+                public List<T> call() throws Exception {
+                    return store.query(collection, fromKey, toKey, limit);
+                }
+            });
         } catch (Exception e) {
             logException(e);
             throw convert(e);
@@ -83,15 +102,20 @@ public class LoggingDocumentStoreWrapper
     
     @Override
     @Nonnull
-    public <T extends Document> List<T> query(Collection<T> collection,
-                                String fromKey,
-                                String toKey,
-                                String indexedProperty,
-                                long startValue,
-                                int limit) {
+    public <T extends Document> List<T> query(final Collection<T> collection,
+                                final String fromKey,
+                                final String toKey,
+                                final String indexedProperty,
+                                final long startValue,
+                                final int limit) {
         try {
             logMethod("query", collection, fromKey, toKey, indexedProperty, startValue, limit);
-            return logResult(store.query(collection, fromKey, toKey, indexedProperty, startValue,
limit));
+            return logResult(new Callable<List<T>>() {
+                @Override
+                public List<T> call() throws Exception {
+                    return store.query(collection, fromKey, toKey, indexedProperty, startValue,
limit);
+                }
+            });
         } catch (Exception e) {
             logException(e);
             throw convert(e);
@@ -110,10 +134,16 @@ public class LoggingDocumentStoreWrapper
     }
 
     @Override
-    public <T extends Document> boolean create(Collection<T> collection, List<UpdateOp>
updateOps) {
+    public <T extends Document> boolean create(final Collection<T> collection,
+                                               final List<UpdateOp> updateOps) {
         try {
             logMethod("create", collection, updateOps);
-            return logResult(store.create(collection, updateOps));
+            return logResult(new Callable<Boolean>() {
+                @Override
+                public Boolean call() throws Exception {
+                    return store.create(collection, updateOps);
+                }
+            });
         } catch (Exception e) {
             logException(e);
             throw convert(e);
@@ -122,11 +152,17 @@ public class LoggingDocumentStoreWrapper
 
     @Nonnull
     @Override
-    public <T extends Document> T createOrUpdate(Collection<T> collection, UpdateOp
update)
+    public <T extends Document> T createOrUpdate(final Collection<T> collection,
+                                                 final UpdateOp update)
             throws MicroKernelException {
         try {
             logMethod("createOrUpdate", collection, update);
-            return logResult(store.createOrUpdate(collection, update));
+            return logResult(new Callable<T>() {
+                @Override
+                public T call() throws Exception {
+                    return store.createOrUpdate(collection, update);
+                }
+            });
         } catch (Exception e) {
             logException(e);
             throw convert(e);
@@ -134,11 +170,17 @@ public class LoggingDocumentStoreWrapper
     }
 
     @Override
-    public <T extends Document> T findAndUpdate(Collection<T> collection, UpdateOp
update)
+    public <T extends Document> T findAndUpdate(final Collection<T> collection,
+                                                final UpdateOp update)
             throws MicroKernelException {
         try {
             logMethod("findAndUpdate", collection, update);
-            return logResult(store.findAndUpdate(collection, update));
+            return logResult(new Callable<T>() {
+                @Override
+                public T call() throws Exception {
+                    return store.findAndUpdate(collection, update);
+                }
+            });
         } catch (Exception e) {
             logException(e);
             throw convert(e);
@@ -179,10 +221,16 @@ public class LoggingDocumentStoreWrapper
     }
 
     @Override
-    public <T extends Document> boolean isCached(Collection<T> collection, String
key) {
+    public <T extends Document> boolean isCached(final Collection<T> collection,
+                                                 final String key) {
         try {
             logMethod("isCached", collection, key);
-            return logResult(store.isCached(collection, key));
+            return logResult(new Callable<Boolean>() {
+                @Override
+                public Boolean call() throws Exception {
+                    return store.isCached(collection, key);
+                }
+            });
         } catch (Exception e) {
             logException(e);
             throw convert(e);
@@ -223,8 +271,11 @@ public class LoggingDocumentStoreWrapper
         log("// exception: " + e.toString());
     }
 
-    private static <T> T logResult(T result) {
-        log("// " + quote(result));
+    private static <T> T logResult(Callable<T> callable) throws Exception {
+        long time = System.nanoTime();
+        T result = callable.call();
+        time = System.nanoTime() - time;
+        log("// " + (time / 1000) + " us\t" + quote(result));
         return result;
     }
 



Mime
View raw message