[jboss-cvs] JBossAS SVN: r86741 - branches/Branch_5_x/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 08:12:32 EDT 2009


Author: bstansberry at jboss.com
Date: 2009-04-03 08:12:32 -0400 (Fri, 03 Apr 2009)
New Revision: 86741

Modified:
   branches/Branch_5_x/tomcat/src/main/org/jboss/web/tomcat/service/session/ClusteredSessionValve.java
   branches/Branch_5_x/tomcat/src/main/org/jboss/web/tomcat/service/session/JBossCacheManager.java
   branches/Branch_5_x/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: branches/Branch_5_x/tomcat/src/main/org/jboss/web/tomcat/service/session/ClusteredSessionValve.java
===================================================================
--- branches/Branch_5_x/tomcat/src/main/org/jboss/web/tomcat/service/session/ClusteredSessionValve.java	2009-04-03 12:11:27 UTC (rev 86740)
+++ branches/Branch_5_x/tomcat/src/main/org/jboss/web/tomcat/service/session/ClusteredSessionValve.java	2009-04-03 12:12:32 UTC (rev 86741)
@@ -135,7 +135,6 @@
          }
          finally
          {
-            SessionReplicationContext.finishCacheActivity();
             if (startedBatch)
             {
                tm.endBatch();
@@ -201,7 +200,6 @@
          }
          finally
          {
-            SessionReplicationContext.finishCacheActivity();
             if (startedBatch)
             {
                tm.endBatch();

Modified: branches/Branch_5_x/tomcat/src/main/org/jboss/web/tomcat/service/session/JBossCacheManager.java
===================================================================
--- branches/Branch_5_x/tomcat/src/main/org/jboss/web/tomcat/service/session/JBossCacheManager.java	2009-04-03 12:11:27 UTC (rev 86740)
+++ branches/Branch_5_x/tomcat/src/main/org/jboss/web/tomcat/service/session/JBossCacheManager.java	2009-04-03 12:12:32 UTC (rev 86741)
@@ -249,18 +249,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);
 
@@ -402,6 +402,8 @@
       session.setMaxInactiveInterval(this.maxInactiveInterval_);
       session.setValid(true);
 
+      String clearInvalidated = null; // see below
+      
       if (sessionId == null)
       {
           sessionId = this.getNextId();
@@ -416,6 +418,10 @@
               sessionId += "." + this.getJvmRoute();
           }
       }
+      else
+      {
+         clearInvalidated = sessionId;
+      }
 
       session.setId(sessionId); // Setting the id leads to a call to add()
       
@@ -433,6 +439,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;
    }
 
@@ -466,7 +479,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");
@@ -571,17 +584,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);
 
@@ -979,15 +992,20 @@
          
          // Ensure the correct TCL is in place
          // BES 2008/11/27 Why?
-         ContextClassLoaderSwitcher.SwitchContext switcher = null;
+         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);
             
@@ -1256,6 +1274,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)
@@ -1415,6 +1437,10 @@
       {
          log_.error("processExpirationPassivation(): failed with exception: " + ex, ex);
       }
+      finally
+      {
+         SessionInvalidationTracker.resume();
+      }
       
       if (trace_)
       { 
@@ -1554,10 +1580,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();
@@ -1614,7 +1636,6 @@
                {
                   switcher.reset();
                }
-               SessionReplicationContext.finishCacheActivity();
             }
          }
 
@@ -1669,13 +1690,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)
@@ -1704,15 +1718,10 @@
       }
       finally
       {
-         try {
-            if(doTx)
-            {
-               batchingManager.endBatch();
-            }
+         if(doTx)
+         {
+            batchingManager.endBatch();
          }
-         finally {
-            SessionReplicationContext.finishCacheActivity();
-         }
       }
    }
    
@@ -1735,19 +1744,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, 
@@ -1784,18 +1785,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: branches/Branch_5_x/tomcat/src/main/org/jboss/web/tomcat/service/session/SessionReplicationContext.java
===================================================================
--- branches/Branch_5_x/tomcat/src/main/org/jboss/web/tomcat/service/session/SessionReplicationContext.java	2009-04-03 12:11:27 UTC (rev 86740)
+++ branches/Branch_5_x/tomcat/src/main/org/jboss/web/tomcat/service/session/SessionReplicationContext.java	2009-04-03 12:12:32 UTC (rev 86741)
@@ -34,11 +34,10 @@
    private static final SessionReplicationContext EMPTY = new SessionReplicationContext();
    
    private int webappCount;
-   private int activityCount;
+//   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 +63,6 @@
       }
       
       ctx.webappCount++;
-      if (startCacheActivity)
-         ctx.activityCount++;
    }
    
    /**
@@ -91,8 +88,7 @@
             ctx.outerRequest = null;
             ctx.outerResponse = null;
             
-            if (ctx.activityCount < 1)
-               replicationContext.set(null);
+            replicationContext.set(null);
             
             return ctx;
          }
@@ -121,56 +117,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 +258,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