[Mulgara-svn] r579 - in branches/mgr-73: jxdata/iTQL/data_types jxdata/iTQL/standard_queries src/jar/resolver/java/org/mulgara/resolver
andrae at mulgara.org
andrae at mulgara.org
Fri Nov 23 06:16:45 UTC 2007
Author: andrae
Date: 2007-11-23 00:16:44 -0600 (Fri, 23 Nov 2007)
New Revision: 579
Modified:
branches/mgr-73/jxdata/iTQL/data_types/queryResult34.txt
branches/mgr-73/jxdata/iTQL/standard_queries/queryResult17.txt
branches/mgr-73/src/jar/resolver/java/org/mulgara/resolver/DatabaseSession.java
branches/mgr-73/src/jar/resolver/java/org/mulgara/resolver/MulgaraExternalTransactionFactory.java
branches/mgr-73/src/jar/resolver/java/org/mulgara/resolver/MulgaraInternalTransactionFactory.java
branches/mgr-73/src/jar/resolver/java/org/mulgara/resolver/MulgaraTransactionManager.java
Log:
Fixed NPE in DatabaseSession::close that triggered if an unused session was
closed. While fixing this added code to inform the write-lock manager that the
session is closing - this allows it to check that the write-lock /
write-lock-reserve has been properly released and force a release /
transaction-abort if it hasn't.
Also spotted (and fixed) a potential deadlock in the case the write-lock was
reserved, but a failure prevented obtaining the writelock again -
releaseReserve() didn't signal the waiting threads blocked on the write-lock to
allow them to proceed. This deadlock would be automatically broken if another
session tried to obtain the write-lock as the reserve was released and so the
new session would jump the queue - however any waiting sessions would remain
blocked until this.
Modified: branches/mgr-73/jxdata/iTQL/data_types/queryResult34.txt
===================================================================
--- branches/mgr-73/jxdata/iTQL/data_types/queryResult34.txt 2007-11-22 09:39:02 UTC (rev 578)
+++ branches/mgr-73/jxdata/iTQL/data_types/queryResult34.txt 2007-11-23 06:16:44 UTC (rev 579)
@@ -1,5 +1,5 @@
-ItqlInterpreter error - org.mulgara.query.QueryException: Could not commit insert
-Caused by: (QueryException) Could not commit insert
+ItqlInterpreter error - org.mulgara.query.QueryException: Could not commit modify
+Caused by: (QueryException) Could not commit modify
Caused by: (QueryException) org.mulgara.query.MulgaraTransactionException: Transaction rollback triggered
Caused by: (QueryException) org.mulgara.resolver.spi.ResolverException: Unable to read input statements
Caused by: (QueryException) org.mulgara.query.TuplesException: Failed to localize node
Modified: branches/mgr-73/jxdata/iTQL/standard_queries/queryResult17.txt
===================================================================
--- branches/mgr-73/jxdata/iTQL/standard_queries/queryResult17.txt 2007-11-22 09:39:02 UTC (rev 578)
+++ branches/mgr-73/jxdata/iTQL/standard_queries/queryResult17.txt 2007-11-23 06:16:44 UTC (rev 579)
@@ -1,4 +1,4 @@
-ItqlInterpreter error - org.mulgara.query.QueryException: Could not commit insert
-Caused by: (QueryException) Could not commit insert
+ItqlInterpreter error - org.mulgara.query.QueryException: Could not commit modify
+Caused by: (QueryException) Could not commit modify
Caused by: (QueryException) org.mulgara.query.MulgaraTransactionException: Transaction rollback triggered
Caused by: (QueryException) rmi://localhost/server1#nomodelexistswiththisname is not a Model
Modified: branches/mgr-73/src/jar/resolver/java/org/mulgara/resolver/DatabaseSession.java
===================================================================
--- branches/mgr-73/src/jar/resolver/java/org/mulgara/resolver/DatabaseSession.java 2007-11-22 09:39:02 UTC (rev 578)
+++ branches/mgr-73/src/jar/resolver/java/org/mulgara/resolver/DatabaseSession.java 2007-11-23 06:16:44 UTC (rev 579)
@@ -561,9 +561,19 @@
public void close() throws QueryException {
logger.info("Closing session");
try {
- transactionFactory.closingSession(this);
+ if (transactionFactory != null) {
+ transactionFactory.closingSession(this);
+ }
} catch (MulgaraTransactionException em) {
+ logger.error("Error closing session", em);
throw new QueryException("Error closing session. Forced close required", em);
+ } finally {
+ try {
+ transactionManager.closingSession(this);
+ } catch (MulgaraTransactionException em2) {
+ logger.error("Error force-closing session", em2);
+ throw new QueryException("Error force-closing session.", em2);
+ }
}
}
Modified: branches/mgr-73/src/jar/resolver/java/org/mulgara/resolver/MulgaraExternalTransactionFactory.java
===================================================================
--- branches/mgr-73/src/jar/resolver/java/org/mulgara/resolver/MulgaraExternalTransactionFactory.java 2007-11-22 09:39:02 UTC (rev 578)
+++ branches/mgr-73/src/jar/resolver/java/org/mulgara/resolver/MulgaraExternalTransactionFactory.java 2007-11-23 06:16:44 UTC (rev 579)
@@ -200,4 +200,16 @@
associatedTransaction.remove(session);
}
+
+ void abortWriteTransaction() throws MulgaraTransactionException {
+ acquireMutex();
+ try {
+ if (writeTransaction != null) {
+ writeTransaction.abortTransaction("Explicit abort requested by write-lock manager", new Throwable());
+ writeTransaction = null;
+ }
+ } finally {
+ releaseMutex();
+ }
+ }
}
Modified: branches/mgr-73/src/jar/resolver/java/org/mulgara/resolver/MulgaraInternalTransactionFactory.java
===================================================================
--- branches/mgr-73/src/jar/resolver/java/org/mulgara/resolver/MulgaraInternalTransactionFactory.java 2007-11-22 09:39:02 UTC (rev 578)
+++ branches/mgr-73/src/jar/resolver/java/org/mulgara/resolver/MulgaraInternalTransactionFactory.java 2007-11-23 06:16:44 UTC (rev 579)
@@ -392,4 +392,16 @@
logger.warn("Unable to set transaction timeout: " + transactionTimeout, es);
}
}
+
+ void abortWriteTransaction() throws MulgaraTransactionException {
+ acquireMutex();
+ try {
+ if (internalWriteTransaction != null) {
+ internalWriteTransaction.abortTransaction("Explicit abort requested by write-lock manager", new Throwable());
+ internalWriteTransaction = null;
+ }
+ } finally {
+ releaseMutex();
+ }
+ }
}
Modified: branches/mgr-73/src/jar/resolver/java/org/mulgara/resolver/MulgaraTransactionManager.java
===================================================================
--- branches/mgr-73/src/jar/resolver/java/org/mulgara/resolver/MulgaraTransactionManager.java 2007-11-22 09:39:02 UTC (rev 578)
+++ branches/mgr-73/src/jar/resolver/java/org/mulgara/resolver/MulgaraTransactionManager.java 2007-11-23 06:16:44 UTC (rev 579)
@@ -193,14 +193,20 @@
}
void releaseReserve(DatabaseSession session) {
- if (!writeLockReserved()) {
- return;
+ acquireMutex();
+ try {
+ if (!writeLockReserved()) {
+ return;
+ }
+ if (!writeLockReserved(session)) {
+ throw new IllegalStateException("Attempt to release reserve without holding reserve");
+ }
+
+ sessionReservingWriteLock = null;
+ writeLockCondition.signal();
+ } finally {
+ releaseMutex();
}
- if (!writeLockReserved(session)) {
- throw new IllegalStateException("Attempt to release reserve without holding reserve");
- }
-
- sessionReservingWriteLock = null;
}
private boolean writeLockHeld() {
@@ -214,4 +220,42 @@
mutex.unlock();
}
+
+ public void closingSession(DatabaseSession session) throws MulgaraTransactionException {
+ acquireMutex();
+ try {
+ Throwable error = null;
+ if (writeLockReserved(session)) {
+ try {
+ releaseReserve(session);
+ } catch (Throwable th) {
+ logger.error("Error releasing reserve on force-close", th);
+ error = th;
+ }
+ }
+ if (isHoldingWriteLock(session)) {
+ try {
+ releaseWriteLock(session);
+ } catch (Throwable th) {
+ logger.error("Error releasing write-lock on force-close", th);
+ error = th;
+ }
+ }
+ if (error != null) {
+ try {
+ internalFactory.abortWriteTransaction();
+ externalFactory.abortWriteTransaction();
+ } catch (Throwable th) {
+ logger.error("Error aborting writeTransaction", th);
+ }
+ if (error instanceof MulgaraTransactionException) {
+ throw (MulgaraTransactionException)error;
+ } else {
+ throw new MulgaraTransactionException("Error force releasing write-lock", error);
+ }
+ }
+ } finally {
+ releaseMutex();
+ }
+ }
}
More information about the Mulgara-svn
mailing list