You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by rj...@apache.org on 2009/09/08 11:35:14 UTC
svn commit: r812415 - in /tomcat/sandbox/tomcat-oacc/trunk:
docs/changelog.xml
src/share/org/apache/catalina/cluster/session/JvmRouteBinderValve.java
Author: rjung
Date: Tue Sep 8 09:35:14 2009
New Revision: 812415
URL: http://svn.apache.org/viewvc?rev=812415&view=rev
Log:
Port r769428 from TC5.5.x resp. r750895 from TC 6.0.x.
Backport: Handle session suffix rewrite at JvmRouteBinderValve with parallel requests from same client.
Modified:
tomcat/sandbox/tomcat-oacc/trunk/docs/changelog.xml
tomcat/sandbox/tomcat-oacc/trunk/src/share/org/apache/catalina/cluster/session/JvmRouteBinderValve.java
Modified: tomcat/sandbox/tomcat-oacc/trunk/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/sandbox/tomcat-oacc/trunk/docs/changelog.xml?rev=812415&r1=812414&r2=812415&view=diff
==============================================================================
--- tomcat/sandbox/tomcat-oacc/trunk/docs/changelog.xml (original)
+++ tomcat/sandbox/tomcat-oacc/trunk/docs/changelog.xml Tue Sep 8 09:35:14 2009
@@ -33,6 +33,11 @@
<subsection name="Cluster">
<changelog>
<fix>
+ Handle situation session ID rewriting on fail-over with parallel requests
+ from the same client.
+ Port from Tomcat 5.5. (rjung)
+ </fix>
+ <fix>
<bug>46717</bug>: Hard to reproduce thread safety issue with
session expiration.
Port from Tomcat 5.5. (rjung)
Modified: tomcat/sandbox/tomcat-oacc/trunk/src/share/org/apache/catalina/cluster/session/JvmRouteBinderValve.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/tomcat-oacc/trunk/src/share/org/apache/catalina/cluster/session/JvmRouteBinderValve.java?rev=812415&r1=812414&r2=812415&view=diff
==============================================================================
--- tomcat/sandbox/tomcat-oacc/trunk/src/share/org/apache/catalina/cluster/session/JvmRouteBinderValve.java (original)
+++ tomcat/sandbox/tomcat-oacc/trunk/src/share/org/apache/catalina/cluster/session/JvmRouteBinderValve.java Tue Sep 8 09:35:14 2009
@@ -35,6 +35,7 @@
import org.apache.catalina.cluster.ClusterManager;
import org.apache.catalina.cluster.ClusterMessage;
import org.apache.catalina.cluster.ClusterValve;
+import org.apache.catalina.cluster.session.DeltaSession;
import org.apache.catalina.connector.Request;
import org.apache.catalina.connector.Response;
import org.apache.catalina.session.ManagerBase;
@@ -219,8 +220,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 = 0 ;
if (log.isDebugEnabled()) {
t1 = System.currentTimeMillis();
@@ -231,7 +232,7 @@
log.warn(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;
@@ -311,23 +312,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));
+ }
}
}
}
@@ -349,10 +359,34 @@
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();
+ 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
@@ -363,15 +397,6 @@
}
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));
- }
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org