tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From p...@apache.org
Subject svn commit: r693378 - in /tomcat/trunk: java/org/apache/catalina/ha/session/JvmRouteBinderValve.java webapps/docs/changelog.xml
Date Tue, 09 Sep 2008 06:18:33 GMT
Author: pero
Date: Mon Sep  8 23:18:32 2008
New Revision: 693378

URL: http://svn.apache.org/viewvc?rev=693378&view=rev
Log:
Handle session suffix rewrite with parallel requests from same client

Modified:
    tomcat/trunk/java/org/apache/catalina/ha/session/JvmRouteBinderValve.java
    tomcat/trunk/webapps/docs/changelog.xml

Modified: tomcat/trunk/java/org/apache/catalina/ha/session/JvmRouteBinderValve.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/ha/session/JvmRouteBinderValve.java?rev=693378&r1=693377&r2=693378&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/ha/session/JvmRouteBinderValve.java (original)
+++ tomcat/trunk/java/org/apache/catalina/ha/session/JvmRouteBinderValve.java Mon Sep  8 23:18:32
2008
@@ -35,6 +35,7 @@
 import org.apache.catalina.ha.ClusterManager;
 import org.apache.catalina.ha.ClusterMessage;
 import org.apache.catalina.ha.ClusterValve;
+import org.apache.catalina.ha.session.DeltaSession;
 import org.apache.catalina.connector.Request;
 import org.apache.catalina.connector.Response;
 import org.apache.catalina.session.ManagerBase;
@@ -217,8 +218,8 @@
      * @param response current response
      */
     protected void handlePossibleTurnover(Request request, Response response) {
-        Session session = request.getSessionInternal(false);
-        if (session != null) {
+        String sessionID = request.getRequestedSessionId() ;
+        if (sessionID != null) {
             long t1 = System.currentTimeMillis();
             String jvmRoute = getLocalJvmRoute(request);
             if (jvmRoute == null) {
@@ -226,7 +227,7 @@
                     log.debug(sm.getString("jvmRoute.missingJvmRouteAttribute"));
                 return;
             }
-            handleJvmRoute( request, response,session.getIdInternal(), jvmRoute);
+            handleJvmRoute( request, response, sessionID, jvmRoute);
             if (log.isDebugEnabled()) {
                 long t2 = System.currentTimeMillis();
                 long time = t2 - t1;
@@ -306,23 +307,32 @@
                 log.debug(sm.getString("jvmRoute.failover", requestJvmRoute,
                         localJvmRoute, sessionId));
             }
-            // OK - turnover the session ?
-            String newSessionID = sessionId.substring(0, index) + "."
-                    + localJvmRoute;
             Session catalinaSession = null;
             try {
                 catalinaSession = getManager(request).findSession(sessionId);
             } catch (IOException e) {
                 // Hups!
             }
+            String id = sessionId.substring(0, index);
+            String newSessionID = id + "." + localJvmRoute;
+            // OK - turnover the session and inform other cluster nodes
             if (catalinaSession != null) {
                 changeSessionID(request, response, sessionId, newSessionID,
                         catalinaSession);
                 numberOfSessions++;
             } else {
-                if (log.isDebugEnabled()) {
-                    log.debug(sm.getString("jvmRoute.cannotFindSession",
-                            sessionId));
+                try {
+                    catalinaSession = getManager(request).findSession(newSessionID);
+                } catch (IOException e) {
+                    // Hups!
+                }
+                if (catalinaSession != null) {
+                    // session is rewrite at other request, rewrite this also
+                    changeRequestSessionID(request, response, sessionId, newSessionID);
+                } else {
+                    if (log.isDebugEnabled()) {
+                        log.debug(sm.getString("jvmRoute.cannotFindSession",sessionId));
+                    }
                 }
             }
         }
@@ -344,11 +354,36 @@
             Response response, String sessionId, String newSessionID, Session catalinaSession)
{
         lifecycle.fireLifecycleEvent("Before session migration",
                 catalinaSession);
-        request.setRequestedSessionId(newSessionID);
+        // FIXME: setId trigger session Listener, but only chance to registiert manager with
correct id!
         catalinaSession.setId(newSessionID);
+        // FIXME: Why we remove change data from other running request?
+        // setId also trigger resetDeltaRequest!!
         if (catalinaSession instanceof DeltaSession)
             ((DeltaSession) catalinaSession).resetDeltaRequest();
-        if(request.isRequestedSessionIdFromCookie()) setNewSessionCookie(request, response,newSessionID);
+        changeRequestSessionID(request, response, sessionId, newSessionID);
+        // now sending the change to all other clusternode!
+        ClusterManager manager = (ClusterManager)catalinaSession.getManager();
+        sendSessionIDClusterBackup(manager,request,sessionId, newSessionID);
+        lifecycle.fireLifecycleEvent("After session migration", catalinaSession);
+        if (log.isDebugEnabled()) {
+            log.debug(sm.getString("jvmRoute.changeSession", sessionId,
+                    newSessionID));
+        }   
+    }
+
+    /**
+     * Change Request Session id
+     * @param request current request
+     * @param response current response
+     * @param sessionId
+     *            original session id
+     * @param newSessionID
+     *            new session id for node migration
+     */
+    protected void changeRequestSessionID(Request request, Response response, String sessionId,
String newSessionID) {
+        request.setRequestedSessionId(newSessionID);
+        if(request.isRequestedSessionIdFromCookie())
+            setNewSessionCookie(request, response,newSessionID);
         // set orginal sessionid at request, to allow application detect the
         // change
         if (sessionIdAttribute != null && !"".equals(sessionIdAttribute)) {
@@ -357,17 +392,8 @@
             }
             request.setAttribute(sessionIdAttribute, sessionId);
         }
-        // now sending the change to all other clusternode!
-        ClusterManager manager = (ClusterManager)catalinaSession.getManager();
-        sendSessionIDClusterBackup(manager,request,sessionId, newSessionID);
-        lifecycle
-                .fireLifecycleEvent("After session migration", catalinaSession);
-        if (log.isDebugEnabled()) {
-            log.debug(sm.getString("jvmRoute.changeSession", sessionId,
-                    newSessionID));
-        }
     }
-
+    
     /**
      * Send the changed Sessionid to all clusternodes.
      * 

Modified: tomcat/trunk/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=693378&r1=693377&r2=693378&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Mon Sep  8 23:18:32 2008
@@ -40,6 +40,9 @@
   </subsection>
   <subsection name="ha">
     <changelog>
+      <fix>
+        Fix that JvmrouteBinderValve can rewrite session suffix with parallel requests from
same client (pero)
+      </fix>
      <fix><rev>671650</rev><br/><bug>45279</bug><br/>
        Close multicast socket when calling close
       </fix> 



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message