Author: manik.surtani(a)jboss.com
Date: 2008-01-02 12:41:26 -0500 (Wed, 02 Jan 2008)
New Revision: 4943
Modified:
core/trunk/src/main/java/org/jboss/cache/CacheImpl.java
core/trunk/src/main/java/org/jboss/cache/loader/AbstractCacheLoader.java
core/trunk/src/main/java/org/jboss/cache/lock/IdentityLock.java
core/trunk/src/main/java/org/jboss/cache/lock/NodeLock.java
core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferGenerator.java
core/trunk/src/main/java/org/jboss/cache/statetransfer/StateTransferManager.java
core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyGroupAssignmentTest.java
core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationContentTest.java
Log:
more efficient locking with state transfer + population of internal fqns set on cache
construction
Modified: core/trunk/src/main/java/org/jboss/cache/CacheImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/CacheImpl.java 2008-01-02 16:53:35 UTC (rev
4942)
+++ core/trunk/src/main/java/org/jboss/cache/CacheImpl.java 2008-01-02 17:41:26 UTC (rev
4943)
@@ -45,7 +45,6 @@
import org.jboss.cache.transaction.TransactionTable;
import org.jboss.cache.util.CachePrinter;
import org.jboss.cache.util.ThreadGate;
-import org.jboss.cache.util.concurrent.ConcurrentHashSet;
import org.jboss.cache.util.reflect.ReflectionUtil;
import org.jgroups.*;
import org.jgroups.blocks.GroupRequest;
@@ -134,7 +133,7 @@
* Set<Fqn> of Fqns of the topmost node of internal regions that should
* not included in standard state transfers.
*/
- private Set<Fqn> internalFqns = new ConcurrentHashSet<Fqn>();
+ private Set<Fqn> internalFqns = new HashSet<Fqn>();
/**
* Marshaller if register to handle marshalling
@@ -200,6 +199,8 @@
this.configuration = configuration;
this.componentRegistry = new ComponentRegistry(configuration);
this.cacheStatus = CacheStatus.INSTANTIATED;
+
+ internalFqns.add(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN);
}
protected ComponentRegistry getComponentRegistry()
Modified: core/trunk/src/main/java/org/jboss/cache/loader/AbstractCacheLoader.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/loader/AbstractCacheLoader.java 2008-01-02
16:53:35 UTC (rev 4942)
+++ core/trunk/src/main/java/org/jboss/cache/loader/AbstractCacheLoader.java 2008-01-02
17:41:26 UTC (rev 4943)
@@ -219,8 +219,7 @@
{
child_name = (String) children_name;
tmp_fqn = new Fqn(fqn, child_name);
- //loadStateHelper(tmp_fqn, out);
- getNodeDataList(tmp_fqn, list);
+ if (!cache.getInternalFqns().contains(tmp_fqn)) getNodeDataList(tmp_fqn, list);
}
}
Modified: core/trunk/src/main/java/org/jboss/cache/lock/IdentityLock.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/lock/IdentityLock.java 2008-01-02 16:53:35
UTC (rev 4942)
+++ core/trunk/src/main/java/org/jboss/cache/lock/IdentityLock.java 2008-01-02 17:41:26
UTC (rev 4943)
@@ -532,9 +532,15 @@
public Set<NodeLock> acquireAll(Object caller, long timeout, LockType
lock_type)
throws LockingException, TimeoutException, InterruptedException
{
+ return acquireAll(caller, timeout, lock_type, false);
+ }
+
+ public Set<NodeLock> acquireAll(Object caller, long timeout, LockType lock_type,
boolean excludeInternalFqns)
+ throws LockingException, TimeoutException, InterruptedException
+ {
boolean acquired;
- if (lock_type == LockType.NONE)
+ if (lock_type == LockType.NONE || (excludeInternalFqns &&
node.getCache().getInternalFqns().contains(getFqn())))
{
return Collections.emptySet();
}
@@ -548,7 +554,7 @@
for (NodeSPI n : node.getChildrenDirect())
{
- retval.addAll(n.getLock().acquireAll(caller, timeout, lock_type));
+ retval.addAll(n.getLock().acquireAll(caller, timeout, lock_type,
excludeInternalFqns));
}
return retval;
}
Modified: core/trunk/src/main/java/org/jboss/cache/lock/NodeLock.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/lock/NodeLock.java 2008-01-02 16:53:35 UTC
(rev 4942)
+++ core/trunk/src/main/java/org/jboss/cache/lock/NodeLock.java 2008-01-02 17:41:26 UTC
(rev 4943)
@@ -98,19 +98,29 @@
InterruptedException;
/**
- * Recursively acquire locks for this node and all subnodes.
+ * Recursively acquire locks for this node and all subnodes, including internal Fqns
such as buddy backup subtrees.
*
* @param caller lock owner
* @param timeout time to wait
* @param lock_type type of lock
* @return locks acquired
- * @throws LockingException
- * @throws TimeoutException
- * @throws InterruptedException
*/
Set<NodeLock> acquireAll(Object caller, long timeout, NodeLock.LockType
lock_type) throws LockingException, TimeoutException,
InterruptedException;
+ /**
+ * Same as the overloaded {@link #acquire(Object, long,
org.jboss.cache.lock.NodeLock.LockType)} except that you can
+ * optionally specify that internal Fqns - such as buddy backup subtrees - can be
excluded when acquiring locks.
+ *
+ * @param caller lock owner
+ * @param timeout time to wait
+ * @param lock_type type of lock
+ * @param excludeInternalFqns if true, locks on internal fqns are not acquired.
+ * @return locks acquired
+ */
+ Set<NodeLock> acquireAll(Object caller, long timeout, LockType lock_type,
boolean excludeInternalFqns) throws LockingException, TimeoutException,
+ InterruptedException;
+
void printLockInfo(StringBuffer sb, int indent);
}
\ No newline at end of file
Modified:
core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferGenerator.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferGenerator.java 2008-01-02
16:53:35 UTC (rev 4942)
+++
core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferGenerator.java 2008-01-02
17:41:26 UTC (rev 4943)
@@ -165,11 +165,7 @@
list.add(nd);
// then visit the children
- for (NodeSPI child : node.getChildrenDirect())
- {
- //marshallTransientState(child, out);
- generateNodeDataList(child, list);
- }
+ for (NodeSPI child : node.getChildrenDirect()) generateNodeDataList(child, list);
}
/**
Modified:
core/trunk/src/main/java/org/jboss/cache/statetransfer/StateTransferManager.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/statetransfer/StateTransferManager.java 2008-01-02
16:53:35 UTC (rev 4942)
+++
core/trunk/src/main/java/org/jboss/cache/statetransfer/StateTransferManager.java 2008-01-02
17:41:26 UTC (rev 4943)
@@ -241,7 +241,7 @@
{
if (lockChildren)
{
- root.getLock().acquireAll(lockOwner, timeout, NodeLock.LockType.READ);
+ root.getLock().acquireAll(lockOwner, timeout, NodeLock.LockType.READ, true);
}
else
{
Modified:
core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyGroupAssignmentTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyGroupAssignmentTest.java 2008-01-02
16:53:35 UTC (rev 4942)
+++
core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyGroupAssignmentTest.java 2008-01-02
17:41:26 UTC (rev 4943)
@@ -11,6 +11,7 @@
import org.jboss.cache.Cache;
import org.jboss.cache.CacheSPI;
import org.jboss.cache.misc.TestingUtil;
+import org.jboss.cache.util.CachePrinter;
import org.testng.annotations.Test;
/**
@@ -39,6 +40,10 @@
assertIsBuddy(caches.get(1), caches.get(2), true);
System.out.println("*** Testing cache 2:");
assertIsBuddy(caches.get(2), caches.get(0), true);
+
+ System.out.println("Cache 0 = " +
CachePrinter.printCacheLockingInfo(caches.get(0)));
+ System.out.println("Cache 1 = " +
CachePrinter.printCacheLockingInfo(caches.get(1)));
+ System.out.println("Cache 2 = " +
CachePrinter.printCacheLockingInfo(caches.get(2)));
}
public void test2Buddies() throws Exception
Modified:
core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationContentTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationContentTest.java 2008-01-02
16:53:35 UTC (rev 4942)
+++
core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationContentTest.java 2008-01-02
17:41:26 UTC (rev 4943)
@@ -71,6 +71,10 @@
assertNull("Should be null", caches.get(2).get(backupFqn, key));
assertNoStaleLocks(caches);
+
+ System.out.println("Cache 0 = " +
CachePrinter.printCacheLockingInfo(caches.get(0)));
+ System.out.println("Cache 1 = " +
CachePrinter.printCacheLockingInfo(caches.get(1)));
+ System.out.println("Cache 2 = " +
CachePrinter.printCacheLockingInfo(caches.get(2)));
}
public void testPutAndRemove() throws Exception