You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by ka...@apache.org on 2007/01/23 13:08:24 UTC
svn commit: r498999 - in
/db/derby/code/trunk/java/engine/org/apache/derby/impl/services/locks:
Deadlock.java LockSet.java LockTableVTI.java SinglePool.java
Author: kahatlen
Date: Tue Jan 23 04:08:23 2007
New Revision: 498999
URL: http://svn.apache.org/viewvc?view=rev&rev=498999
Log:
DERBY-1704 (partial) Allow more concurrency in the lock manager
* Made LockSet contain a HashMap instead of extending Hashtable.
* Fixed some comments about MT/synchronization.
Modified:
db/derby/code/trunk/java/engine/org/apache/derby/impl/services/locks/Deadlock.java
db/derby/code/trunk/java/engine/org/apache/derby/impl/services/locks/LockSet.java
db/derby/code/trunk/java/engine/org/apache/derby/impl/services/locks/LockTableVTI.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/Deadlock.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/services/locks/Deadlock.java?view=diff&rev=498999&r1=498998&r2=498999
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/services/locks/Deadlock.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/services/locks/Deadlock.java Tue Jan 23 04:08:23 2007
@@ -46,6 +46,11 @@
private Deadlock() {}
+ /**
+ * Look for a deadlock.
+ * <BR>
+ * MT - must be synchronized on the <code>LockSet</code> object.
+ */
static Object[] look(SinglePool factory, LockSet set, LockControl control, ActiveLock startingLock, byte deadlockWake) {
// step one, get a list of all waiters
@@ -177,16 +182,8 @@
}
private static Hashtable getWaiters(LockSet set) {
-
- Hashtable waiters = new Hashtable(set.size() * 2);
-
- for (Enumeration e = set.elements(); e.hasMoreElements(); ) {
-
- Control control = (Control) e.nextElement();
-
- control.addWaiters(waiters);
- }
-
+ Hashtable waiters = new Hashtable();
+ set.addWaiters(waiters);
return waiters;
}
Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/services/locks/LockSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/services/locks/LockSet.java?view=diff&rev=498999&r1=498998&r2=498999
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/services/locks/LockSet.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/services/locks/LockSet.java Tue Jan 23 04:08:23 2007
@@ -24,7 +24,6 @@
import org.apache.derby.iapi.services.locks.Latch;
import org.apache.derby.iapi.services.locks.Lockable;
import org.apache.derby.iapi.services.locks.C_LockFactory;
-import org.apache.derby.iapi.services.monitor.Monitor;
import org.apache.derby.iapi.error.StandardException;
@@ -34,8 +33,12 @@
import org.apache.derby.iapi.reference.Property;
import org.apache.derby.iapi.reference.SQLState;
+import java.util.Dictionary;
+import java.util.HashMap;
import java.util.Hashtable;
import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.Map;
/**
@@ -46,10 +49,11 @@
A LockControl contains information about the locks held on a Lockable.
<BR>
- MT - Mutable - Container Object : Thread Safe
+ MT - Mutable - Container Object : All non-private methods of this class are
+ thread safe unless otherwise stated by their javadoc comments.
<BR>
- The Hashtable we extend is synchronized on this, all addition, searching of
+ All searching of
the hashtable is performed using java synchroization(this).
<BR>
The class creates ActiveLock and LockControl objects.
@@ -65,13 +69,16 @@
@see LockControl
*/
-public final class LockSet extends Hashtable
-{
+final class LockSet {
/*
** Fields
*/
private final SinglePool factory;
+ /** Hash table which maps <code>Lockable</code> objects to
+ * <code>Lock</code>s. */
+ private final HashMap locks;
+
/**
Timeout for deadlocks, in ms.
<BR>
@@ -92,15 +99,15 @@
//EXCLUDE-END-lockdiag-
// The number of waiters for locks
- protected int blockCount;
+ private int blockCount;
/*
** Constructor
*/
protected LockSet(SinglePool factory) {
- super();
this.factory = factory;
+ locks = new HashMap();
}
@@ -129,8 +136,9 @@
if (SanityManager.DEBUG_ON("memoryLeakTrace")) {
- if (size() > 1000)
- System.out.println("memoryLeakTrace:LockSet: " + size());
+ if (locks.size() > 1000)
+ System.out.println("memoryLeakTrace:LockSet: " +
+ locks.size());
}
}
@@ -150,14 +158,14 @@
gl.grant();
- put(ref, gl);
+ locks.put(ref, gl);
return gl;
}
control = gc.getLockControl();
if (control != gc) {
- put(ref, control);
+ locks.put(ref, control);
}
@@ -550,7 +558,7 @@
if (mayBeEmpty) {
if (control.isEmpty()) {
// no-one granted, no-one waiting, remove lock control
- remove(control.getLockable());
+ locks.remove(control.getLockable());
}
return;
}
@@ -589,12 +597,10 @@
String str = new String();
int i = 0;
- for (Enumeration e = this.elements();
- e.hasMoreElements();
- i++)
+ for (Iterator it = locks.values().iterator(); it.hasNext(); )
{
str += "\n lock[" + i + "]: " +
- DiagnosticUtil.toDiagString(e.nextElement());
+ DiagnosticUtil.toDiagString(it.next());
}
return(str);
@@ -605,18 +611,30 @@
}
}
+ /**
+ * Add all waiters in this lock table to a <code>Dictionary</code> object.
+ * <br>
+ * MT - must be synchronized on this <code>LockSet</code> object.
+ */
+ void addWaiters(Dictionary waiters) {
+ for (Iterator it = locks.values().iterator(); it.hasNext(); ) {
+ Control control = (Control) it.next();
+ control.addWaiters(waiters);
+ }
+ }
+
//EXCLUDE-START-lockdiag-
/*
* make a shallow clone of myself and my lock controls
*/
/* package */
- synchronized LockSet shallowClone()
+ synchronized Map shallowClone()
{
- LockSet clone = new LockSet(factory);
+ HashMap clone = new HashMap();
- for (Enumeration e = keys(); e.hasMoreElements(); )
+ for (Iterator it = locks.keySet().iterator(); it.hasNext(); )
{
- Lockable lockable = (Lockable)e.nextElement();
+ Lockable lockable = (Lockable) it.next();
Control control = getControl(lockable);
clone.put(lockable, control.shallowClone());
@@ -630,25 +648,40 @@
** Support for anyoneBlocked(). These methods assume that caller
** is synchronized on this LockSet object.
*/
+
+ /**
+ * Increase blockCount by one.
+ * <BR>
+ * MT - must be synchronized on this <code>LockSet</code> object.
+ */
void oneMoreWaiter() {
blockCount++;
}
+ /**
+ * Decrease blockCount by one.
+ * <BR>
+ * MT - must be synchronized on this <code>LockSet</code> object.
+ */
void oneLessWaiter() {
blockCount--;
}
- boolean anyoneBlocked() {
+ synchronized boolean anyoneBlocked() {
if (SanityManager.DEBUG) {
SanityManager.ASSERT(
blockCount >= 0, "blockCount should not be negative");
}
- // no synchronization needed because reads of ints are atomic
return blockCount != 0;
}
+ /**
+ * Get the <code>Control</code> for an object in the lock table.
+ * <br>
+ * MT - must be synchronized on this <code>LockSet</code> object.
+ */
public final Control getControl(Lockable ref) {
- return (Control) get(ref);
+ return (Control) locks.get(ref);
}
}
Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/services/locks/LockTableVTI.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/services/locks/LockTableVTI.java?view=diff&rev=498999&r1=498998&r2=498999
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/services/locks/LockTableVTI.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/services/locks/LockTableVTI.java Tue Jan 23 04:08:23 2007
@@ -23,13 +23,13 @@
import org.apache.derby.iapi.services.locks.Latch;
-import java.util.Hashtable;
-import java.util.Vector;
import java.util.Enumeration;
import java.util.NoSuchElementException;
+import java.util.Iterator;
import java.util.ListIterator;
import java.util.List;
+import java.util.Map;
/**
This provides an Enumeration of Latch's
@@ -45,18 +45,15 @@
// its time digesting the information without blocking the real lock
// manager.
- private final LockSet clonedLockTable;
- private final Enumeration outerControl;
+ private final Iterator outerControl;
private Control control;
private ListIterator grantedList;
private ListIterator waitingList;
private Latch nextLock;
- LockTableVTI(LockSet clonedLockTable)
+ LockTableVTI(Map clonedLockTable)
{
- this.clonedLockTable = clonedLockTable;
-
- outerControl = clonedLockTable.elements();
+ outerControl = clonedLockTable.values().iterator();
}
@@ -68,11 +65,11 @@
for (;;) {
if (control == null) {
- if (!outerControl.hasMoreElements())
+ if (!outerControl.hasNext())
return false;
//System.out.println("new control lock ");
- control = (Control) outerControl.nextElement();
+ control = (Control) outerControl.next();
List granted = control.getGranted();
if (granted != null)
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=498999&r1=498998&r2=498999
==============================================================================
--- 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 Jan 23 04:08:23 2007
@@ -422,7 +422,7 @@
// release the lock method.
synchronized (lockTable) {
- Control control = (Control) lockTable.get(ref);
+ Control control = lockTable.getControl(ref);
if (control == null) {
return true;
}