jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [2/8] jena git commit: Update transactional usage to full range of modes.
Date Sun, 12 Aug 2018 09:53:52 GMT
Update transactional usage to full range of modes.

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

Branch: refs/heads/master
Commit: ac9c769ae2ccaa8826a2a0e7e83bb9f0b3ebeb72
Parents: 5a51311
Author: Andy Seaborne <andy@apache.org>
Authored: Fri Aug 10 20:43:01 2018 +0100
Committer: Andy Seaborne <andy@apache.org>
Committed: Fri Aug 10 20:43:01 2018 +0100

----------------------------------------------------------------------
 .../apache/jena/fuseki/server/DataService.java  | 48 +++----------
 .../apache/jena/fuseki/servlets/HttpAction.java | 71 ++++++++++----------
 .../jena/fuseki/servlets/REST_Quads_RW.java     |  4 +-
 .../jena/fuseki/servlets/SPARQL_GSP_RW.java     |  6 +-
 .../jena/fuseki/servlets/SPARQL_Update.java     |  2 +-
 5 files changed, 54 insertions(+), 77 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/ac9c769a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/server/DataService.java
----------------------------------------------------------------------
diff --git a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/server/DataService.java
b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/server/DataService.java
index 2644b87..eccc402 100644
--- a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/server/DataService.java
+++ b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/server/DataService.java
@@ -29,7 +29,7 @@ import org.apache.jena.ext.com.google.common.collect.ArrayListMultimap;
 import org.apache.jena.ext.com.google.common.collect.ListMultimap;
 import org.apache.jena.fuseki.DEF ;
 import org.apache.jena.fuseki.Fuseki ;
-import org.apache.jena.query.ReadWrite ;
+import org.apache.jena.query.TxnType;
 import org.apache.jena.sparql.core.DatasetGraph ;
 import org.apache.jena.sparql.core.DatasetGraphFactory ;
 import org.apache.jena.sparql.core.DatasetGraphReadOnly ;
@@ -151,50 +151,24 @@ public class DataService { //implements DatasetMXBean {
         return counters.value(CounterName.RequestsBad) ;
     }
 
-    /** Counter of active read transactions */
-    public AtomicLong   activeReadTxn           = new AtomicLong(0) ;
+    /** Counter of active transactions */
+    public AtomicLong   activeTxn           = new AtomicLong(0) ;
 
-    /** Counter of active write transactions */
-    public AtomicLong   activeWriteTxn          = new AtomicLong(0) ;
+    /** Cumulative counter of transactions */
+    public AtomicLong   totalTxn            = new AtomicLong(0) ;
 
-    /** Cumulative counter of read transactions */
-    public AtomicLong   totalReadTxn            = new AtomicLong(0) ;
-
-    /** Cumulative counter of writer transactions */
-    public AtomicLong   totalWriteTxn           = new AtomicLong(0) ;
-
-    public void startTxn(ReadWrite mode)
-    {
-        switch(mode)
-        {
-            case READ:  
-                activeReadTxn.getAndIncrement() ;
-                totalReadTxn.getAndIncrement() ;
-                break ;
-            case WRITE:
-                activeWriteTxn.getAndIncrement() ;
-                totalWriteTxn.getAndIncrement() ;
-                break ;
-        }
+    public void startTxn(TxnType mode) {
+        activeTxn.getAndIncrement();
+        totalTxn.getAndIncrement();
     }
 
-    public void finishTxn(ReadWrite mode)
-    {
-        switch(mode)
-        {
-            case READ:  
-                activeReadTxn.decrementAndGet() ;
-                break ;
-            case WRITE:
-                activeWriteTxn.decrementAndGet() ;
-                break ;
-        }
-        checkShutdown() ;
+    public void finishTxn() {
+        activeTxn.decrementAndGet();
     }
 
     private void checkShutdown() {
         if ( state == CLOSING ) {
-            if ( activeReadTxn.get() == 0 && activeWriteTxn.get() == 0 )
+            if ( activeTxn.get() == 0 )
                 shutdown() ;
         }
     }

http://git-wip-us.apache.org/repos/asf/jena/blob/ac9c769a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/HttpAction.java
----------------------------------------------------------------------
diff --git a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/HttpAction.java
b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/HttpAction.java
index 79a6a5f..31eb0ca 100644
--- a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/HttpAction.java
+++ b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/HttpAction.java
@@ -18,8 +18,8 @@
 
 package org.apache.jena.fuseki.servlets;
 
-import static org.apache.jena.query.ReadWrite.READ ;
-import static org.apache.jena.query.ReadWrite.WRITE ;
+import static org.apache.jena.query.TxnType.*;
+import static org.apache.jena.query.TxnType.WRITE;
 
 import java.util.HashMap ;
 import java.util.Map ;
@@ -31,7 +31,7 @@ import org.apache.jena.atlas.logging.Log ;
 import org.apache.jena.fuseki.Fuseki ;
 import org.apache.jena.fuseki.FusekiException ;
 import org.apache.jena.fuseki.server.* ;
-import org.apache.jena.query.ReadWrite ;
+import org.apache.jena.query.TxnType;
 import org.apache.jena.sparql.SystemARQ ;
 import org.apache.jena.sparql.core.DatasetGraph ;
 import org.apache.jena.sparql.core.DatasetGraphWrapper ;
@@ -61,7 +61,6 @@ public class HttpAction
     private Transactional   transactional   = null ;
     private boolean         isTransactional = false ;
     private DatasetGraph    activeDSG       = null ;        // Set when inside begin/end.
-    private ReadWrite       activeMode      = null ;        // Set when inside begin/end.
     
     // -- Valid only for administration actions.
     
@@ -270,30 +269,50 @@ public class HttpAction
         return isTransactional ;
     }
 
-    public void beginRead() {
-        activeMode = READ ;
-        transactional.begin(READ) ;
+    public void begin(TxnType txnType) {
+        transactional.begin(txnType);
         activeDSG = dsg ;
-        dataService.startTxn(READ) ;
+        dataService.startTxn(txnType) ;
+    }
+    
+    public void begin() {
+        begin(READ_PROMOTE);
+    }
+
+    public void beginWrite() {
+        begin(WRITE);
+    }
+
+    public void beginRead() {
+        begin(READ);
     }
 
     public void endRead() {
-        dataService.finishTxn(READ) ;
-        activeMode = null ;
+        dataService.finishTxn() ;
+        transactional.commit();
         transactional.end() ;
         activeDSG = null ;
     }
 
-    public void beginWrite() {
-        transactional.begin(WRITE) ;
-        activeMode = WRITE ;
-        activeDSG = dsg ;
-        dataService.startTxn(WRITE) ;
+    public void end() {
+        dataService.finishTxn() ;
+        
+        if ( transactional.isInTransaction() ) {
+            Log.warn(this, "Transaction still active - no commit or abort seen (forced abort)")
;
+            try {
+                transactional.abort() ;
+            } catch (RuntimeException ex) {
+                Log.warn(this, "Exception in forced abort (trying to continue)", ex) ;
+            }
+        }
+        transactional.end() ;
+        activeDSG = null ;
     }
-
+    
     public void commit() {
+        dataService.finishTxn() ;
         transactional.commit() ;
-        activeDSG = null ;
+        end();
     }
 
     public void abort() {
@@ -305,23 +324,7 @@ public class HttpAction
             // we try to continue server operation.
             Log.warn(this, "Exception during abort (operation attempts to continue): "+ex.getMessage())
; 
         }
-        activeDSG = null ;
-    }
-
-    public void endWrite() {
-        dataService.finishTxn(WRITE) ;
-        activeMode = null ;
-
-        if ( transactional.isInTransaction() ) {
-            Log.warn(this, "Transaction still active in endWriter - no commit or abort seen
(forced abort)") ;
-            try {
-                transactional.abort() ;
-            } catch (RuntimeException ex) {
-                Log.warn(this, "Exception in forced abort (trying to continue)", ex) ;
-            }
-        }
-        transactional.end() ;
-        activeDSG = null ;
+        end();
     }
 
     public final void startRequest() { 

http://git-wip-us.apache.org/repos/asf/jena/blob/ac9c769a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/REST_Quads_RW.java
----------------------------------------------------------------------
diff --git a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/REST_Quads_RW.java
b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/REST_Quads_RW.java
index 10e36ac..98589c9 100644
--- a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/REST_Quads_RW.java
+++ b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/REST_Quads_RW.java
@@ -109,7 +109,7 @@ public class REST_Quads_RW extends REST_Quads_R {
             action.abort() ;
             ServletOps.errorOccurred(ex.getMessage()) ;
         } finally {
-            action.endWrite() ;
+            action.end() ;
         }
         ServletOps.uploadResponse(action, details) ;
     }
@@ -143,7 +143,7 @@ public class REST_Quads_RW extends REST_Quads_R {
             } catch (Exception ex2) {}
             ServletOps.errorOccurred(ex.getMessage()) ;
         } finally {
-            action.endWrite() ;
+            action.end() ;
         }
         ServletOps.uploadResponse(action, details) ;
     }

http://git-wip-us.apache.org/repos/asf/jena/blob/ac9c769a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_GSP_RW.java
----------------------------------------------------------------------
diff --git a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_GSP_RW.java
b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_GSP_RW.java
index 7b964e2..4ba5ffe 100644
--- a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_GSP_RW.java
+++ b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_GSP_RW.java
@@ -68,7 +68,7 @@ public class SPARQL_GSP_RW extends SPARQL_GSP_R
             deleteGraph(action) ;
             action.commit() ;
         }
-        finally { action.endWrite() ; }
+        finally { action.end() ; }
         ServletOps.successNoContent(action) ;
     }
 
@@ -143,7 +143,7 @@ public class SPARQL_GSP_RW extends SPARQL_GSP_R
             ServletOps.errorOccurred(ex.getMessage()) ;
             return null ;
         } finally {
-            action.endWrite() ;
+            action.end() ;
         }
     }
     
@@ -188,7 +188,7 @@ public class SPARQL_GSP_RW extends SPARQL_GSP_R
             try { action.abort() ; } catch (Exception ex2) {} 
             ServletOps.errorOccurred(ex.getMessage()) ;
             return null ;            
-        } finally { action.endWrite() ; }
+        } finally { action.end() ; }
     }
     
     /** Delete a graph. This removes the storage choice and looses the setup.

http://git-wip-us.apache.org/repos/asf/jena/blob/ac9c769a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Update.java
----------------------------------------------------------------------
diff --git a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Update.java
b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Update.java
index 539cbf5..2b05907 100644
--- a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Update.java
+++ b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Update.java
@@ -249,7 +249,7 @@ public class SPARQL_Update extends SPARQL_Protocol
                 try { action.abort() ; } catch (Exception ex2) {}
                 ServletOps.errorOccurred(ex.getMessage(), ex) ;
             }
-        } finally { action.endWrite(); }
+        } finally { action.end(); }
     }
 
     /* [It is an error to supply the using-graph-uri or using-named-graph-uri parameters


Mime
View raw message