[jboss-cvs] JBossAS SVN: r86746 - trunk/tomcat/src/main/org/jboss/web/tomcat/service/session.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Apr 3 09:22:30 EDT 2009
Author: bstansberry at jboss.com
Date: 2009-04-03 09:22:29 -0400 (Fri, 03 Apr 2009)
New Revision: 86746
Modified:
trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/ClusteredSessionValve.java
trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/JBossCacheManager.java
trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/SessionReplicationContext.java
Log:
[JBAS-6733] Avoid re-reading expired sessions from distributed cache
[JBAS-6038] Get rid of SessionReplicationContext.start/finishCacheActivity
Modified: trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/ClusteredSessionValve.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/ClusteredSessionValve.java 2009-04-03 13:21:52 UTC (rev 86745)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/ClusteredSessionValve.java 2009-04-03 13:22:29 UTC (rev 86746)
@@ -135,7 +135,6 @@
}
finally
{
- SessionReplicationContext.finishCacheActivity();
if (startedBatch)
{
tm.endBatch();
@@ -201,7 +200,6 @@
}
finally
{
- SessionReplicationContext.finishCacheActivity();
if (startedBatch)
{
tm.endBatch();
Modified: trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/JBossCacheManager.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/JBossCacheManager.java 2009-04-03 13:21:52 UTC (rev 86745)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/JBossCacheManager.java 2009-04-03 13:22:29 UTC (rev 86746)
@@ -238,18 +238,18 @@
}
try {
- // Ignore any cache notifications that our own work generates
- SessionReplicationContext.startCacheActivity();
clusterSess.removeMyselfLocal();
}
finally
{
- SessionReplicationContext.finishCacheActivity();
-
// We don't want to replicate this session at the end
// of the request; the removal process took care of that
SessionReplicationContext.sessionExpired(clusterSess, realId, snapshotManager_);
+ // Track this session to prevent reincarnation by this request
+ // from the distributed cache
+ SessionInvalidationTracker.sessionInvalidated(realId, this);
+
sessions_.remove(realId);
stats_.removeStats(realId);
@@ -391,6 +391,8 @@
session.setMaxInactiveInterval(this.maxInactiveInterval_);
session.setValid(true);
+ String clearInvalidated = null; // see below
+
if (sessionId == null)
{
sessionId = this.getNextId();
@@ -405,6 +407,10 @@
sessionId += "." + this.getJvmRoute();
}
}
+ else
+ {
+ clearInvalidated = sessionId;
+ }
session.setId(sessionId); // Setting the id leads to a call to add()
@@ -422,6 +428,13 @@
// Add this session to the set of those potentially needing replication
SessionReplicationContext.bindSession(session, snapshotManager_);
+ if (clearInvalidated != null)
+ {
+ // We no longer need to track any earlier session w/ same id
+ // invalidated by this thread
+ SessionInvalidationTracker.clearInvalidatedSession(clearInvalidated, this);
+ }
+
return session;
}
@@ -455,7 +468,7 @@
// session from the other nodes to be gravitated, thus resuscitating
// the session.
if (session == null
- && !SessionReplicationContext.isSessionBoundAndExpired(realId, snapshotManager_))
+ && !SessionInvalidationTracker.isSessionInvalidated(realId, this))
{
if (trace_)
log_.trace("Checking for session " + realId + " in the distributed cache");
@@ -560,17 +573,17 @@
}
try {
- // Ignore any cache notifications that our own work generates
- SessionReplicationContext.startCacheActivity();
clusterSess.removeMyself();
}
finally {
- SessionReplicationContext.finishCacheActivity();
-
// We don't want to replicate this session at the end
// of the request; the removal process took care of that
SessionReplicationContext.sessionExpired(clusterSess, realId, snapshotManager_);
+ // Track this session to prevent reincarnation by this request
+ // from the distributed cache
+ SessionInvalidationTracker.sessionInvalidated(realId, this);
+
sessions_.remove(realId);
stats_.removeStats(realId);
@@ -939,12 +952,17 @@
ContextClassLoaderSwitcher.SwitchContext switcher = null;
try
{
+ // Don't track this invalidation is if it were from a request
+ SessionInvalidationTracker.suspend();
+
switcher = getContextClassLoaderSwitcher().getSwitchContext();
switcher.setClassLoader(tcl_);
session.expire(notify, localCall, localOnly, ClusteredSessionNotificationCause.INVALIDATE);
}
finally
{
+ SessionInvalidationTracker.resume();
+
// Remove any stats for this session
stats_.removeStats(realId);
@@ -1213,6 +1231,10 @@
try
{
+ // Don't track sessions invalidated via this method as if they
+ // were going to be re-requested by the thread
+ SessionInvalidationTracker.suspend();
+
// First, handle the sessions we are actively managing
Session sessions[] = findLocalSessions();
for (int i = 0; i < sessions.length; ++i)
@@ -1372,6 +1394,10 @@
{
log_.error("processExpirationPassivation(): failed with exception: " + ex, ex);
}
+ finally
+ {
+ SessionInvalidationTracker.resume();
+ }
if (trace_)
{
@@ -1511,10 +1537,6 @@
doTx = true;
}
- // Ignore cache notifications we may generate for this
- // session if data gravitation occurs.
- SessionReplicationContext.startCacheActivity();
-
// Tomcat calls Manager.findSession before setting the tccl,
// so we need to do it :(
switcher = getContextClassLoaderSwitcher().getSwitchContext();
@@ -1571,7 +1593,6 @@
{
switcher.reset();
}
- SessionReplicationContext.finishCacheActivity();
}
}
@@ -1626,13 +1647,6 @@
doTx = true;
}
- // Tell the proxy to ignore cache notifications we are about
- // to generate for this session. We have to do this
- // at this level because we don't want to resume handling
- // notifications until any compensating changes resulting
- // from a tx rollback are done.
- SessionReplicationContext.startCacheActivity();
-
session.processSessionReplication();
}
catch (Exception ex)
@@ -1661,15 +1675,10 @@
}
finally
{
- try {
- if(doTx)
- {
- batchingManager.endBatch();
- }
+ if(doTx)
+ {
+ batchingManager.endBatch();
}
- finally {
- SessionReplicationContext.finishCacheActivity();
- }
}
}
@@ -1692,19 +1701,11 @@
{
log_.trace("Passivating session with id: " + realId);
}
-
- try {
- // Tell the proxy to ignore cache notifications we are about
- // to generate for this session.
- SessionReplicationContext.startCacheActivity();
- session.notifyWillPassivate(ClusteredSessionNotificationCause.PASSIVATION);
- proxy_.evictSession(realId);
- sessionPassivated();
- }
- finally {
- SessionReplicationContext.finishCacheActivity();
- }
+ session.notifyWillPassivate(ClusteredSessionNotificationCause.PASSIVATION);
+ proxy_.evictSession(realId);
+ sessionPassivated();
+
// Put the session in the unloadedSessions map. This will
// expose the session to regular invalidation.
Object obj = unloadedSessions_.put(realId,
@@ -1741,18 +1742,9 @@
log_.trace("Passivating session with id: " + realId);
}
- try {
- // Tell the proxy to ignore cache notifications we are about
- // to generate for this session.
- SessionReplicationContext.startCacheActivity();
- proxy_.evictSession(realId, osu.owner);
- osu.passivated = true;
- sessionPassivated();
- }
- finally {
- SessionReplicationContext.finishCacheActivity();
- }
-
+ proxy_.evictSession(realId, osu.owner);
+ osu.passivated = true;
+ sessionPassivated();
}
private void sessionPassivated()
Modified: trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/SessionReplicationContext.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/SessionReplicationContext.java 2009-04-03 13:21:52 UTC (rev 86745)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/SessionReplicationContext.java 2009-04-03 13:22:29 UTC (rev 86746)
@@ -34,11 +34,9 @@
private static final SessionReplicationContext EMPTY = new SessionReplicationContext();
private int webappCount;
- private int activityCount;
private SnapshotManager soleManager;
private ClusteredSession soleSession;
private Map<ClusteredSession, SnapshotManager> crossCtxSessions;
- private Map<SnapshotManager, String> expiredSessions;
private Request outerRequest;
private Response outerResponse;
@@ -64,8 +62,6 @@
}
ctx.webappCount++;
- if (startCacheActivity)
- ctx.activityCount++;
}
/**
@@ -91,8 +87,7 @@
ctx.outerRequest = null;
ctx.outerResponse = null;
- if (ctx.activityCount < 1)
- replicationContext.set(null);
+ replicationContext.set(null);
return ctx;
}
@@ -121,56 +116,54 @@
SessionReplicationContext ctx = getCurrentContext();
if (ctx != null && ctx.webappCount > 0)
{
- ctx.addExpiredSession(session, manager);
+ ctx.sessionExpired(session, manager);
}
}
+ /**
+ * Does nothing
+ *
+ * @return <code>false</code>
+ *
+ * @deprecated Always returns false; will be removed in AS 6
+ */
+ @Deprecated
public static boolean isSessionBoundAndExpired(String realId, SnapshotManager manager)
{
- boolean result = false;
- SessionReplicationContext ctx = getCurrentContext();
- if (ctx != null)
- {
- result = ctx.isSessionExpired(realId, manager);
- }
- return result;
+ return false;
}
/**
- * Marks the current thread as actively processing the given session.
- * If the thread has already been so marked, increases a counter
- * so a subsequent call to finishLocalActivity does not remove
- * the association (allowing nested calls).
+ * Does nothing
+ *
+ * @deprecated Does nothing; will be removed in AS 6
*/
+ @Deprecated
public static void startCacheActivity()
{
- SessionReplicationContext ctx = getCurrentContext();
- if (ctx == null)
- {
- ctx = new SessionReplicationContext();
- replicationContext.set(ctx);
- }
-
- ctx.activityCount++;
+ // no-op
}
/**
- * Marks the completion of activity on a given session. Should be called
- * once for each invocation of {@link #startCacheActivity()}.
+ * Does nothing
+ *
+ * @deprecated Does nothing; will be removed in AS 6
*/
+ @Deprecated
public static void finishCacheActivity()
{
- SessionReplicationContext ctx = getCurrentContext();
- if (ctx != null)
- {
- ctx.activityCount--;
- if (ctx.activityCount < 1 && ctx.webappCount < 1)
- {
- replicationContext.set(null);
- }
- }
+ // no-op
}
+ /**
+ * Returns whether there is a SessionReplicationContext associated with
+ * the current thread.
+ *
+ * @return <code>true</code> if there is a context associated with the thread
+ *
+ * @deprecated Will be removed in AS 6
+ */
+ @Deprecated
public static boolean isLocallyActive()
{
return getCurrentContext() != null;
@@ -264,38 +257,17 @@
}
}
- private void addExpiredSession(ClusteredSession session, SnapshotManager manager)
+ private void sessionExpired(ClusteredSession session, SnapshotManager manager)
{
- boolean store = manager.equals(soleManager);
- if (store)
+ if (manager.equals(soleManager))
{
soleManager = null;
soleSession = null;
}
else if (crossCtxSessions != null)
{
- // Only store the session if it was previously in our map
- store = (crossCtxSessions.remove(session) != null);
+ crossCtxSessions.remove(session);
}
-
- if (store)
- {
- if (this.expiredSessions == null)
- {
- expiredSessions = new HashMap<SnapshotManager, String>();
- }
- expiredSessions.put(manager, session.getRealId());
- }
}
- private boolean isSessionExpired(String realId, SnapshotManager manager)
- {
- boolean result = false;
- if (expiredSessions != null)
- {
- result = realId.equals(expiredSessions.get(manager));
- }
- return result;
- }
-
}
More information about the jboss-cvs-commits
mailing list