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/03/06 16:29:52 UTC

[02/12] jena git commit: Align to the style of sparql.core.TransactionalLock.

Align to the style of sparql.core.TransactionalLock.

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

Branch: refs/heads/master
Commit: e58cbcb043ed0c18f9df0f26b2da66c8745e3963
Parents: b75fcce
Author: Andy Seaborne <an...@apache.org>
Authored: Mon Feb 26 16:42:03 2018 +0000
Committer: Andy Seaborne <an...@apache.org>
Committed: Tue Feb 27 23:23:30 2018 +0000

----------------------------------------------------------------------
 .../txn/TransactionalComponentByLock.java       | 127 +++++++++++++++++
 .../dboe/transaction/txn/TransactionalMRSW.java | 137 -------------------
 2 files changed, 127 insertions(+), 137 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/e58cbcb0/jena-db/jena-dboe-transaction/src/main/java/org/apache/jena/dboe/transaction/txn/TransactionalComponentByLock.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-transaction/src/main/java/org/apache/jena/dboe/transaction/txn/TransactionalComponentByLock.java b/jena-db/jena-dboe-transaction/src/main/java/org/apache/jena/dboe/transaction/txn/TransactionalComponentByLock.java
new file mode 100644
index 0000000..879548d
--- /dev/null
+++ b/jena-db/jena-dboe-transaction/src/main/java/org/apache/jena/dboe/transaction/txn/TransactionalComponentByLock.java
@@ -0,0 +1,127 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.dboe.transaction.txn;
+
+import java.nio.ByteBuffer ;
+
+import org.apache.jena.atlas.logging.Log ;
+
+import org.apache.jena.query.ReadWrite ;
+import org.apache.jena.shared.Lock;
+import org.apache.jena.shared.LockMRSW;
+
+//  ** Not used currently **
+/** Implementation of the component interface for {@link TransactionalComponent}.
+ *  Useful for in-memory transactions that do not provide durability or abort (undo). 
+ *  When retro fitting to other systems, that may be the best that can be done. 
+ */
+public class TransactionalComponentByLock extends TransactionalComponentLifecycle<Object> {
+    //See org.apache.jena.sparql.core.TransactionalLock
+    private Lock lock = new LockMRSW();
+    
+    private TransactionalComponentByLock(ComponentId componentId) {
+        super(componentId) ;
+    }
+
+    // ---- Recovery phase
+    @Override
+    public void startRecovery() {}
+    
+    @Override
+    public void recover(ByteBuffer ref) {
+        Log.warn(this, "Called to recover a transaction (ignored)") ; 
+    }
+
+    @Override
+    public void finishRecovery() { }
+    
+    @Override 
+    public void cleanStart() {}
+    
+    @Override
+    protected Object _begin(ReadWrite readWrite, TxnId thisTxnId) {
+        if ( isWriteTxn() )
+            startWriteTxn(); 
+        else 
+            startReadTxn(); 
+        return createState();                    
+    }
+
+    private Object createState() {
+        return new Object();
+    }
+    
+    @Override
+    protected Object _promote(TxnId txnId, Object state) {
+        // We have a read lock, the transaction coordinator has said 
+        // it's OK (from it's point-of-view) to promote so this should succeed.
+        // We have a read lock - there are no other writers.
+        
+        // No lock promotion.
+        // Best we can do is unlock and lock again:-(
+        // This is "read committed"
+        if ( isReadTxn() ) {
+            finishReadTxn();
+            startWriteTxn();
+        }
+        return createState(); 
+    }
+
+    protected void startReadTxn()   { lock.enterCriticalSection(Lock.READ); }
+    protected void startWriteTxn()  { lock.enterCriticalSection(Lock.WRITE); }
+    protected void finishReadTxn()  { lock.leaveCriticalSection(); }
+    protected void finishWriteTxn() { lock.leaveCriticalSection(); }
+
+    @Override
+    protected ByteBuffer _commitPrepare(TxnId txnId, Object obj) {
+        return null ;
+    }
+
+    @Override
+    protected void _commit(TxnId txnId, Object obj) {
+        clearup() ;
+    }
+
+    @Override
+    protected void _commitEnd(TxnId txnId, Object obj) {
+        clearup() ;
+    }
+
+    @Override
+    protected void _abort(TxnId txnId, Object obj) {
+        clearup() ;
+    }
+
+    @Override
+    protected void _complete(TxnId txnId, Object obj) {
+    }
+
+    @Override
+    protected void _shutdown() {
+        lock = null ;
+    }
+
+    private void clearup() {
+        if ( isWriteTxn() )
+            finishWriteTxn(); 
+        else 
+            finishReadTxn(); 
+    }
+}
+

http://git-wip-us.apache.org/repos/asf/jena/blob/e58cbcb0/jena-db/jena-dboe-transaction/src/main/java/org/apache/jena/dboe/transaction/txn/TransactionalMRSW.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-transaction/src/main/java/org/apache/jena/dboe/transaction/txn/TransactionalMRSW.java b/jena-db/jena-dboe-transaction/src/main/java/org/apache/jena/dboe/transaction/txn/TransactionalMRSW.java
deleted file mode 100644
index 0aa741a..0000000
--- a/jena-db/jena-dboe-transaction/src/main/java/org/apache/jena/dboe/transaction/txn/TransactionalMRSW.java
+++ /dev/null
@@ -1,137 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.jena.dboe.transaction.txn;
-
-import java.nio.ByteBuffer ;
-import java.util.concurrent.locks.Lock ;
-import java.util.concurrent.locks.ReadWriteLock ;
-import java.util.concurrent.locks.ReentrantReadWriteLock ;
-
-import org.apache.jena.atlas.logging.Log ;
-
-import org.apache.jena.query.ReadWrite ;
-
-/** Implementation of the component interface for {@link TransactionalComponent}.
- *  Useful for in-memory transactions that do not provide durability or abort (undo). 
- *  When retro fitting to other systems, that may be the best that can be done. 
- */
-public class TransactionalMRSW extends TransactionalComponentLifecycle<Object> {
-    // MRSW implementation of TransactionMVCC
-    // XXX Update to Jena style TransactionalLock
-    private ReadWriteLock lock = new ReentrantReadWriteLock() ;
-    
-    public TransactionalMRSW(ComponentId componentId) {
-        super(componentId) ;
-    }
-
-    // ---- Recovery phase
-    @Override
-    public void startRecovery() {}
-    
-    @Override
-    public void recover(ByteBuffer ref) {
-        Log.warn(this, "Called to recover a transaction (ignored)") ; 
-    }
-
-    @Override
-    public void finishRecovery() { }
-    
-    @Override 
-    public void cleanStart() {}
-    
-    private Lock getLock() {
-        return ( ReadWrite.WRITE.equals(getReadWriteMode()) ) ? lock.writeLock() : lock.readLock() ;
-    }
-    
-    @Override
-    protected Object _begin(ReadWrite readWrite, TxnId thisTxnId) {
-        Lock lock = getLock() ;
-        // This is the point that makes this MRSW (readers OR writer), not MR+SW (readers and a writer)
-        lock.lock();
-        if ( isWriteTxn() )
-            startWriteTxn(); 
-        else 
-            startReadTxn(); 
-        return createState();                    
-    }
-
-    private Object createState() {
-        return new Object();
-    }
-    
-    @Override
-    protected Object _promote(TxnId txnId, Object state) {
-        // We have a read lock, the transaction coordinator has said 
-        // it's OK (from it's point-of-view) to promote so this should succeed.
-        // We have a read lock - theer are no other writers.
-        boolean b = lock.writeLock().tryLock();
-        if ( ! b ) {
-            Log.warn(this, "Failed to promote");  
-            return false;
-        }
-        lock.readLock().unlock(); 
-        return createState(); 
-    }
-
-    // Checks.
-    
-    protected void startReadTxn()   {}
-    protected void startWriteTxn()  {}
-    protected void finishReadTxn()  {}
-    protected void finishWriteTxn() {}
-
-    @Override
-    protected ByteBuffer _commitPrepare(TxnId txnId, Object obj) {
-        return null ;
-    }
-
-    @Override
-    protected void _commit(TxnId txnId, Object obj) {
-        clearup() ;
-    }
-
-    @Override
-    protected void _commitEnd(TxnId txnId, Object obj) {
-        clearup() ;
-    }
-
-    @Override
-    protected void _abort(TxnId txnId, Object obj) {
-        clearup() ;
-    }
-
-    @Override
-    protected void _complete(TxnId txnId, Object obj) {
-    }
-
-    @Override
-    protected void _shutdown() {
-        lock = null ;
-    }
-
-    private void clearup() {
-        Lock lock = getLock() ;
-        if ( isWriteTxn() )
-            finishWriteTxn(); 
-        else 
-            finishReadTxn(); 
-        lock.unlock(); 
-    }
-}
-