[
https://issues.apache.org/jira/browse/JENA-1085?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15054993#comment-15054993
]
ASF GitHub Bot commented on JENA-1085:
--------------------------------------
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!"`
> Review transaction finishes for DatasetGraphInMemory
> ----------------------------------------------------
>
> Key: JENA-1085
> URL: https://issues.apache.org/jira/browse/JENA-1085
> Project: Apache Jena
> Issue Type: Task
> Components: ARQ
> Affects Versions: Jena 3.0.1
> Reporter: Andy Seaborne
> Assignee: Andy Seaborne
> Fix For: Jena 3.1.0
>
>
> This JIRA is for a review of the transaction finishing code.
> Some of the code works because of the nature of specific implementations.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)