You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2018/04/13 21:11:52 UTC

[03/10] jena git commit: JENA-1521: Don't close. TDB1 and TDB2 datasets are managed differently.

JENA-1521: Don't close. TDB1 and TDB2 datasets are managed differently.

Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/f6d3c77f
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/f6d3c77f
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/f6d3c77f

Branch: refs/heads/master
Commit: f6d3c77f32e5ba8c48d2b987dea3915004970eab
Parents: 32608d2
Author: Andy Seaborne <an...@apache.org>
Authored: Fri Apr 13 14:04:55 2018 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Fri Apr 13 14:04:55 2018 +0100

----------------------------------------------------------------------
 .../jena/tdb2/store/DatasetGraphSwitchable.java | 10 +++++
 .../transaction/DatasetGraphTransaction.java    | 40 ++++++++++----------
 2 files changed, 30 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/f6d3c77f/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/store/DatasetGraphSwitchable.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/store/DatasetGraphSwitchable.java b/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/store/DatasetGraphSwitchable.java
index 60b654a..f27718c 100644
--- a/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/store/DatasetGraphSwitchable.java
+++ b/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/store/DatasetGraphSwitchable.java
@@ -81,6 +81,16 @@ public class DatasetGraphSwitchable extends DatasetGraphWrapper
         return dsgx.getAndSet(dsg);
     }
     
+    /** Don't do anythine on close.
+     *  This would not be safe across switches.  
+     */
+    @Override
+    public void close() {}
+    
+//    /** Don't do anything on sync. */
+//    @Override
+//    public void sync() { }
+    
     /** If and only if the current value is the given old value, set the base {@link DatasetGraph}  
      * Returns true if a swap happened.
      */ 

http://git-wip-us.apache.org/repos/asf/jena/blob/f6d3c77f/jena-tdb/src/main/java/org/apache/jena/tdb/transaction/DatasetGraphTransaction.java
----------------------------------------------------------------------
diff --git a/jena-tdb/src/main/java/org/apache/jena/tdb/transaction/DatasetGraphTransaction.java b/jena-tdb/src/main/java/org/apache/jena/tdb/transaction/DatasetGraphTransaction.java
index bd5ba8b..fbb851b 100644
--- a/jena-tdb/src/main/java/org/apache/jena/tdb/transaction/DatasetGraphTransaction.java
+++ b/jena-tdb/src/main/java/org/apache/jena/tdb/transaction/DatasetGraphTransaction.java
@@ -290,32 +290,32 @@ import org.apache.jena.tdb.store.GraphTxnTDB ;
     protected void _close() {
         if ( isClosed )
             return ;
+        isClosed = true ;
         
-        if ( !sConn.haveUsedInTransaction() ) {
-            synchronized(this) {
-                if ( isClosed ) return ;
-                isClosed = true ;
-                if ( ! sConn.isValid() ) {
-                    // There may be another DatasetGraphTransaction using this location
-                    // and that DatasetGraphTransaction has been closed, invalidating
-                    // the StoreConnection.
-                    return ;
-                }
-                DatasetGraphTDB dsg = sConn.getBaseDataset() ;
-                dsg.sync() ;
-                dsg.close() ;
-                StoreConnection.release(getLocation()) ;
+        if ( sConn.haveUsedInTransaction() ) {
+            if ( isInTransaction() ) {
+                TDB.logInfo.warn("Attempt to close a DatasetGraphTransaction while a transaction is active - ignored close (" + getLocation() + ")") ;
                 return ;
             }
+            // Otherwise ignore - there might be other transactions aronud.
+            return ;
         }
-
-        if ( isInTransaction() ) {
-            TDB.logInfo.warn("Attempt to close a DatasetGraphTransaction while a transaction is active - ignored close (" + getLocation() + ")") ;
+        synchronized(this) {
+            if ( ! sConn.isValid() ) {
+                // There may be another DatasetGraphTransaction using this location
+                // and that DatasetGraphTransaction has been closed, invalidating
+                // the StoreConnection.
+                return ;
+            }
+            DatasetGraphTDB dsg = sConn.getBaseDataset() ;
+            dsg.sync() ;
+            dsg.close() ;
+            StoreConnection.release(getLocation()) ;
+            dsgtxn.remove() ;
+            inTransaction.remove() ;
+            isClosed = true ;
             return ;
         }
-        dsgtxn.remove() ;
-        inTransaction.remove() ;
-        isClosed = true ;
     }
 
     @Override