directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject [directory-mavibot] branch single-value updated: Added the transaction list, to be able to have a list of pending revisions when we will be able to clean them up.
Date Tue, 02 Jan 2018 22:45:25 GMT
This is an automated email from the ASF dual-hosted git repository.

elecharny pushed a commit to branch single-value
in repository https://gitbox.apache.org/repos/asf/directory-mavibot.git


The following commit(s) were added to refs/heads/single-value by this push:
     new 79566e1  Added the transaction list, to be able to have a list of pending revisions
when we will be able to clean them up.
79566e1 is described below

commit 79566e1b28efbfb5e4eaeb1a44010137e4932f69
Author: Emmanuel L├ęcharny <elecharny@symas.com>
AuthorDate: Tue Jan 2 23:45:23 2018 +0100

    Added the transaction list, to be able to have a list of pending
    revisions when we will be able to clean them up.
---
 .../directory/mavibot/btree/AbstractTransaction.java   | 16 ++++++++++++++++
 .../directory/mavibot/btree/ReadTransaction.java       | 12 ++++++++++++
 .../apache/directory/mavibot/btree/RecordManager.java  | 12 ++++++++++--
 .../directory/mavibot/btree/RecordManagerHeader.java   |  4 ++++
 .../directory/mavibot/btree/WriteTransaction.java      | 18 ++++++++++++++++++
 5 files changed, 60 insertions(+), 2 deletions(-)

diff --git a/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractTransaction.java
b/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractTransaction.java
index 8e98d34..4e0664a 100644
--- a/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractTransaction.java
+++ b/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractTransaction.java
@@ -183,6 +183,14 @@ public abstract class AbstractTransaction implements Transaction
     public void abort() throws IOException
     {
         aborted = true;
+
+        // Decrement the counter
+        int txnNumber = recordManagerHeader.txnCounter.getAndDecrement();
+
+        if ( ( txnNumber == 0 ) && ( recordManager.transactionsList.peek().revision
!= recordManagerHeader.revision ) )
+        {
+            // We can cleanup 
+        }
     }
 
 
@@ -193,6 +201,14 @@ public abstract class AbstractTransaction implements Transaction
     public void commit() throws IOException
     {
         closed = true;
+        
+        // Decrement the counter
+        int txnNumber = recordManagerHeader.txnCounter.getAndDecrement();
+        
+        if ( ( txnNumber == 0 ) && ( recordManager.transactionsList.peek().revision
!= recordManagerHeader.revision ) )
+        {
+            // We can cleanup 
+        }
     }
     
     
diff --git a/mavibot/src/main/java/org/apache/directory/mavibot/btree/ReadTransaction.java
b/mavibot/src/main/java/org/apache/directory/mavibot/btree/ReadTransaction.java
index d9d0876..947b766 100644
--- a/mavibot/src/main/java/org/apache/directory/mavibot/btree/ReadTransaction.java
+++ b/mavibot/src/main/java/org/apache/directory/mavibot/btree/ReadTransaction.java
@@ -21,6 +21,7 @@ package org.apache.directory.mavibot.btree;
 
 
 import java.io.Closeable;
+import java.io.IOException;
 import java.util.Date;
 
 
@@ -71,6 +72,17 @@ public class ReadTransaction extends AbstractTransaction implements Closeable
 
 
     /**
+     * {@inheritDoc}
+     * @throws IOException
+     */
+    @Override
+    public void close() throws IOException
+    {
+        commit();
+    }
+
+
+    /**
      * @see Object#toString()
      */
     @Override
diff --git a/mavibot/src/main/java/org/apache/directory/mavibot/btree/RecordManager.java b/mavibot/src/main/java/org/apache/directory/mavibot/btree/RecordManager.java
index 24285fe..ba06be0 100644
--- a/mavibot/src/main/java/org/apache/directory/mavibot/btree/RecordManager.java
+++ b/mavibot/src/main/java/org/apache/directory/mavibot/btree/RecordManager.java
@@ -26,6 +26,7 @@ import java.io.RandomAccessFile;
 import java.nio.ByteBuffer;
 import java.nio.channels.FileChannel;
 import java.util.ArrayList;
+import java.util.Deque;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.LinkedHashMap;
@@ -33,6 +34,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Queue;
 import java.util.Set;
+import java.util.concurrent.ConcurrentLinkedDeque;
 import java.util.concurrent.LinkedBlockingQueue;
 import java.util.concurrent.atomic.AtomicLong;
 import java.util.concurrent.atomic.AtomicReference;
@@ -178,6 +180,9 @@ public class RecordManager implements TransactionManager
     
     /** The page cache */
     private Cache<Long, Page> pageCache;
+    
+    /** The active transactions list */
+    Deque<RecordManagerHeader> transactionsList = new ConcurrentLinkedDeque<>();
 
 
 
@@ -598,7 +603,11 @@ public class RecordManager implements TransactionManager
                 Thread.currentThread().getName() );
         }
 
-        return new ReadTransaction( this, timeout );
+        Transaction transaction = new ReadTransaction( this, timeout );
+        
+        transaction.getRecordManagerHeader().txnCounter.getAndIncrement();
+        
+        return transaction;
     }
 
 
@@ -625,7 +634,6 @@ public class RecordManager implements TransactionManager
             TXN_LOG.debug( "..o The current thread already holds the lock" );
         }
 
-        // Create the transaction
         return new WriteTransaction( this );
     }
 
diff --git a/mavibot/src/main/java/org/apache/directory/mavibot/btree/RecordManagerHeader.java
b/mavibot/src/main/java/org/apache/directory/mavibot/btree/RecordManagerHeader.java
index db5ebd0..581e33d 100644
--- a/mavibot/src/main/java/org/apache/directory/mavibot/btree/RecordManagerHeader.java
+++ b/mavibot/src/main/java/org/apache/directory/mavibot/btree/RecordManagerHeader.java
@@ -4,6 +4,7 @@ import java.io.IOException;
 import java.nio.ByteBuffer;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.locks.ReadWriteLock;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
 
@@ -73,6 +74,9 @@ public class RecordManagerHeader
     /** The offset of the end of the file */
     /* no qualifier */long lastOffset = BTreeConstants.NO_PAGE;
     
+    /** The transaction counter */
+    /* no qualifier */ AtomicInteger txnCounter = new AtomicInteger( 0 );
+    
     
     /** The lock used to protect the recordManagerHeader while accessing it */
     private ReadWriteLock lock = new ReentrantReadWriteLock();
diff --git a/mavibot/src/main/java/org/apache/directory/mavibot/btree/WriteTransaction.java
b/mavibot/src/main/java/org/apache/directory/mavibot/btree/WriteTransaction.java
index 8919846..1303223 100644
--- a/mavibot/src/main/java/org/apache/directory/mavibot/btree/WriteTransaction.java
+++ b/mavibot/src/main/java/org/apache/directory/mavibot/btree/WriteTransaction.java
@@ -177,6 +177,24 @@ public class WriteTransaction extends AbstractTransaction
             newPages.clear();
             copiedPageMap.clear();
             super.close();
+
+            // Finally add the new RecordManagerHeader in the transaction list
+            RecordManagerHeader previousRMH = recordManager.transactionsList.peek();
+            
+            recordManager.transactionsList.offerFirst( recordManagerHeader );
+
+            // Corner case : it might be null, if this is the first revision
+            if ( previousRMH != null )
+            {
+                // We may also have to cleanup the previous RMH
+                if ( previousRMH.txnCounter.get() == 0 )
+                {
+                    // Ok, we can get read of it
+                    recordManager.transactionsList.remove( previousRMH );
+                    
+                    // And we can clean it up
+                }
+            }
         }
     }
     

-- 
To stop receiving notification emails like this one, please contact
['"commits@directory.apache.org" <commits@directory.apache.org>'].

Mime
View raw message