db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r507428 - in /db/derby/code/trunk/java/engine/org/apache/derby/impl/services/locks: LockSpace.java SinglePool.java
Date Wed, 14 Feb 2007 07:40:24 GMT
Author: kahatlen
Date: Tue Feb 13 23:40:23 2007
New Revision: 507428

URL: http://svn.apache.org/viewvc?view=rev&rev=507428
Log:
DERBY-1704 (partial) Allow more concurrency in the lock manager

Modified LockSpace so that it doesn't extend Hashtable.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/services/locks/LockSpace.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/services/locks/SinglePool.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/services/locks/LockSpace.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/services/locks/LockSpace.java?view=diff&rev=507428&r1=507427&r2=507428
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/services/locks/LockSpace.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/services/locks/LockSpace.java Tue
Feb 13 23:40:23 2007
@@ -28,7 +28,6 @@
 import org.apache.derby.iapi.services.sanity.SanityManager;
 import org.apache.derby.iapi.error.StandardException;
 
-import java.util.Hashtable;
 import java.util.Enumeration;
 import java.util.Dictionary;
 import java.util.HashMap;
@@ -39,12 +38,14 @@
 	A LockSpace represents the complete set of locks held within
 	a single compatability space, broken into groups of locks.
 
-    A LockSpace is a hashtable keyed by the group reference,
-	the data for each key is a Hashtable of Lock's.
+    A LockSpace contains a hashtable keyed by the group reference,
+    the data for each key is a HashMap of Lock's.
 
 */
-class LockSpace extends Hashtable {
+final class LockSpace {
 
+	/** Map from group references to groups of locks. */
+	private final HashMap groups;
 	private final Object compatSpace;
 	// the object I live in
 	private final Dictionary holder;
@@ -58,9 +59,9 @@
 	private Limit  callback;
 
 	LockSpace(Dictionary holder, Object compatSpace) {
-		super();
 		this.compatSpace = compatSpace;
 		this.holder = holder;
+		groups = new HashMap();
 	}
 
 	/**
@@ -71,7 +72,7 @@
 
 		Lock lockInGroup = null;
 
-		HashMap dl = (HashMap) get(group);
+		HashMap dl = (HashMap) groups.get(group);
 		if (dl == null)	{
 			dl = getGroupMap(group);
 		} else if (lock.getCount() != 1) {
@@ -119,7 +120,7 @@
 	*/
 
 	synchronized void unlockGroup(LockSet lset, Object group) {
-		HashMap dl = (HashMap) remove(group);
+		HashMap dl = (HashMap) groups.remove(group);
 		if (dl == null)
 			return;
 
@@ -127,7 +128,7 @@
 			lset.unlock((Lock) list.next(), 0);
 		}
 
-		if ((callbackGroup == null) && isEmpty())
+		if ((callbackGroup == null) && groups.isEmpty())
 			holder.remove(compatSpace);
 		else if (group.equals(callbackGroup))
 			nextLimitCall = limit;
@@ -149,7 +150,7 @@
 		if (dl == null)
 			dl = new HashMap(5, 0.8f);
 
-		put(group, dl);
+		groups.put(group, dl);
 		return dl;
 	}
 	private void saveGroup(HashMap dl) {
@@ -167,7 +168,7 @@
 		Unlock all locks in the group that match the key
 	*/
 	synchronized void unlockGroup(LockSet lset, Object group, Matchable key) {
-		HashMap dl = (HashMap) get(group);
+		HashMap dl = (HashMap) groups.get(group);
 		if (dl == null)
 			return; //  no group at all
 
@@ -184,9 +185,9 @@
 		}
 
 		if (allUnlocked) {
-			remove(group);
+			groups.remove(group);
 			saveGroup(dl);
-			if ((callbackGroup == null) && isEmpty())
+			if ((callbackGroup == null) && groups.isEmpty())
 				holder.remove(compatSpace);
 			else if (group.equals(callbackGroup))
 				nextLimitCall = limit;
@@ -195,16 +196,16 @@
 	}
 
 	synchronized void transfer(Object oldGroup, Object newGroup) {
-		HashMap from = (HashMap) get(oldGroup);
+		HashMap from = (HashMap) groups.get(oldGroup);
 		if (from == null)
 			return;
 
-		HashMap to = (HashMap) get(newGroup);
+		HashMap to = (HashMap) groups.get(newGroup);
 		if (to == null) {
 			// simple case 
-			put(newGroup, from);
+			groups.put(newGroup, from);
 			clearLimit(oldGroup);
-			remove(oldGroup);
+			groups.remove(oldGroup);
 			return;
 		}
 
@@ -213,7 +214,7 @@
 			// place the contents of to into from
 			mergeGroups(to, from);
 
-			Object oldTo = put(newGroup, from);
+			Object oldTo = groups.put(newGroup, from);
 			if (SanityManager.DEBUG) {
 				SanityManager.ASSERT(oldTo == to, "inconsistent state in LockSpace");
 			}
@@ -223,7 +224,7 @@
 		}
 		
 		clearLimit(oldGroup);
-		remove(oldGroup);
+		groups.remove(oldGroup);
 	}
 
 	private void mergeGroups(HashMap from, HashMap into) {
@@ -251,7 +252,7 @@
 	synchronized int unlockReference(LockSet lset, Lockable ref, Object qualifier, Object group)
{
 
 		// look for locks matching our reference and qualifier.
-		HashMap dl = (HashMap) get(group);
+		HashMap dl = (HashMap) groups.get(group);
 		if (dl == null)
 			return 0;
 
@@ -276,9 +277,9 @@
 		if (lockInGroup.getCount() == 1) {
 
 			if (dl.isEmpty()) {
-				remove(group);
+				groups.remove(group);
 				saveGroup(dl);
-				if ((callbackGroup == null) && isEmpty())
+				if ((callbackGroup == null) && groups.isEmpty())
 					holder.remove(compatSpace);
 				else if (group.equals(callbackGroup))
 					nextLimitCall = limit;
@@ -298,13 +299,21 @@
 		Return true if locks are held in a group
 	*/
 	synchronized boolean areLocksHeld(Object group) {
-		return  (get(group) != null);
+		return groups.containsKey(group);
+	}
+
+	/**
+	 * Return true if locks are held in this compatibility space.
+	 * @return true if locks are held, false otherwise
+	 */
+	synchronized boolean areLocksHeld() {
+		return !groups.isEmpty();
 	}
 	
 	synchronized boolean isLockHeld(Object group, Lockable ref, Object qualifier) {
 
 		// look for locks matching our reference and qualifier.
-		HashMap dl = (HashMap) get(group);
+		HashMap dl = (HashMap) groups.get(group);
 		if (dl == null)
 			return false;
 
@@ -328,7 +337,7 @@
 			nextLimitCall = limit = Integer.MAX_VALUE;
 			callback = null;
 
-			if (isEmpty())
+			if (groups.isEmpty())
 				holder.remove(compatSpace);
 		}
 	}
@@ -348,8 +357,8 @@
 
 		int count = 0;
 
-		for (Enumeration groups = elements(); groups.hasMoreElements(); ) {
-			HashMap group = (HashMap) groups.nextElement();
+		for (Iterator it = groups.values().iterator(); it.hasNext(); ) {
+			HashMap group = (HashMap) it.next();
 			for (Iterator locks = group.keySet().iterator(); locks.hasNext(); ) {
 					Lock lock = (Lock) locks.next();
 					count += lock.getCount();

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/services/locks/SinglePool.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/services/locks/SinglePool.java?view=diff&rev=507428&r1=507427&r2=507428
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/services/locks/SinglePool.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/services/locks/SinglePool.java Tue
Feb 13 23:40:23 2007
@@ -339,7 +339,7 @@
 		LockSpace ls = (LockSpace) get(compatabilitySpace);
 		if (ls == null)
 			return false;
-		return !ls.isEmpty();
+		return ls.areLocksHeld();
 	}
 
 	public boolean zeroDurationlockObject(Object compatabilitySpace, Lockable ref, Object qualifier,
int timeout)



Mime
View raw message