db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r447856 - /db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/RAFContainer.java
Date Tue, 19 Sep 2006 14:24:45 GMT
Author: kahatlen
Date: Tue Sep 19 07:24:45 2006
New Revision: 447856

URL: http://svn.apache.org/viewvc?view=rev&rev=447856
Log:
DERBY-801 (partial) Allow parallel access to data files

Backing out the patch for DERBY-733 as it is not needed anymore and
the code is cleaner without it.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/RAFContainer.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/RAFContainer.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/RAFContainer.java?view=diff&rev=447856&r1=447855&r2=447856
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/RAFContainer.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/RAFContainer.java
Tue Sep 19 07:24:45 2006
@@ -55,8 +55,6 @@
 import java.security.AccessController;
 import java.security.PrivilegedExceptionAction;
 import java.security.PrivilegedActionException;
-import java.lang.reflect.Method;
-import java.lang.reflect.Constructor;
 
 /**
 	RAFContainer (short for RandomAccessFileContainer) is a concrete subclass of FileContainer
@@ -97,43 +95,6 @@
 	private boolean inBackup = false;
 	private boolean inRemove = false;
 
-	/* Fields with references to classes and methods in ReentrantLock
-	 * introduced in Java 1.5. Reflection is used to only use these
-     * interfaces if they exist.
-     * 
-     */
-	private static Class fairLockClass;
-	private static Constructor fairLockConstructor;
-	private static Method lock;
-	private static Method unlock;
-	private static boolean hasJava5FairLocks = false;
-
-	// Use reflection to find the constructor, lock() and unlock() in
-	// java.util.concurrent.locks.ReentrantLock. If the class and its
-	// methods are found, hasJava5FairLocks will be true and fair
-	// locking can be used.
-	static {
-		try {
-			fairLockClass = 
-                Class.forName("java.util.concurrent.locks.ReentrantLock");
-
-			fairLockConstructor = 
-                fairLockClass.getConstructor(new Class[] { Boolean.TYPE });
-
-			lock   = fairLockClass.getMethod("lock",   new Class[0]);
-			unlock = fairLockClass.getMethod("unlock", new Class[0]);
-			hasJava5FairLocks = true;
-		}
-		catch (NoSuchMethodException nsme) {}
-		catch (ClassNotFoundException cnfe) {}
-	}
-
-	/**
-	 * Object of type java.util.concurrent.locks.ReentrantLock. It is
-	 * used to prevent starvation when many threads are reading from
-	 * the same file.
-	 */
-	private Object fairLock;
 
 	/*
 	 * Constructors
@@ -141,24 +102,6 @@
 
 	RAFContainer(BaseDataFileFactory factory) {
 		super(factory);
-
-		// If Java 1.5 fair locks are available, construct one.
-		if (hasJava5FairLocks) {
-			try {
-				// construct a lock with fairness set to true
-				fairLock = 
-                    fairLockConstructor.newInstance(
-                        new Object[] { Boolean.TRUE });
-			} catch (Exception e) {
-				// couldn't construct the lock, fall back to old behaviour
-
-				hasJava5FairLocks = false;
-				if (SanityManager.DEBUG) {
-					SanityManager.THROWASSERT(
-                        "failed constructing ReentrantLock", e);
-				}
-			}
-		}
 	}
 
 	/*
@@ -286,51 +229,11 @@
 
 		long pageOffset = pageNumber * pageSize;
 
-		// Use Java 1.5 fair locks if they are available.
-		if (hasJava5FairLocks) {
-			try {
-				lock.invoke(fairLock, null);
-			} catch (Exception e) {
-				// Something bad happened while trying to lock the
-				// region. Since the locking is not required for
-				// anything other than ensuring fairness, it is ok to
-				// fall back to pre-1.5 behaviour.
-				hasJava5FairLocks = false;
-				if (SanityManager.DEBUG) {
-					SanityManager.THROWASSERT(
-                        "failed invoking ReentrantLock.lock()", e);
-				}
-			}
-		}
+		synchronized (this) {
 
-		try {
-			// Starvation might occur at this point if many threads
-			// are waiting for the monitor. This section is therefore
-			// surrounded by calls to ReentrantLock.lock()/unlock() if
-			// we are running Java 1.5 or higher.
-			synchronized (this) {
-				fileData.seek(pageOffset);
-				fileData.readFully(pageData, 0, pageSize);
-			}
-		} finally {
-			// Unlock this section.
-			if (hasJava5FairLocks) {
-				try {
-					unlock.invoke(fairLock, null);
-				} catch (Exception e) {
-					// An error occurred while unlocking the
-					// region. The region might still be locked, so
-					// we'd better stop using this kind of
-					// locking. There will be no loss of
-					// functionality, only a possible loss of
-					// fairness.
-					hasJava5FairLocks = false;
-					if (SanityManager.DEBUG) {
-						SanityManager.THROWASSERT(
-                            "failed invoking ReentrantLock.unlock()", e);
-					}
-				}
-			}
+			fileData.seek(pageOffset);
+
+			fileData.readFully(pageData, 0, pageSize);
 		}
 
 		if (dataFactory.databaseEncrypted() &&



Mime
View raw message