[jboss-cvs] JBossAS SVN: r104577 - projects/cluster/ha-server-cache-jbc/branches/Branch_2_0/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri May 7 15:36:17 EDT 2010
Author: bstansberry at jboss.com
Date: 2010-05-07 15:36:16 -0400 (Fri, 07 May 2010)
New Revision: 104577
Modified:
projects/cluster/ha-server-cache-jbc/branches/Branch_2_0/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/AbstractJBossCacheService.java
projects/cluster/ha-server-cache-jbc/branches/Branch_2_0/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/Util.java
Log:
[JBCLUSTER-269] Port to Branch_2_0
Modified: projects/cluster/ha-server-cache-jbc/branches/Branch_2_0/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/AbstractJBossCacheService.java
===================================================================
--- projects/cluster/ha-server-cache-jbc/branches/Branch_2_0/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/AbstractJBossCacheService.java 2010-05-07 19:35:14 UTC (rev 104576)
+++ projects/cluster/ha-server-cache-jbc/branches/Branch_2_0/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/AbstractJBossCacheService.java 2010-05-07 19:36:16 UTC (rev 104577)
@@ -517,16 +517,14 @@
for (Fqn<Object> fqn : fqns)
{
distributedCacheData = cacheWrapper_.getData(fqn, false);
- // Above call will return an empty map if fqn doesn't exist;
- // once we get a non-empty on that's the real data
- if (distributedCacheData.size() > 0)
+ if (distributedCacheData != null && distributedCacheData.size() > 0)
{
break;
}
}
}
- return getDistributableSessionData(realId, distributedCacheData, includeAttributes);
+ return distributedCacheData == null ? null : getDistributableSessionData(realId, distributedCacheData, includeAttributes);
}
/**
@@ -552,13 +550,36 @@
for (Node<Object, Object> owner : owners)
{
@SuppressWarnings("unchecked")
- Node webRoot = owner.getChild(webappFqn);
- if (webRoot != null)
+ Fqn<String> ownerFqn = owner.getFqn();
+ if (Util.isBuddyOwnerDead(ownerFqn))
{
- @SuppressWarnings("unchecked")
- Set<String> ids = webRoot.getChildrenNames();
- storeSessionOwners(ids, (String) owner.getFqn().getLastElement(), result);
+ Set<Object> ownerVersions = owner.getChildrenNames();
+ for (Object ownerVersion : ownerVersions)
+ {
+ // If we pulled node from FileCacheLoader, the type will
+ // be String, which is incorrect
+ boolean correctType = ownerVersion instanceof Integer;
+
+ Integer versionInt = correctType ?
+ (Integer) ownerVersion : Integer.valueOf(ownerVersion.toString());
+ Node<Object, Object> versionNode = owner.getChild(versionInt);
+
+ if (!correctType)
+ {
+ // We loaded a node with a bogus name type from FileCacheLoader.
+ // We need to evict it or it will screw up JBC code that assumes
+ // all names at this point in the tree are Integer
+ Fqn<Object> bogus = Fqn.fromRelativeElements(ownerFqn, ownerVersion);
+ this.cacheWrapper_.removeLocal(bogus);
+ }
+
+ storeSessionIdsForOwner(versionNode, webappFqn, result);
+ }
}
+ else
+ {
+ storeSessionIdsForOwner(owner, webappFqn, result);
+ }
}
}
}
@@ -575,6 +596,20 @@
Set<String> children = (node == null ? Collections.EMPTY_SET : node.getChildrenNames());
return children;
}
+
+ private void storeSessionIdsForOwner(Node<Object, Object> owner, Fqn<String> webappFqn, Map<String, String> result)
+ {
+ @SuppressWarnings("unchecked")
+ Node webRoot = owner.getChild(webappFqn);
+ if (webRoot != null)
+ {
+ @SuppressWarnings("unchecked")
+ Set<String> ids = webRoot.getChildrenNames();
+ @SuppressWarnings("unchecked")
+ String ownerName = Util.getBuddyOwner(owner.getFqn());
+ storeSessionOwners(ids, ownerName, result);
+ }
+ }
private void storeSessionOwners(Set<String> ids, String owner, Map<String, String> map)
{
@@ -726,6 +761,17 @@
Set<Object> buddies = plainCache_.getChildrenNames(dead); // won't return null
for (Object child : buddies)
{
+ if (!(child instanceof Integer))
+ {
+ log_.warn("Found child of type " + child.getClass() + " under fqn " + dead, new Exception("Just a stack trace"));
+ Object orig = child;
+ child = Integer.valueOf(orig.toString());
+ // In case we loaded a node with a bogus name type from FileCacheLoader
+ // we need to evict it or it will screw up JBC code that assumes
+ // all names at this point in the tree are Integer
+ Fqn<Object> bogus = Fqn.fromElements(BUDDY_BACKUP, deadBuddy, orig);
+ this.cacheWrapper_.removeLocal(bogus);
+ }
result.add(Fqn.fromElements(BUDDY_BACKUP, deadBuddy, child, SESSION, contextHostPath, sessionId));
}
return result;
Modified: projects/cluster/ha-server-cache-jbc/branches/Branch_2_0/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/Util.java
===================================================================
--- projects/cluster/ha-server-cache-jbc/branches/Branch_2_0/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/Util.java 2010-05-07 19:35:14 UTC (rev 104576)
+++ projects/cluster/ha-server-cache-jbc/branches/Branch_2_0/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/Util.java 2010-05-07 19:36:16 UTC (rev 104577)
@@ -25,6 +25,8 @@
import org.jboss.cache.Cache;
import org.jboss.cache.CacheManager;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.buddyreplication.BuddyManager;
import org.jboss.cache.pojo.PojoCache;
import org.jboss.ha.framework.server.CacheManagerLocator;
import org.jboss.ha.framework.server.PojoCacheManager;
@@ -42,6 +44,9 @@
*/
public class Util
{
+ private static final int BUDDY_BACKUP_ROOT_OWNER_INDEX = BuddyManager.BUDDY_BACKUP_SUBTREE_FQN.size();
+ private static final String DEAD_BUDDY_SUFFIX = ":DEAD";
+
public static ReplicationGranularity getReplicationGranularity(LocalDistributableSessionManager localManager)
{
ReplicationConfig config = localManager.getReplicationConfig();
@@ -128,7 +133,24 @@
return cm;
}
+ public static boolean isBuddyOwnerDead(Fqn<String> fqn)
+ {
+ String base = (String) fqn.get(BUDDY_BACKUP_ROOT_OWNER_INDEX);
+ return base.endsWith(DEAD_BUDDY_SUFFIX);
+ }
+
/**
+ * Extracts the owner portion of an buddy subtree Fqn.
+ *
+ * @param fqn An Fqn that is a child of the buddy backup root node.
+ */
+ public static String getBuddyOwner(Fqn<String> fqn)
+ {
+ String base = (String) fqn.get(BUDDY_BACKUP_ROOT_OWNER_INDEX);
+ return base.endsWith(DEAD_BUDDY_SUFFIX) ? base.substring(0, base.length() - DEAD_BUDDY_SUFFIX.length()): base;
+ }
+
+ /**
* Prevent instantiation.
*/
private Util() {}
More information about the jboss-cvs-commits
mailing list