Author: stillalex
Date: Wed Sep 12 07:41:18 2018
New Revision: 1840630
URL: http://svn.apache.org/viewvc?rev=1840630&view=rev
Log:
OAK-6402 SessionStats log access warning
Modified:
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/RefreshStrategy.java
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=1840630&r1=1840629&r2=1840630&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
Wed Sep 12 07:41:18 2018
@@ -22,7 +22,6 @@ import static java.util.Collections.sing
import static
org.apache.jackrabbit.oak.spi.whiteboard.WhiteboardUtils.registerMBean;
import java.io.Closeable;
-import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.ScheduledExecutorService;
@@ -40,7 +39,6 @@ import javax.jcr.SimpleCredentials;
import javax.jcr.Value;
import javax.security.auth.login.LoginException;
-import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableMap;
import org.apache.commons.io.IOUtils;
@@ -63,7 +61,6 @@ import org.apache.jackrabbit.oak.spi.gc.
import org.apache.jackrabbit.oak.spi.mount.MountInfoProvider;
import org.apache.jackrabbit.oak.spi.security.SecurityProvider;
import org.apache.jackrabbit.oak.spi.whiteboard.Registration;
-import org.apache.jackrabbit.oak.spi.whiteboard.Tracker;
import org.apache.jackrabbit.oak.spi.whiteboard.Whiteboard;
import org.apache.jackrabbit.oak.spi.whiteboard.WhiteboardUtils;
import org.apache.jackrabbit.oak.stats.Clock;
@@ -282,18 +279,12 @@ public class RepositoryImpl implements J
throw new RepositoryException("Duplicate attribute '" +
REFRESH_INTERVAL + "'.");
}
boolean relaxedLocking = getRelaxedLocking(attributes);
-
- RefreshPredicate predicate = new RefreshPredicate();
- RefreshStrategy refreshStrategy = refreshInterval == null
- ? new RefreshStrategy.ConditionalRefreshStrategy(new
RefreshStrategy.LogOnce(60), predicate)
- : new RefreshStrategy.Timed(refreshInterval);
ContentSession contentSession =
contentRepository.login(credentials, workspaceName);
- SessionDelegate sessionDelegate =
createSessionDelegate(refreshStrategy, contentSession);
+ SessionDelegate sessionDelegate =
createSessionDelegate(refreshInterval, contentSession);
SessionContext context = createSessionContext(
statisticManager, securityProvider,
createAttributes(refreshInterval, relaxedLocking),
sessionDelegate, observationQueueLength,
commitRateLimiter);
- predicate.setSessionContext(context);
return context.getSession();
} catch (LoginException e) {
throw new javax.jcr.LoginException(e.getMessage(), e);
@@ -301,11 +292,16 @@ public class RepositoryImpl implements J
}
private SessionDelegate createSessionDelegate(
- RefreshStrategy refreshStrategy,
+ Long refreshInterval,
ContentSession contentSession) {
+ RefreshStrategy refreshStrategy;
final RefreshOnGC refreshOnGC = new RefreshOnGC(gcMonitor);
- refreshStrategy = Composite.create(refreshStrategy, refreshOnGC);
+ if (refreshInterval == null) {
+ refreshStrategy = refreshOnGC;
+ } else {
+ refreshStrategy = Composite.create(new
RefreshStrategy.Timed(refreshInterval), refreshOnGC);
+ }
return new SessionDelegate(
contentSession, securityProvider, refreshStrategy,
@@ -517,26 +513,6 @@ public class RepositoryImpl implements J
}
}
- /**
- * Predicate which ensures that refresh strategy is invoked only
- * if there is no event listeners registered with the session
- */
- private static class RefreshPredicate implements Predicate<Long>{
- private SessionContext sessionContext;
-
- @Override
- public boolean apply(@Nullable Long input) {
- if (sessionContext == null){
- return true;
- }
- return !sessionContext.hasEventListeners();
- }
-
- public void setSessionContext(SessionContext sessionContext) {
- this.sessionContext = sessionContext;
- }
- }
-
private static class RegistrationTask implements Runnable {
private final SessionStats sessionStats;
private final Whiteboard whiteboard;
Modified:
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/RefreshStrategy.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/RefreshStrategy.java?rev=1840630&r1=1840629&r2=1840630&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/RefreshStrategy.java
(original)
+++
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/RefreshStrategy.java
Wed Sep 12 07:41:18 2018
@@ -20,15 +20,9 @@ package org.apache.jackrabbit.oak.jcr.se
import static com.google.common.collect.Lists.newArrayList;
import static java.util.Arrays.asList;
-import static java.util.concurrent.TimeUnit.MINUTES;
-import static java.util.concurrent.TimeUnit.SECONDS;
import java.util.ArrayList;
-import com.google.common.base.Predicate;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
/**
* Implementations of this interface determine whether a session needs
* to be refreshed before the next session operation is performed. This is
@@ -37,7 +31,6 @@ import org.slf4j.LoggerFactory;
*
* @see Composite
* @see Timed
- * @see LogOnce
*/
public interface RefreshStrategy {
@@ -155,83 +148,4 @@ public interface RefreshStrategy {
return "Refresh every " + interval + " seconds";
}
}
-
- /**
- * This refresh strategy never refreshed the session but logs
- * a warning if a session has been idle for more than a given time.
- *
- * TODO replace logging with JMX monitoring. See OAK-941
- */
- class LogOnce extends Timed {
-
- private static final Logger log =
- LoggerFactory.getLogger(RefreshStrategy.class);
-
- private final Exception initStackTrace =
- new Exception("The session was created here:");
-
- private boolean warnIfIdle = true;
-
- /**
- * @param interval Interval in seconds after which a warning is
logged if there was no
- * activity.
- */
- public LogOnce(long interval) {
- super(interval);
- }
-
- /**
- * Log once
- * @param secondsSinceLastAccess seconds since last access
- * @return {@code false}
- */
- @Override
- public boolean needsRefresh(long secondsSinceLastAccess) {
- if (super.needsRefresh(secondsSinceLastAccess) && warnIfIdle) {
- log.warn("This session has been idle for "
- + MINUTES.convert(secondsSinceLastAccess, SECONDS)
- + " minutes and might be out of date. " +
- "Consider using a fresh session or explicitly refresh
the session.",
- initStackTrace);
- }
- return false;
- }
-
- @Override
- public void refreshed() {
- warnIfIdle = false;
- }
-
- @Override
- public String toString() {
- return "Never refresh but log warning after more than " + interval
+ " seconds of inactivity";
- }
- }
-
- /**
- * This strategy conditionally invokes the delegated strategy based on the
passed predicate
- */
- class ConditionalRefreshStrategy implements RefreshStrategy {
- private final RefreshStrategy delegate;
- private final Predicate<Long> condition;
-
- public ConditionalRefreshStrategy(RefreshStrategy delegate,
Predicate<Long> condition) {
- this.delegate = delegate;
- this.condition = condition;
- }
-
- @Override
- public boolean needsRefresh(long secondsSinceLastAccess) {
- if (condition.apply(secondsSinceLastAccess)){
- return delegate.needsRefresh(secondsSinceLastAccess);
- }
- return false;
- }
-
- @Override
- public void refreshed() {
- delegate.refreshed();
- }
- }
-
}