Github user ajs6f commented on a diff in the pull request:
https://github.com/apache/jena/pull/108#discussion_r47445042
--- Diff:
jena-arq/src/main/java/org/apache/jena/sparql/core/mem/DatasetGraphInMemory.java
---
@@ -125,57 +115,104 @@ public DatasetGraphInMemory(final QuadTable i, final
TripleTable t) {
@Override
public void begin(final ReadWrite readWrite) {
- if (isInTransaction()) throw new
JenaTransactionException("Transactions cannot be nested!");
- transactionType(readWrite);
- isInTransaction(true);
- writeLock().enterCriticalSection(readWrite.equals(READ)); // get
the dataset write lock, if needed.
- commitLock().readLock().lock(); // if a commit is proceeding, wait
so that we see a coherent index state
- try {
+ if (isInTransaction())
+ throw new JenaTransactionException("Transactions cannot be
nested!");
+ startTransaction(readWrite) ;
+ _begin(readWrite) ;
+ }
+
+ private void _begin(ReadWrite readWrite) {
+ withLock(systemLock, () ->{
quadsIndex().begin(readWrite);
defaultGraph().begin(readWrite);
- } finally {
- commitLock().readLock().unlock();
- }
+ }) ;
+ }
+
+ /** Called transaction start code at most once per transaction. */
+ private void startTransaction(ReadWrite mode) {
+ writeLock.enterCriticalSection(mode.equals(READ)); // get the
dataset write lock, if needed.
+ transactionType(mode);
+ isInTransaction(true);
}
+ /** Called transaction ending code at most once per transaction. */
+ private void finishTransaction() {
+ isInTransaction.remove();
+ transactionType.remove();
+ writeLock.leaveCriticalSection();
+ }
+
@Override
public void commit() {
- if (!isInTransaction()) throw new JenaTransactionException("Tried
to commit outside a transaction!");
- commitLock().writeLock().lock();
- try {
+ if (!isInTransaction())
+ throw new JenaTransactionException("Tried to commit outside a
transaction!");
+ if (transactionType().equals(WRITE))
+ _commit();
+ finishTransaction();
+ }
+
+ private void _commit() {
+ withLock(systemLock, () -> {
quadsIndex().commit();
defaultGraph().commit();
- } finally {
- commitLock().writeLock().unlock();
- }
- isInTransaction.remove();
- writeLock().leaveCriticalSection();
+ quadsIndex().end();
+ defaultGraph().end();
+ } ) ;
}
-
+
@Override
public void abort() {
- if (!isInTransaction()) throw new JenaTransactionException("Tried
to abort outside a transaction!");
- end();
+ if (!isInTransaction())
+ throw new JenaTransactionException("Tried to abort outside a
transaction!");
+ if (transactionType().equals(WRITE))
+ _abort();
+ finishTransaction();
}
+ private void _abort() {
+ withLock(systemLock, () -> {
+ quadsIndex().abort();
+ defaultGraph().abort();
+ quadsIndex().end();
+ defaultGraph().end();
+ } ) ;
+ }
+
@Override
public void close() {
- if (isInTransaction()) abort();
+ if (isInTransaction())
+ abort();
}
@Override
public void end() {
if (isInTransaction()) {
- if (transactionType().equals(WRITE))
- log.warn("end() called for WRITE transaction without
commit or abort having been called");
+ if (transactionType().equals(WRITE)) {
+ log.warn("end() called for WRITE transaction without
commit or abort having been called causing a forced abort");
--- End diff --
This message is a tiny bit ambiguous if you don't already understand that
`end` calls `_abort`. Maybe just add a sentence break: `"end() called for WRITE
transaction without commit or abort having been called. This causes a forced
abort!"`
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---