[jboss-cvs] JBossAS SVN: r105114 - in projects/cluster/ha-server-cache-jbc/trunk: src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri May 21 22:33:57 EDT 2010
Author: bstansberry at jboss.com
Date: 2010-05-21 22:33:57 -0400 (Fri, 21 May 2010)
New Revision: 105114
Modified:
projects/cluster/ha-server-cache-jbc/trunk/pom.xml
projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/AbstractJBossCacheService.java
projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/Util.java
Log:
[JBCLUSTER-272] Handling batching in AbstractJBossCacheServer.getSessionData
Modified: projects/cluster/ha-server-cache-jbc/trunk/pom.xml
===================================================================
--- projects/cluster/ha-server-cache-jbc/trunk/pom.xml 2010-05-22 01:06:20 UTC (rev 105113)
+++ projects/cluster/ha-server-cache-jbc/trunk/pom.xml 2010-05-22 02:33:57 UTC (rev 105114)
@@ -31,7 +31,7 @@
<properties>
<version.jboss.ha.server.cache.spi>2.1.0.Final</version.jboss.ha.server.cache.spi>
- <version.jboss.ha.server.api>1.1.2.Final</version.jboss.ha.server.api>
+ <version.jboss.ha.server.api>2.0.0.Alpha3</version.jboss.ha.server.api>
<version.jboss.common.core>2.2.17.GA</version.jboss.common.core>
<version.jboss.logging.spi>2.0.5.GA</version.jboss.logging.spi>
<version.jboss.cache>3.2.5.GA</version.jboss.cache>
Modified: projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/AbstractJBossCacheService.java
===================================================================
--- projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/AbstractJBossCacheService.java 2010-05-22 01:06:20 UTC (rev 105113)
+++ projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/AbstractJBossCacheService.java 2010-05-22 02:33:57 UTC (rev 105114)
@@ -352,36 +352,62 @@
}
Fqn<String> fqn = getSessionFqn(combinedPath_, realId);
- Map<Object, Object> sessionData = cacheWrapper_.getData(fqn, true);
- if (sessionData == null) {
- // Requested session is no longer in the cache; return null
- return null;
- }
-
- if (initialLoad)
+ boolean ourBatch = false;
+ boolean loadCompleted = false;
+ Map<Object, Object> sessionData = null;
+ try
{
- setupSessionRegion(fqn);
- }
+ // We need batching so any data gravitation replication
+ // is sent in batch.
+ // Don't do anything if there is already a batch
+ // associated with this thread.
+ ourBatch = ensureBatchInProgress();
+
+ sessionData = cacheWrapper_.getData(fqn, true);
- IncomingDistributableSessionData dsd = null;
-
- try
- {
- dsd = getDistributableSessionData(realId, sessionData, true);
+ if (sessionData == null) {
+ // Requested session is no longer in the cache; return null
+ return null;
+ }
+
+ if (initialLoad)
+ {
+ setupSessionRegion(fqn);
+ }
+
+ IncomingDistributableSessionData dsd = null;
+
+ try
+ {
+ dsd = getDistributableSessionData(realId, sessionData, true);
+ }
+ catch (Exception e)
+ {
+ String masked = Util.maskId(realId);
+ log_.warn("Problem accessing session data for session " + masked + " (" +
+ e.getClass().getName() + ") -- existing session cannot be used");
+ log_.debug("Details on problem accessing session data for " + masked, e);
+ // Clean up
+ removeSessionLocal(realId);
+ return null;
+ }
+
+ loadCompleted = true;
+
+ return dsd;
}
catch (Exception e)
{
- String masked = Util.maskId(realId);
- log_.warn("Problem accessing session data for session " + masked + " (" +
- e.getClass().getName() + ") -- existing session cannot be used");
- log_.debug("Details on problem accessing session data for " + masked, e);
- // Clean up
- removeSessionLocal(realId);
- return null;
+ throw handleBatchException(ourBatch, realId, e);
}
-
- return dsd;
+ finally
+ {
+ if (ourBatch)
+ {
+ finishBatch(realId, loadCompleted);
+ }
+ }
}
public void storeSessionData(T sessionData)
@@ -566,26 +592,45 @@
public IncomingDistributableSessionData getSessionData(String realId, String dataOwner, boolean includeAttributes)
{
- Map<Object, Object> distributedCacheData = null;
- if (dataOwner == null)
+ boolean ourBatch = false;
+ boolean loadCompleted = false;
+ try
{
- Fqn<String> fqn = getSessionFqn(combinedPath_, realId);
- distributedCacheData = cacheWrapper_.getData(fqn, false);
- }
- else
- {
- List<Fqn<Object>> fqns = getBuddyBackupSessionFqns(dataOwner, combinedPath_, realId);
- for (Fqn<Object> fqn : fqns)
+ ourBatch = ensureBatchInProgress();
+
+ Map<Object, Object> distributedCacheData = null;
+ if (dataOwner == null)
{
+ Fqn<String> fqn = getSessionFqn(combinedPath_, realId);
distributedCacheData = cacheWrapper_.getData(fqn, false);
- if (distributedCacheData != null && distributedCacheData.size() > 0)
+ }
+ else
+ {
+ List<Fqn<Object>> fqns = getBuddyBackupSessionFqns(dataOwner, combinedPath_, realId);
+ for (Fqn<Object> fqn : fqns)
{
- break;
+ distributedCacheData = cacheWrapper_.getData(fqn, false);
+ if (distributedCacheData != null && distributedCacheData.size() > 0)
+ {
+ break;
+ }
}
}
+ IncomingDistributableSessionData result = distributedCacheData == null ? null : getDistributableSessionData(realId, distributedCacheData, includeAttributes);
+ loadCompleted = true;
+ return result;
}
-
- return distributedCacheData == null ? null : getDistributableSessionData(realId, distributedCacheData, includeAttributes);
+ catch (Exception e)
+ {
+ throw handleBatchException(ourBatch, realId, e);
+ }
+ finally
+ {
+ if (ourBatch)
+ {
+ finishBatch(realId, loadCompleted);
+ }
+ }
}
/**
@@ -825,4 +870,55 @@
}
}
+ private boolean ensureBatchInProgress() throws Exception
+ {
+ boolean newBatch = false;
+ if (batchingManager.isBatchInProgress() == false)
+ {
+ batchingManager.startBatch();
+ newBatch = true;
+ }
+ return newBatch;
+ }
+
+ private RuntimeException handleBatchException(boolean ourBatch, String realId, Exception e)
+ {
+ try
+ {
+// if(ourBatch)
+ // Let's set it no matter what.
+ batchingManager.setBatchRollbackOnly();
+ }
+ catch (Exception exn)
+ {
+ log_.error("Caught exception rolling back transaction", exn);
+ }
+
+ return Util.getRuntimeException("Failed to load session " + Util.maskId(realId), e);
+ }
+
+ private void finishBatch(String realId, boolean loadCompleted)
+ {
+ 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 " + Util.maskId(realId) + " -- " + e.getLocalizedMessage() + " However session data was successful loaded.");
+ log_.debug("Failure cause", e);
+ }
+ else
+ {
+ throw Util.getRuntimeException("Failed to load session " + Util.maskId(realId), e);
+ }
+ }
+ }
+
}
Modified: projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/Util.java
===================================================================
--- projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/Util.java 2010-05-22 01:06:20 UTC (rev 105113)
+++ projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/Util.java 2010-05-22 02:33:57 UTC (rev 105114)
@@ -281,6 +281,26 @@
}
/**
+ * Returns either an <code>e</code> or a wrapper RuntimeException, depending on the type
+ * of <code>e</code>. If <code>e</code> is an Ea RuntimeException, it
+ * is simply returned, otherwise <code>e</code> is wrapped in a RuntimeException
+ * which is returned.
+ *
+ * @param wrapperMsg an optional message for the wrapper RuntimeException, if
+ * one is needed. If not provided, the classname of <code>e</code>
+ * and it's localized message is used
+ * @param e the underlying exception
+ */
+ public static RuntimeException getRuntimeException(String wrapperMsg, Exception e)
+ {
+ if (e instanceof RuntimeException)
+ return (RuntimeException) e;
+
+ wrapperMsg = (wrapperMsg != null) ? wrapperMsg : e.getClass().getName() + " -- " + e.getLocalizedMessage();
+ throw new RuntimeException(wrapperMsg, e);
+ }
+
+ /**
* Prevent instantiation.
*/
private Util() {}
More information about the jboss-cvs-commits
mailing list