jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [01/11] jena git commit: JENA-1223: Have a data version and use to verify promotion.
Date Wed, 17 Aug 2016 16:01:34 GMT
Repository: jena
Updated Branches:
  refs/heads/master 244e0ace7 -> f4915e7f6


JENA-1223: Have a data version and use to verify promotion.

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

Branch: refs/heads/master
Commit: 39a8c3e1cf1f45caf5cc5557643f4cc64ead65b1
Parents: 0142c3b
Author: Andy Seaborne <andy@apache.org>
Authored: Fri Aug 12 21:18:42 2016 +0100
Committer: Andy Seaborne <andy@apache.org>
Committed: Sat Aug 13 15:08:01 2016 +0100

----------------------------------------------------------------------
 .../jena/tdb/transaction/Transaction.java       |  5 +++-
 .../tdb/transaction/TransactionManager.java     | 25 ++++++++++++++------
 .../transaction/AbstractTestNodeTableTrans.java |  2 +-
 .../AbstractTestObjectFileTrans.java            |  2 +-
 .../jena/tdb/transaction/TestTransPromote.java  | 13 ++++++----
 5 files changed, 32 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/39a8c3e1/jena-tdb/src/main/java/org/apache/jena/tdb/transaction/Transaction.java
----------------------------------------------------------------------
diff --git a/jena-tdb/src/main/java/org/apache/jena/tdb/transaction/Transaction.java b/jena-tdb/src/main/java/org/apache/jena/tdb/transaction/Transaction.java
index 76262b0..309abf4 100644
--- a/jena-tdb/src/main/java/org/apache/jena/tdb/transaction/Transaction.java
+++ b/jena-tdb/src/main/java/org/apache/jena/tdb/transaction/Transaction.java
@@ -41,6 +41,7 @@ public class Transaction
     private final List<BlockMgrJournal> blkMgrs = new ArrayList<>() ;
     // The dataset this is a transaction over - may be a commited, pending dataset.
     private final DatasetGraphTDB   basedsg ;
+    private final long version ;
 
     private final List<Iterator<?>> iterators ;     // Tracking iterators 
     private DatasetGraphTxn         activedsg ;
@@ -52,7 +53,7 @@ public class Transaction
     
     private boolean changesPending ;
     
-    public Transaction(DatasetGraphTDB dsg, ReadWrite mode, long id, String label, TransactionManager
txnMgr) {
+    public Transaction(DatasetGraphTDB dsg, long version, ReadWrite mode, long id, String
label, TransactionManager txnMgr) {
         this.id = id ;
         if (label == null )
             label = "Txn" ;
@@ -65,6 +66,7 @@ public class Transaction
         this.label = label ;
         this.txnMgr = txnMgr ;
         this.basedsg = dsg ;
+        this.version = version ;
         this.mode = mode ;
         this.journal = ( txnMgr == null ) ? null : txnMgr.getJournal() ;
         activedsg = null ;      // Don't know yet.
@@ -268,6 +270,7 @@ public class Transaction
     public TransactionManager getTxnMgr()           { return txnMgr ; }
     
     public DatasetGraphTxn getActiveDataset()       { return activedsg ; }
+    public long getVersion()                        { return version ; }
 
     /*package*/ void setActiveDataset(DatasetGraphTxn activedsg) { 
         this.activedsg = activedsg ;

http://git-wip-us.apache.org/repos/asf/jena/blob/39a8c3e1/jena-tdb/src/main/java/org/apache/jena/tdb/transaction/TransactionManager.java
----------------------------------------------------------------------
diff --git a/jena-tdb/src/main/java/org/apache/jena/tdb/transaction/TransactionManager.java
b/jena-tdb/src/main/java/org/apache/jena/tdb/transaction/TransactionManager.java
index 1a65277..efbc764 100644
--- a/jena-tdb/src/main/java/org/apache/jena/tdb/transaction/TransactionManager.java
+++ b/jena-tdb/src/main/java/org/apache/jena/tdb/transaction/TransactionManager.java
@@ -93,6 +93,11 @@ public class TransactionManager
     List<Transaction> commitedAwaitingFlush = new ArrayList<>() ;
     
     static AtomicLong transactionId = new AtomicLong(1) ;
+    // The version of the data starting at 1. The contract is that this is
+    // never the same for two version (it may not be monotonic increasing).
+    // Currently, it is sequentially increasing.
+    // Set on each commit.
+    private AtomicLong version = new AtomicLong(0) ;
     
     // Accessed by SysTxnState
     // These must be AtomicLong
@@ -342,13 +347,18 @@ public class TransactionManager
 //            // Would this block corrctly? ... drops the sync lock?
 //            acquireWriterLock(true) ;
 
-        // 2/ Check the database view has not moved on.
-        DatasetGraphTDB current  = determineBaseDataset() ;
-        DatasetGraphTDB starting = txn.getBaseDataset() ;
-        // Compare by object identity.
-        if ( current != starting )
-            throw new TDBTransactionException("Dataset changed - can't promote") ;
+        // 2/ Check the database view has not moved on. No active writers at the moment.
         
+        if ( txn.getVersion() != version.get() )
+            throw new TDBTransactionException("Dataset changed - can't promote") ;
+
+        // This is an equivalent test.
+//        // Compare by object identity.
+//        DatasetGraphTDB current  = determineBaseDataset() ;
+//        DatasetGraphTDB starting = txn.getBaseDataset() ;
+//        if ( current != starting )
+//            throw new TDBTransactionException("Dataset changed - can't promote") ;
+
         // Need to go through begin for the writers lock. 
         DatasetGraphTxn dsgtxn2 = begin( ReadWrite.WRITE, txn.getLabel()) ;
         return dsgtxn2 ;
@@ -409,7 +419,7 @@ public class TransactionManager
           return dsg ;
       }
     private Transaction createTransaction(DatasetGraphTDB dsg, ReadWrite mode, String label)
{
-        Transaction txn = new Transaction(dsg, mode, transactionId.getAndIncrement(), label,
this) ;
+        Transaction txn = new Transaction(dsg, version.get(), mode, transactionId.getAndIncrement(),
label, this) ;
         return txn ;
     }
 
@@ -452,6 +462,7 @@ public class TransactionManager
         switch ( transaction.getMode() ) {
             case READ: break ;
             case WRITE:
+                version.incrementAndGet() ;
                 currentReaderView.set(null) ;       // Clear the READ transaction cache.
                 releaseWriterLock();
         }

http://git-wip-us.apache.org/repos/asf/jena/blob/39a8c3e1/jena-tdb/src/test/java/org/apache/jena/tdb/transaction/AbstractTestNodeTableTrans.java
----------------------------------------------------------------------
diff --git a/jena-tdb/src/test/java/org/apache/jena/tdb/transaction/AbstractTestNodeTableTrans.java
b/jena-tdb/src/test/java/org/apache/jena/tdb/transaction/AbstractTestNodeTableTrans.java
index bac63dd..c676c39 100644
--- a/jena-tdb/src/test/java/org/apache/jena/tdb/transaction/AbstractTestNodeTableTrans.java
+++ b/jena-tdb/src/test/java/org/apache/jena/tdb/transaction/AbstractTestNodeTableTrans.java
@@ -72,7 +72,7 @@ public abstract class AbstractTestNodeTableTrans extends BaseTest
     
     Transaction createTxn(long id) 
     {
-        return new Transaction(null, ReadWrite.WRITE, id, null, null) ; 
+        return new Transaction(null, 99, ReadWrite.WRITE, id, null, null) ; 
     }
     
     @Test public void nodetrans_01()

http://git-wip-us.apache.org/repos/asf/jena/blob/39a8c3e1/jena-tdb/src/test/java/org/apache/jena/tdb/transaction/AbstractTestObjectFileTrans.java
----------------------------------------------------------------------
diff --git a/jena-tdb/src/test/java/org/apache/jena/tdb/transaction/AbstractTestObjectFileTrans.java
b/jena-tdb/src/test/java/org/apache/jena/tdb/transaction/AbstractTestObjectFileTrans.java
index a1ca123..49dc7ee 100644
--- a/jena-tdb/src/test/java/org/apache/jena/tdb/transaction/AbstractTestObjectFileTrans.java
+++ b/jena-tdb/src/test/java/org/apache/jena/tdb/transaction/AbstractTestObjectFileTrans.java
@@ -49,7 +49,7 @@ public abstract class AbstractTestObjectFileTrans extends BaseTest
     @Before
     public void setup()
     {
-        txn = new Transaction(null, ReadWrite.WRITE, ++count, null, tm) ;
+        txn = new Transaction(null, 5, ReadWrite.WRITE, ++count, null, tm) ;
         file1 = createFile("base") ;
         file2 = createFile("log") ;
     }

http://git-wip-us.apache.org/repos/asf/jena/blob/39a8c3e1/jena-tdb/src/test/java/org/apache/jena/tdb/transaction/TestTransPromote.java
----------------------------------------------------------------------
diff --git a/jena-tdb/src/test/java/org/apache/jena/tdb/transaction/TestTransPromote.java
b/jena-tdb/src/test/java/org/apache/jena/tdb/transaction/TestTransPromote.java
index f843e76..a32ba30 100644
--- a/jena-tdb/src/test/java/org/apache/jena/tdb/transaction/TestTransPromote.java
+++ b/jena-tdb/src/test/java/org/apache/jena/tdb/transaction/TestTransPromote.java
@@ -259,7 +259,8 @@ public class TestTransPromote {
         }) ;
     }
 
-    // Tests for XXX Read-committed yes/no, and whether the other transaction commits or
aborts.
+    // Tests for XXX Read-committed yes/no (false = snapshot isolation, true = read committed),
+    // and whether the other transaction commits (true) or aborts (false).
     
     @Test
     public void promote_10() { promote_readCommit_txnCommit(true, true) ; }
@@ -297,8 +298,9 @@ public class TestTransPromote {
         logger2.setLevel(level2);
     }
     
-    // Test whether a writer casuses a snapshot isolation
-    // promotion to fail like it should
+    // Test whether an active writer causes a snapshot isolation
+    // promotion to fail like it should.
+    // No equivalent read commiter version - it would block. 
     @Test(expected=TDBTransactionException.class)
     public void promote_clash_1() { 
         DatasetGraphTransaction.readCommittedPromotion = false ;
@@ -318,8 +320,9 @@ public class TestTransPromote {
         sema1.acquireUninterruptibly(); 
         // The thread is in the write.
         dsg.begin(ReadWrite.READ) ;
-        // If read commited this will block.
-        // If snapshot, this will though an exception due to the active writer.
+        // ++ If read commited, the promotion will block. ++
+        // because the other-thread writer is blocked. 
+        // If snapshot, this will cause an exception due to the active writer.
         dsg.add(q1) ;
         fail("Should not be here") ;
         dsg.commit() ;


Mime
View raw message