jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1565271 - in /jackrabbit/oak/trunk: oak-core/ oak-core/src/main/java/org/apache/jackrabbit/oak/spi/whiteboard/ oak-core/src/main/java/org/apache/jackrabbit/oak/stats/ oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/ oak-jcr/src/m...
Date Thu, 06 Feb 2014 14:27:52 GMT
Author: mduerig
Date: Thu Feb  6 14:27:51 2014
New Revision: 1565271

URL: http://svn.apache.org/r1565271
Log:
OAK-1337: Implement RepositoryStatistics from Jackrabbit API
OAK-1338: Implement QueryStat from Jackrabbit API
Implement QueryStats and introduce StatisticManager class as central point for managing repository
wide statistics.

Added:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/whiteboard/CompositeRegistration.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/stats/
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/stats/StatisticManager.java
Modified:
    jackrabbit/oak/trunk/oak-core/pom.xml
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/QueryManagerImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/repository/RepositoryImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/SessionContext.java

Modified: jackrabbit/oak/trunk/oak-core/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/pom.xml?rev=1565271&r1=1565270&r2=1565271&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/pom.xml (original)
+++ jackrabbit/oak/trunk/oak-core/pom.xml Thu Feb  6 14:27:51 2014
@@ -45,6 +45,7 @@
               org.apache.jackrabbit.oak,
               org.apache.jackrabbit.oak.api,
               org.apache.jackrabbit.oak.api.jmx,
+              org.apache.jackrabbit.oak.stats,
               org.apache.jackrabbit.oak.kernel,
               org.apache.jackrabbit.oak.util,
               org.apache.jackrabbit.oak.namepath,

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/whiteboard/CompositeRegistration.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/whiteboard/CompositeRegistration.java?rev=1565271&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/whiteboard/CompositeRegistration.java
(added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/whiteboard/CompositeRegistration.java
Thu Feb  6 14:27:51 2014
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.jackrabbit.oak.spi.whiteboard;
+
+/**
+ * A composite of registrations that unregisters all its constituents
+ * upon {@link #unregister()}.
+ */
+public class CompositeRegistration implements Registration {
+    private final Registration[] registrations;
+
+    public CompositeRegistration(Registration... registrations) {
+        this.registrations = registrations;
+    }
+
+    @Override
+    public void unregister() {
+        for (Registration reg : registrations) {
+            reg.unregister();
+        }
+    }
+}

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/stats/StatisticManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/stats/StatisticManager.java?rev=1565271&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/stats/StatisticManager.java
(added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/stats/StatisticManager.java
Thu Feb  6 14:27:51 2014
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.jackrabbit.oak.stats;
+
+import static org.apache.jackrabbit.oak.spi.whiteboard.WhiteboardUtils.registerMBean;
+
+import org.apache.jackrabbit.api.jmx.QueryStatManagerMBean;
+import org.apache.jackrabbit.oak.spi.whiteboard.CompositeRegistration;
+import org.apache.jackrabbit.oak.spi.whiteboard.Whiteboard;
+import org.apache.jackrabbit.stats.QueryStatImpl;
+import org.apache.jackrabbit.stats.jmx.QueryStatManager;
+
+/**
+ * Manager for all repository wide statistics.
+ * @see org.apache.jackrabbit.api.stats.RepositoryStatistics
+ * @see org.apache.jackrabbit.api.stats.QueryStat
+ */
+public class StatisticManager {
+    private final QueryStatImpl queryStat = new QueryStatImpl();
+    private final CompositeRegistration registration;
+
+    /**
+     * Create a new instance of this class registering all repository wide
+     * statistics with the passed {@code whiteboard}.
+     * @param whiteboard   whiteboard for registering the individual statistics with
+     */
+    public StatisticManager(Whiteboard whiteboard) {
+        registration = new CompositeRegistration(
+            registerMBean(whiteboard, QueryStatManagerMBean.class,
+                new QueryStatManager(queryStat), "QueryStats", QueryStatManagerMBean.NAME));
+    }
+
+    /**
+     * Logs the call of each query ran on the repository.
+     * @param language   the query language
+     * @param statement  the query
+     * @param millis     time it took to evaluate the query in milli seconds.
+     * @see org.apache.jackrabbit.stats.QueryStatCore#logQuery(java.lang.String, java.lang.String,
long)
+     */
+    public void logQueryEvaluationTime(String language, String statement, long millis) {
+        queryStat.logQuery(language, statement, millis);
+    }
+
+    /**
+     * Unregister all statistics previously registered with the whiteboard passed
+     * to the constructor.
+     */
+    public void dispose() {
+        registration.unregister();
+    }
+}

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/QueryManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/QueryManagerImpl.java?rev=1565271&r1=1565270&r2=1565271&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/QueryManagerImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/QueryManagerImpl.java
Thu Feb  6 14:27:51 2014
@@ -39,9 +39,9 @@ import org.apache.jackrabbit.JcrConstant
 import org.apache.jackrabbit.oak.api.PropertyValue;
 import org.apache.jackrabbit.oak.api.QueryEngine;
 import org.apache.jackrabbit.oak.api.Result;
-import org.apache.jackrabbit.oak.jcr.session.SessionContext;
 import org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate;
 import org.apache.jackrabbit.oak.jcr.query.qom.QueryObjectModelFactoryImpl;
+import org.apache.jackrabbit.oak.jcr.session.SessionContext;
 import org.apache.jackrabbit.oak.plugins.memory.PropertyStates;
 import org.apache.jackrabbit.oak.spi.query.PropertyValues;
 
@@ -120,9 +120,12 @@ public class QueryManagerImpl implements
             long limit, long offset, HashMap<String, Value> bindVariableMap) throws
RepositoryException {
         try {
             Map<String, PropertyValue> bindMap = convertMap(bindVariableMap);
+            long t = System.nanoTime();
             Result r = queryEngine.executeQuery(
                     statement, language, limit, offset, bindMap,
                     sessionContext.getSessionLocalMappings());
+            sessionContext.getStatisticManager()
+                    .logQueryEvaluationTime(language, statement, (System.nanoTime() - t)
/ 1000000);
             return new QueryResultImpl(sessionContext, r);
         } catch (IllegalArgumentException e) {
             throw new InvalidQueryException(e);

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/repository/RepositoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/repository/RepositoryImpl.java?rev=1565271&r1=1565270&r2=1565271&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/repository/RepositoryImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/repository/RepositoryImpl.java
Thu Feb  6 14:27:51 2014
@@ -46,6 +46,7 @@ import org.apache.jackrabbit.commons.Sim
 import org.apache.jackrabbit.oak.api.ContentRepository;
 import org.apache.jackrabbit.oak.api.ContentSession;
 import org.apache.jackrabbit.oak.api.jmx.SessionMBean;
+import org.apache.jackrabbit.oak.stats.StatisticManager;
 import org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate;
 import org.apache.jackrabbit.oak.jcr.session.RefreshStrategy;
 import org.apache.jackrabbit.oak.jcr.session.RefreshStrategy.LogOnce;
@@ -87,6 +88,7 @@ public class RepositoryImpl implements J
     private final ThreadLocal<Long> threadSaveCount;
     private final ListeningScheduledExecutorService scheduledExecutor =
             MoreExecutors.listeningDecorator(Executors.newSingleThreadScheduledExecutor());
+    private final StatisticManager statisticManager;
 
     public RepositoryImpl(@Nonnull ContentRepository contentRepository,
                           @Nonnull Whiteboard whiteboard,
@@ -96,6 +98,7 @@ public class RepositoryImpl implements J
         this.securityProvider = checkNotNull(securityProvider);
         this.threadSaveCount = new ThreadLocal<Long>();
         this.descriptors = determineDescriptors();
+        this.statisticManager = new StatisticManager(whiteboard);
     }
 
     //---------------------------------------------------------< Repository >---
@@ -222,7 +225,7 @@ public class RepositoryImpl implements J
             ContentSession contentSession = contentRepository.login(credentials, workspaceName);
             SessionDelegate sessionDelegate = createSessionDelegate(refreshStrategy, contentSession);
             SessionContext context = createSessionContext(
-                    securityProvider, createAttributes(refreshInterval), sessionDelegate);
+                    statisticManager, securityProvider, createAttributes(refreshInterval),
sessionDelegate);
             return context.getSession();
         } catch (LoginException e) {
             throw new javax.jcr.LoginException(e.getMessage(), e);
@@ -261,6 +264,7 @@ public class RepositoryImpl implements J
 
     @Override
     public void shutdown() {
+        statisticManager.dispose();
         scheduledExecutor.shutdown();
     }
 
@@ -274,9 +278,9 @@ public class RepositoryImpl implements J
      * @return session context
      */
     protected SessionContext createSessionContext(
-            SecurityProvider securityProvider, Map<String, Object> attributes,
-            SessionDelegate delegate) {
-        return new SessionContext(this, securityProvider, whiteboard, attributes, delegate);
+            StatisticManager statisticManager, SecurityProvider securityProvider,
+            Map<String, Object> attributes, SessionDelegate delegate) {
+        return new SessionContext(this, statisticManager, securityProvider, whiteboard, attributes,
delegate);
     }
 
     /**

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/SessionContext.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/SessionContext.java?rev=1565271&r1=1565270&r2=1565271&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/SessionContext.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/SessionContext.java
Thu Feb  6 14:27:51 2014
@@ -42,6 +42,7 @@ import org.apache.jackrabbit.api.securit
 import org.apache.jackrabbit.api.security.authorization.PrivilegeManager;
 import org.apache.jackrabbit.api.security.principal.PrincipalManager;
 import org.apache.jackrabbit.api.security.user.UserManager;
+import org.apache.jackrabbit.oak.stats.StatisticManager;
 import org.apache.jackrabbit.oak.jcr.delegate.AccessControlManagerDelegator;
 import org.apache.jackrabbit.oak.jcr.delegate.JackrabbitAccessControlManagerDelegator;
 import org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate;
@@ -79,6 +80,7 @@ public class SessionContext implements N
     private static final Logger log = LoggerFactory.getLogger(SessionContext.class);
 
     private final Repository repository;
+    private final StatisticManager statisticManager;
     private final SecurityProvider securityProvider;
     private final Whiteboard whiteboard;
     private final Map<String, Object> attributes;
@@ -106,10 +108,11 @@ public class SessionContext implements N
     private final Set<String> sessionScopedLocks = newHashSet();
 
     public SessionContext(
-            @Nonnull Repository repository, @Nonnull SecurityProvider securityProvider,
-            @Nonnull Whiteboard whiteboard, @Nonnull Map<String, Object> attributes,
-            @Nonnull final SessionDelegate delegate) {
+            @Nonnull Repository repository, @Nonnull StatisticManager statisticManager,
+            @Nonnull SecurityProvider securityProvider, @Nonnull Whiteboard whiteboard,
+            @Nonnull Map<String, Object> attributes, @Nonnull final SessionDelegate
delegate) {
         this.repository = checkNotNull(repository);
+        this.statisticManager = statisticManager;
         this.securityProvider = checkNotNull(securityProvider);
         this.whiteboard = checkNotNull(whiteboard);
         this.attributes = checkNotNull(attributes);
@@ -165,6 +168,11 @@ public class SessionContext implements N
     }
 
     @Nonnull
+    public StatisticManager getStatisticManager() {
+        return statisticManager;
+    }
+
+    @Nonnull
     public Repository getRepository() {
         return repository;
     }
@@ -178,6 +186,7 @@ public class SessionContext implements N
         return namespaces;
     }
 
+    @Override
     @Nonnull
     public Map<String, String> getSessionLocalMappings() {
         return namespaces.getSessionLocalMappings();



Mime
View raw message