hi Rainer,

DeltaManager needs to replicate changed attributes even if session
gets invalidated. Otherwise session listeners will not see the right
data on the secondary nodes.

This is an interesting use case indeed. The fact that we would replicate 
changes on an invalidated session sounds awkward.
I will have to take a look when I have some more brain capacity

Filip



On 09/23/2009 06:18 AM, Rainer Jung wrote:
Hi Filip,

I think the below needs some kind of port to the BackupManager.

Ideas?

Regards,

Rainer

On 23.09.2009 13:28, rj...@apache.org wrote:
Author: rjung
Date: Wed Sep 23 11:28:14 2009
New Revision: 818062

URL: http://svn.apache.org/viewvc?rev=818062&view=rev
Log:
DeltaManager needs to replicate changed attributes even if session
gets invalidated. Otherwise session listeners will not see the right
data on the secondary nodes.

Port of r818061 from TC 5.5.x.

Modified:
     tomcat/trunk/java/org/apache/catalina/ha/session/DeltaManager.java
     tomcat/trunk/java/org/apache/catalina/ha/session/DeltaSession.java

Modified: tomcat/trunk/java/org/apache/catalina/ha/session/DeltaManager.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/ha/session/DeltaManager.java?rev=818062&r1=818061&r2=818062&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/ha/session/DeltaManager.java 
(original)
+++ tomcat/trunk/java/org/apache/catalina/ha/session/DeltaManager.java Wed Sep 
23 11:28:14 2009
@@ -1108,6 +1108,25 @@
       * @return a SessionMessage to be sent,
       */
      public ClusterMessage requestCompleted(String sessionId) {
+         return requestCompleted(sessionId, false);
+     }
+
+     /**
+      * When the request has been completed, the replication valve will notify
+      * the manager, and the manager will decide whether any replication is
+      * needed or not. If there is a need for replication, the manager will
+      * create a session message and that will be replicated. The cluster
+      * determines where it gets sent.
+      *
+      * Session expiration also calls this method, but with expires == true.
+      *
+      * @param sessionId -
+      *            the sessionId that just completed.
+      * @param expires -
+      *            whether this method has been called during session 
expiration
+      * @return a SessionMessage to be sent,
+      */
+     public ClusterMessage requestCompleted(String sessionId, boolean expires) 
{
          DeltaSession session = null;
          try {
              session = (DeltaSession) findSession(sessionId);
@@ -1129,7 +1148,7 @@
                  }
              }
              if(!isDeltaRequest) {
-                if(!session.isPrimarySession()) {
+                if(!expires&&  !session.isPrimarySession()) {
                      counterSend_EVT_SESSION_ACCESSED++;
                      msg = new SessionMessageImpl(getName(),
                                                   
SessionMessage.EVT_SESSION_ACCESSED,
@@ -1145,9 +1164,10 @@
                      
log.debug(sm.getString("deltaManager.createMessage.delta",getName(), 
sessionId));
                  }
              }
-            session.setPrimarySession(true);
+            if (!expires)
+                session.setPrimarySession(true);
              //check to see if we need to send out an access message
-            if ((msg == null)) {
+            if (!expires&&  (msg == null)) {
                  long replDelta = System.currentTimeMillis() - 
session.getLastTimeReplicated();
                  if (replDelta>  (getMaxInactiveInterval() * 1000)) {
                      counterSend_EVT_SESSION_ACCESSED++;

Modified: tomcat/trunk/java/org/apache/catalina/ha/session/DeltaSession.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/ha/session/DeltaSession.java?rev=818062&r1=818061&r2=818062&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/ha/session/DeltaSession.java 
(original)
+++ tomcat/trunk/java/org/apache/catalina/ha/session/DeltaSession.java Wed Sep 
23 11:28:14 2009
@@ -38,7 +38,9 @@
  import org.apache.catalina.Manager;
  import org.apache.catalina.SessionListener;
  import org.apache.catalina.ha.ClusterManager;
+import org.apache.catalina.ha.CatalinaCluster;
  import org.apache.catalina.ha.ClusterSession;
+import org.apache.catalina.ha.ClusterMessage;
  import org.apache.catalina.realm.GenericPrincipal;
  import org.apache.catalina.session.StandardSession;
  import org.apache.catalina.tribes.io.ReplicationStream;
@@ -373,7 +375,24 @@
      }

      public void expire(boolean notify, boolean notifyCluster) {
+        if (expiring)
+            return;
          String expiredId = getIdInternal();
+
+        if(expiredId != null&&  manager != null&&
+           manager instanceof DeltaManager) {
+            DeltaManager dmanager = (DeltaManager)manager;
+            CatalinaCluster cluster = dmanager.getCluster();
+            ClusterMessage msg = dmanager.requestCompleted(expiredId, true);
+            if (msg != null) {
+                if(dmanager.doDomainReplication()) {
+                    cluster.sendClusterDomain(msg);
+                } else {
+                    cluster.send(msg);
+                }
+            }
+        }
+
          super.expire(notify);

          if (notifyCluster) {
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org




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

Reply via email to