[jboss-cvs] JBossAS SVN: r92504 - branches/JBPAPP_5_0/tomcat/src/main/org/jboss/web/tomcat/service/session.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Aug 18 05:28:37 EDT 2009


Author: bstansberry at jboss.com
Date: 2009-08-18 05:28:37 -0400 (Tue, 18 Aug 2009)
New Revision: 92504

Modified:
   branches/JBPAPP_5_0/tomcat/src/main/org/jboss/web/tomcat/service/session/AttributeBasedClusteredSession.java
   branches/JBPAPP_5_0/tomcat/src/main/org/jboss/web/tomcat/service/session/ClusteredSession.java
   branches/JBPAPP_5_0/tomcat/src/main/org/jboss/web/tomcat/service/session/FieldBasedClusteredSession.java
   branches/JBPAPP_5_0/tomcat/src/main/org/jboss/web/tomcat/service/session/JBossCacheManager.java
   branches/JBPAPP_5_0/tomcat/src/main/org/jboss/web/tomcat/service/session/SessionBasedClusteredSession.java
Log:
[JBPAPP-2529] Replicate full session content after failover

Modified: branches/JBPAPP_5_0/tomcat/src/main/org/jboss/web/tomcat/service/session/AttributeBasedClusteredSession.java
===================================================================
--- branches/JBPAPP_5_0/tomcat/src/main/org/jboss/web/tomcat/service/session/AttributeBasedClusteredSession.java	2009-08-18 09:16:59 UTC (rev 92503)
+++ branches/JBPAPP_5_0/tomcat/src/main/org/jboss/web/tomcat/service/session/AttributeBasedClusteredSession.java	2009-08-18 09:28:37 UTC (rev 92504)
@@ -95,12 +95,18 @@
    @Override
    protected OutgoingAttributeGranularitySessionData getOutgoingSessionData()
    {
+      boolean needFull = isFullReplicationNeeded();
       Map<String, Object> modAttrs = null;
       Set<String> removeAttrs = null;
-      if (isSessionAttributeMapDirty())
+      if (needFull || isSessionAttributeMapDirty())
       {
-         if (attrModifiedMap_.size() > 0)
+         if (needFull)
          {
+            modAttrs = new HashMap<String, Object>(getAttributesInternal());
+            removeExcludedAttributes(modAttrs);
+         }
+         else if (attrModifiedMap_.size() > 0)
+         {
             modAttrs = new HashMap<String, Object>(attrModifiedMap_);
          }
          
@@ -111,7 +117,7 @@
          
          clearAttrChangedMaps();
       }
-      DistributableSessionMetadata metadata = isSessionMetadataDirty() ? getSessionMetadata() : null;
+      DistributableSessionMetadata metadata = (needFull || isSessionMetadataDirty()) ? getSessionMetadata() : null;
       Long timestamp = modAttrs != null || removeAttrs != null || metadata != null || getMustReplicateTimestamp() ? Long.valueOf(getSessionTimestamp()) : null;
       return new OutgoingData(getRealId(), getVersion(), timestamp, metadata, modAttrs, removeAttrs);
    }

Modified: branches/JBPAPP_5_0/tomcat/src/main/org/jboss/web/tomcat/service/session/ClusteredSession.java
===================================================================
--- branches/JBPAPP_5_0/tomcat/src/main/org/jboss/web/tomcat/service/session/ClusteredSession.java	2009-08-18 09:16:59 UTC (rev 92503)
+++ branches/JBPAPP_5_0/tomcat/src/main/org/jboss/web/tomcat/service/session/ClusteredSession.java	2009-08-18 09:28:37 UTC (rev 92504)
@@ -150,6 +150,9 @@
    protected static final StringManager sm =
       StringManager.getManager(ClusteredSession.class.getPackage().getName());
 
+   /** Length of time we do full replication as workaround to JBCACHE-1531 */
+   private static final long FULL_REPLICATION_WINDOW_LENGTH = 5000;
+
    // ----------------------------------------------------- Instance Variables
 
    /**
@@ -374,6 +377,13 @@
    /** True if a call to activate() is needed to offset a preceding passivate() call */
    private transient boolean needsPostReplicateActivation;
    
+   /** True if a getOutgoingSessionData() should include metadata and all 
+    *  attributes no matter what. This is a workaround to JBCACHE-1531.
+    *  This flag ensures that at least one request gets full replication, whether
+    *  or not in occurs before this.fullReplicationWindow */
+   private transient boolean fullReplicationRequired = true;
+   /** End of period when we do full replication */
+   private transient long fullReplicationWindow = -1;
    
    // ------------------------------------------------------------ Constructors
 
@@ -391,6 +401,7 @@
       this.firstAccess = true;
       
       setManager(manager);
+      requireFullReplication();
    }
    
    // ---------------------------------------------------------------- Session
@@ -1070,9 +1081,19 @@
    
    protected boolean isSessionAttributeMapDirty()
    {
-      return sessionAttributesDirty;
+      return sessionAttributesDirty || isFullReplicationNeeded();
    }
    
+   protected boolean isFullReplicationNeeded()
+   {
+      if (fullReplicationRequired)
+      {
+         return true;
+      }
+      return fullReplicationRequired || 
+         (fullReplicationWindow > 0 && System.currentTimeMillis() < fullReplicationWindow);
+   }
+   
    /**
     * {@inheritDoc}
     */
@@ -1146,7 +1167,10 @@
 //      }
       
       // We are no longer outdated vis a vis distributed cache
-      outdatedTime = 0;
+      this.outdatedTime = 0;
+      
+      // Requests must publish our full state back to the cluster in case anything got dropped.
+      this.requireFullReplication();      
    }   
 
    // ------------------------------------------------------------------ Public
@@ -1171,6 +1195,12 @@
       sessionMetadataDirty = false;
       
       lastReplicated = System.currentTimeMillis();
+      
+      this.fullReplicationRequired = false;
+      if (this.fullReplicationWindow > 0 && System.currentTimeMillis() > this.fullReplicationWindow)
+      {
+         this.fullReplicationWindow = -1;
+      }
    }
    
    protected abstract O getOutgoingSessionData();
@@ -2003,5 +2033,11 @@
          manager.remove(this);
       }
    }
+   
+   private void requireFullReplication()
+   {
+      this.fullReplicationRequired = true;
+      this.fullReplicationWindow = System.currentTimeMillis() + FULL_REPLICATION_WINDOW_LENGTH;      
+   }
 
 }

Modified: branches/JBPAPP_5_0/tomcat/src/main/org/jboss/web/tomcat/service/session/FieldBasedClusteredSession.java
===================================================================
--- branches/JBPAPP_5_0/tomcat/src/main/org/jboss/web/tomcat/service/session/FieldBasedClusteredSession.java	2009-08-18 09:16:59 UTC (rev 92503)
+++ branches/JBPAPP_5_0/tomcat/src/main/org/jboss/web/tomcat/service/session/FieldBasedClusteredSession.java	2009-08-18 09:28:37 UTC (rev 92504)
@@ -85,7 +85,11 @@
    @Override
    protected OutgoingDistributableSessionData getOutgoingSessionData()
    {
-      DistributableSessionMetadata metadata = isSessionMetadataDirty() ? getSessionMetadata() : null;
+      boolean needFull = isFullReplicationNeeded();
+      
+      // TODO if needFull, publish all attributes to distributed cache
+      
+      DistributableSessionMetadata metadata = (needFull || isSessionMetadataDirty()) ? getSessionMetadata() : null;
       Long timestamp = metadata != null || isSessionAttributeMapDirty() || getMustReplicateTimestamp() ? Long.valueOf(getSessionTimestamp()) : null;
       return new OutgoingDistributableSessionDataImpl(getRealId(), getVersion(), timestamp, metadata);
    }

Modified: branches/JBPAPP_5_0/tomcat/src/main/org/jboss/web/tomcat/service/session/JBossCacheManager.java
===================================================================
--- branches/JBPAPP_5_0/tomcat/src/main/org/jboss/web/tomcat/service/session/JBossCacheManager.java	2009-08-18 09:16:59 UTC (rev 92503)
+++ branches/JBPAPP_5_0/tomcat/src/main/org/jboss/web/tomcat/service/session/JBossCacheManager.java	2009-08-18 09:28:37 UTC (rev 92504)
@@ -2017,6 +2017,7 @@
                {
                   ContextClassLoaderSwitcher.SwitchContext switcher = null; 
                   boolean doTx = false; 
+                  boolean loadCompleted = false;
                   try
                   {
                      // We need transaction so any data gravitation replication 
@@ -2052,6 +2053,8 @@
                                                                              : ClusteredSessionNotificationCause.FAILOVER;
                         session.notifyDidActivate(cause);
                      }
+                     
+                     loadCompleted = true;
                   }
                   catch (Exception ex)
                   {
@@ -2077,7 +2080,30 @@
                      try {
                         if(doTx)
                         {
-                           batchingManager.endBatch();
+                           try
+                           {
+                              batchingManager.endBatch();
+                           }
+                           catch (Exception e)
+                           {
+                              if (loadCompleted)
+                              {
+                                 // We read the data successfully but then failed in commit?
+                                 // That indicates a JBC data gravitation where the replication of
+                                 // the gravitated data to our buddy failed. We can ignore that
+                                 // and count on this request updating the cache.                               // 
+                                 log_.warn("Problem ending batch after loading session " + realId + " -- " + e.getLocalizedMessage() + " However session data was successful loaded.");
+                                 log_.debug("Failure cause", e);
+                              }
+                              else
+                              {
+                                 if (e instanceof RuntimeException)
+                                    throw (RuntimeException) e;
+                                 
+                                 throw new RuntimeException("loadSession(): failed to load session " +
+                                                            realId, e);
+                              }
+                           }
                         }
                      }
                      finally {

Modified: branches/JBPAPP_5_0/tomcat/src/main/org/jboss/web/tomcat/service/session/SessionBasedClusteredSession.java
===================================================================
--- branches/JBPAPP_5_0/tomcat/src/main/org/jboss/web/tomcat/service/session/SessionBasedClusteredSession.java	2009-08-18 09:16:59 UTC (rev 92503)
+++ branches/JBPAPP_5_0/tomcat/src/main/org/jboss/web/tomcat/service/session/SessionBasedClusteredSession.java	2009-08-18 09:28:37 UTC (rev 92504)
@@ -71,8 +71,9 @@
    @Override
    protected OutgoingSessionGranularitySessionData getOutgoingSessionData()
    {
-      Map<String, Object> attrs = isSessionAttributeMapDirty() ? getSessionAttributeMap() : null;
-      DistributableSessionMetadata metadata = isSessionMetadataDirty() ? getSessionMetadata() : null;
+      boolean needFull = isFullReplicationNeeded();
+      Map<String, Object> attrs = (needFull || isSessionAttributeMapDirty()) ? getSessionAttributeMap() : null;
+      DistributableSessionMetadata metadata = (needFull || isSessionMetadataDirty()) ? getSessionMetadata() : null;
       Long timestamp = attrs != null || metadata != null || getMustReplicateTimestamp() ? Long.valueOf(getSessionTimestamp()) : null;
       return new OutgoingData(getRealId(), getVersion(), timestamp, metadata, attrs);
    }




More information about the jboss-cvs-commits mailing list