ozeigermann 2004/10/31 03:32:44
Modified: src/webdav/server/org/apache/slide/webdav/method
MkworkspaceMethod.java UpdateMethod.java
SearchMethod.java BindMethod.java
AbstractWebdavMethod.java LabelMethod.java
UnbindMethod.java RebindMethod.java
Added: lib commons-transaction-20041031.jar
Log:
Made global search lock idea more general and expanded this to
all global write lock methods.
Required modification of commons tx lib with new compatibility mode -
replaced jar with newest version.
Revision Changes Path
1.15 +4 -4
jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/MkworkspaceMethod.java
Index: MkworkspaceMethod.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/MkworkspaceMethod.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- MkworkspaceMethod.java 26 Oct 2004 20:34:47 -0000 1.14
+++ MkworkspaceMethod.java 31 Oct 2004 11:32:39 -0000 1.15
@@ -67,7 +67,7 @@
*/
public void acquireFineGrainLocks() {
// TODO a global write lock is certainly too much, but I have no better
idea (OZ)
- acquireLock("/", WRITE_LOCK);
+ acquireGlobalWriteLock();
}
/**
1.34 +4 -4
jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/UpdateMethod.java
Index: UpdateMethod.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/UpdateMethod.java,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -r1.33 -r1.34
--- UpdateMethod.java 26 Oct 2004 20:34:47 -0000 1.33
+++ UpdateMethod.java 31 Oct 2004 11:32:39 -0000 1.34
@@ -115,7 +115,7 @@
*/
public void acquireFineGrainLocks() {
// TODO a global write lock is certainly too much, but I have no better
idea (OZ)
- acquireLock("/", WRITE_LOCK);
+ acquireGlobalWriteLock();
}
/**
1.50 +4 -4
jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/SearchMethod.java
Index: SearchMethod.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/SearchMethod.java,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -r1.49 -r1.50
--- SearchMethod.java 26 Oct 2004 20:06:01 -0000 1.49
+++ SearchMethod.java 31 Oct 2004 11:32:39 -0000 1.50
@@ -95,7 +95,7 @@
* @see
org.apache.slide.webdav.method.FineGrainedLockingMethod#acquireFineGrainLocks()
*/
public void acquireFineGrainLocks() {
- acquireSearchLock();
+ acquireGlobalReadLock();
}
/**
1.20 +4 -4
jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/BindMethod.java
Index: BindMethod.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/BindMethod.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- BindMethod.java 26 Oct 2004 20:34:47 -0000 1.19
+++ BindMethod.java 31 Oct 2004 11:32:39 -0000 1.20
@@ -73,7 +73,7 @@
*/
public void acquireFineGrainLocks() {
// TODO a global write lock is certainly too much, but I have no better
idea (OZ)
- acquireLock("/", WRITE_LOCK);
+ acquireGlobalWriteLock();
}
/**
1.59 +77 -24
jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/AbstractWebdavMethod.java
Index: AbstractWebdavMethod.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/AbstractWebdavMethod.java,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -r1.58 -r1.59
--- AbstractWebdavMethod.java 29 Oct 2004 20:17:14 -0000 1.58
+++ AbstractWebdavMethod.java 31 Oct 2004 11:32:39 -0000 1.59
@@ -155,12 +155,13 @@
new SimpleDateFormat("EEE MMMM d HH:mm:ss yyyy", Locale.US)
};
+ private static final int LOCK_LOG_LEVEL = Logger.INFO;
+
protected static final int READ_LOCK = 1;
protected static final int WRITE_LOCK = 2;
- private static final int SHARED_SEARCH_LOCK = 1;
- private static final int NO_WRITE_SEARCH_LOCK = 2;
- private static final int EXCLUSIVE_SEARCH_LOCK = 3;
+ private static final int SHARED_LOCK = 1;
+ private static final int EXCLUSIVE_LOCK = 2;
// global read/write lock to allow for deadlock-free access
private static final MultiLevelLock GLOBAL_LOCK = new GenericLock("global",
WRITE_LOCK,
@@ -172,15 +173,12 @@
private static final LockManager FINE_LOCK_MANAGER = new
GenericLockManager(WRITE_LOCK,
new PrintWriterLogger(new PrintWriter(System.out), LOG_CHANNEL, false));
- // global search lock to deny write access while searching
- // XXX setting the highest lock to more than no write looks wrong, but
- // causes two SEARCH methods
- // to execute concurrently which is what we want - the highest lock level
- // will never be acquired
- private static final GenericLock SEARCH_LOCK = new GenericLock("GLOBAL SEARCH",
- WRITE_LOCK + 1, new PrintWriterLogger(new PrintWriter(System.out),
- LOG_CHANNEL, false));
-
+ private static final GenericLock GLOBAL_READ_LOCK = new GenericLock("GLOBAL
READ", EXCLUSIVE_LOCK,
+ new PrintWriterLogger(new PrintWriter(System.out), LOG_CHANNEL, false));
+
+ private static final GenericLock GLOBAL_WRITE_LOCK = new GenericLock("GLOBAL
WRITE", EXCLUSIVE_LOCK,
+ new PrintWriterLogger(new PrintWriter(System.out), LOG_CHANNEL, false));
+
// ----------------------------------------------------- Instance Variables
@@ -910,14 +908,45 @@
}
/**
- * Acquires an exclusive search lock to disallow any writing while searching.
- * Should be used by the search method or any other method that does not allow
- * any writing while running.
- *
+ * Acquires a global read lock to disallow any writing.
+ * Should be used by methods that do not allow any writing while running.
*/
- protected void acquireSearchLock() {
- if (this instanceof WriteMethod) {
- acquireLock(SEARCH_LOCK, NO_WRITE_SEARCH_LOCK);
+ protected void acquireGlobalReadLock() {
+ // we should already have this lock, but just to make sure:
+ synchronized (ATOMIC_LOCKING_MONITOR) {
+ // we have a shared global read lock which means we are compatible with
+ // any other read
+ acquireLock(GLOBAL_READ_LOCK, SHARED_LOCK);
+ // this means no other write request may run in parallel, but if
another global read
+ // has the lock, we will *not* be blocked
+ blockWithLock(GLOBAL_WRITE_LOCK, EXCLUSIVE_LOCK);
+ }
+ }
+
+ /**
+ * Acquires a global write lock to disallow any concurrent access.
+ */
+ protected void acquireGlobalWriteLock() {
+ // we should already have this lock, but just to make sure:
+ synchronized (ATOMIC_LOCKING_MONITOR) {
+ // we really want to read and write alone:
+ acquireLock(GLOBAL_READ_LOCK, EXCLUSIVE_LOCK);
+ acquireLock(GLOBAL_WRITE_LOCK, EXCLUSIVE_LOCK);
+ }
+ }
+
+ /**
+ * Inhibits a global read lock. Should be called by all fine grain writing
methods.
+ */
+ protected void inhibitGlobalReadLock() {
+ // we should already have this lock, but just to make sure:
+ synchronized (ATOMIC_LOCKING_MONITOR) {
+ // we have a shared global write lock which means other fine grained
write
+ // methods are compatible
+ acquireLock(GLOBAL_WRITE_LOCK, SHARED_LOCK);
+ // do not allow global read as long as we write to any resource, but
+ // if another global write has the lock, we will *not* be blocked
+ blockWithLock(GLOBAL_READ_LOCK, EXCLUSIVE_LOCK);
}
}
@@ -963,9 +992,10 @@
if (Configuration.useVersionControl() && path.startsWith(getHistoryPath()))
{
acquireLock(getHistoryPath(), READ_LOCK);
}
- // (4) be sure to write only when no search currently takes place
+ // (4) be sure to write only when no search or other global read currently
takes place
+ // this is the counter part to acquireSearchLock()
if (this instanceof WriteMethod) {
- acquireLock(SEARCH_LOCK, SHARED_SEARCH_LOCK);
+ inhibitGlobalReadLock();
}
}
@@ -1026,7 +1056,29 @@
locks.add(lock);
token.getLogger().log(Thread.currentThread() +
(level == READ_LOCK ? " read" : " write") + " locking "
- + lock.getResourceId().toString(), LOG_CHANNEL,
Logger.INFO);
+ + lock.getResourceId().toString(), LOG_CHANNEL,
LOCK_LOG_LEVEL);
+ }
+
+ /**
+ * Acquires a supporting block lock.
+ *
+ * @param lock
+ * the lock to acquire
+ * @param level
+ * either [EMAIL PROTECTED] #READ_LOCK} or [EMAIL PROTECTED]
#WRITE_LOCK}
+ *
+ * @see #acquireLock(String, int)
+ */
+ protected void blockWithLock(GenericLock lock, int level) {
+ try {
+ lock.acquire(this, level, true,
GenericLock.COMPATIBILITY_REENTRANT_AND_SUPPORT,
+ Long.MAX_VALUE);
+ } catch (InterruptedException e) {
+ }
+ locks.add(lock);
+ token.getLogger().log(
+ Thread.currentThread() + (level == READ_LOCK ? " read" : " write")
+ " locking "
+ + lock.getResourceId().toString(), LOG_CHANNEL,
LOCK_LOG_LEVEL);
}
/**
@@ -1051,8 +1103,9 @@
for (Iterator i = locks.iterator(); i.hasNext();) {
lock = (GenericLock) i.next();
lock.release(this);
- token.getLogger().log(Thread.currentThread() + " releasing " +
lock.getResourceId().toString(), LOG_CHANNEL,
- Logger.INFO);
+ token.getLogger().log(
+ Thread.currentThread() + " releasing " +
lock.getResourceId().toString(),
+ LOG_CHANNEL, LOCK_LOG_LEVEL);
}
}
1.30 +5 -5
jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/LabelMethod.java
Index: LabelMethod.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/LabelMethod.java,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -r1.29 -r1.30
--- LabelMethod.java 26 Oct 2004 20:34:48 -0000 1.29
+++ LabelMethod.java 31 Oct 2004 11:32:40 -0000 1.30
@@ -131,7 +131,7 @@
*/
public void acquireFineGrainLocks() {
// TODO a global write lock is certainly too much, but I have no better
idea (OZ)
- acquireLock("/", WRITE_LOCK);
+ acquireGlobalWriteLock();
}
/**
1.17 +4 -4
jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/UnbindMethod.java
Index: UnbindMethod.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/UnbindMethod.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- UnbindMethod.java 26 Oct 2004 20:34:48 -0000 1.16
+++ UnbindMethod.java 31 Oct 2004 11:32:40 -0000 1.17
@@ -70,7 +70,7 @@
*/
public void acquireFineGrainLocks() {
// TODO a global write lock is certainly too much, but I have no better
idea (OZ)
- acquireLock("/", WRITE_LOCK);
+ acquireGlobalWriteLock();
}
/**
1.18 +4 -4
jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/RebindMethod.java
Index: RebindMethod.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/RebindMethod.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- RebindMethod.java 26 Oct 2004 20:34:48 -0000 1.17
+++ RebindMethod.java 31 Oct 2004 11:32:40 -0000 1.18
@@ -76,7 +76,7 @@
*/
public void acquireFineGrainLocks() {
// TODO a global write lock is certainly too much, but I have no better
idea (OZ)
- acquireLock("/", WRITE_LOCK);
+ acquireGlobalWriteLock();
}
/**
1.1 jakarta-slide/lib/commons-transaction-20041031.jar
<<Binary file>>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]