directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject [directory-mavibot] 03/03: Switched to Caffeine cache. Fixed some test compilation errors
Date Sat, 30 Dec 2017 21:42:13 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

commit a2980169496da3d256a2a3d71419849ccd0c7aa1
Author: Emmanuel L├ęcharny <elecharny@symas.com>
AuthorDate: Sat Dec 30 22:42:06 2017 +0100

    Switched to Caffeine cache. Fixed some test compilation errors
---
 .../apache/directory/mavibot/btree/BulkLoader.java | 121 ++++++++++-----------
 .../directory/mavibot/btree/RecordManager.java     |  17 +--
 .../directory/mavibot/btree/BTreeBrowseTest.java   |  78 ++++++++++---
 .../directory/mavibot/btree/BulkLoaderTest.java    |  50 +++++----
 .../mavibot/btree/PersistedStoreTest.java          |   6 +-
 .../apache/directory/mavibot/btree/ReadTest.java   |   6 +-
 .../mavibot/btree/RecordManagerFreePageTest.java   |  55 ++++++----
 .../btree/RecordManagerPrivateMethodTest.java      |   2 +-
 8 files changed, 195 insertions(+), 140 deletions(-)

diff --git a/mavibot/src/main/java/org/apache/directory/mavibot/btree/BulkLoader.java b/mavibot/src/main/java/org/apache/directory/mavibot/btree/BulkLoader.java
index b8710a5..b6f818c 100644
--- a/mavibot/src/main/java/org/apache/directory/mavibot/btree/BulkLoader.java
+++ b/mavibot/src/main/java/org/apache/directory/mavibot/btree/BulkLoader.java
@@ -59,7 +59,7 @@ public class BulkLoader<K, V>
     {
     }
 
-    static enum LevelEnum
+    enum LevelEnum
     {
         LEAF,
         NODE
@@ -106,7 +106,7 @@ public class BulkLoader<K, V>
         int nbIteration = 0;
         int nbElems = 0;
         boolean inMemory = true;
-        Set<K> keys = new HashSet<K>();
+        Set<K> keys = new HashSet<>();
 
         while ( true )
         {
@@ -189,45 +189,43 @@ public class BulkLoader<K, V>
     {
         File file = File.createTempFile( "sortedUnique", "data" );
         file.deleteOnExit();
-        FileOutputStream fos = new FileOutputStream( file );
-
         // Number of read elements
         int nbReads = 0;
 
-        // Flush the tuples on disk
-        while ( dataIterator.hasNext() )
+        try ( FileOutputStream fos = new FileOutputStream( file ) )
         {
-            nbReads++;
-
-            // grab a tuple
-            Tuple<K, V> tuple = dataIterator.next();
-
-            // Serialize the key
-            byte[] bytesKey = btree.getKeySerializer().serialize( tuple.key );
-            fos.write( IntSerializer.serialize( bytesKey.length ) );
-            fos.write( bytesKey );
-
-            // Serialize the values
-            V value = tuple.getValue();
-
-            byte[] bytesValue = btree.getValueSerializer().serialize( value );
-
-            // Serialize the value
-            fos.write( IntSerializer.serialize( bytesValue.length ) );
-            fos.write( bytesValue );
+    
+            // Flush the tuples on disk
+            while ( dataIterator.hasNext() )
+            {
+                nbReads++;
+    
+                // grab a tuple
+                Tuple<K, V> tuple = dataIterator.next();
+    
+                // Serialize the key
+                byte[] bytesKey = btree.getKeySerializer().serialize( tuple.key );
+                fos.write( IntSerializer.serialize( bytesKey.length ) );
+                fos.write( bytesKey );
+    
+                // Serialize the values
+                V value = tuple.getValue();
+    
+                byte[] bytesValue = btree.getValueSerializer().serialize( value );
+    
+                // Serialize the value
+                fos.write( IntSerializer.serialize( bytesValue.length ) );
+                fos.write( bytesValue );
+            }
+    
+            fos.flush();
         }
 
-        fos.flush();
-        fos.close();
-
         FileInputStream fis = new FileInputStream( file );
         Iterator<Tuple<K, V>> uniqueIterator = createUniqueFileIterator( btree,
fis );
         SortedFile sortedFile = new SortedFile( file, nbReads );
 
-        Tuple<Iterator<Tuple<K, V>>, SortedFile> result = new Tuple<Iterator<Tuple<K,
V>>, SortedFile>(
-            uniqueIterator, sortedFile );
-
-        return result;
+        return new Tuple<>( uniqueIterator, sortedFile );
     }
 
 
@@ -257,10 +255,10 @@ public class BulkLoader<K, V>
         boolean inMemory = true;
 
         // The list of files we will use to store the sorted chunks
-        List<File> sortedFiles = new ArrayList<File>();
+        List<File> sortedFiles = new ArrayList<>();
 
         // An array of chunkSize tuple max
-        List<Tuple<K, V>> tuples = new ArrayList<Tuple<K, V>>( chunkSize
);
+        List<Tuple<K, V>> tuples = new ArrayList<>( chunkSize );
 
         // Now, start to read all the tuples to sort them. We may use intermediate files
         // for that purpose if we hit the threshold.
@@ -269,7 +267,7 @@ public class BulkLoader<K, V>
         // If the tuple list is empty, we have to process the load based on files, not in
memory
         if ( nbElems > 0 )
         {
-            inMemory = tuples.size() > 0;
+            inMemory = !tuples.isEmpty();
         }
 
         // Now that we have processed all the data, we can start storing them in the btree
@@ -327,7 +325,8 @@ public class BulkLoader<K, V>
      */
     /* no qualifier*/static <K, V> LevelInfo<K, V> computeLevel( BTree<K,
V> btree, int nbElems, LevelEnum levelType )
     {
-        int pageSize = btree.getPageSize();
+        BTreeInfo<K, V> btreeInfo = btree.getBtreeInfo();
+        int pageSize = btree.getPageNbElem();
         int incrementNode = 0;
 
         if ( levelType == LevelEnum.NODE )
@@ -335,7 +334,7 @@ public class BulkLoader<K, V>
             incrementNode = 1;
         }
 
-        LevelInfo<K, V> level = new LevelInfo<K, V>();
+        LevelInfo<K, V> level = new LevelInfo<>();
         level.setType( ( levelType == LevelEnum.NODE ) );
         level.setNbElems( nbElems );
         level.setNbPages( nbElems / ( pageSize + incrementNode ) );
@@ -355,11 +354,11 @@ public class BulkLoader<K, V>
 
             if ( level.isNode() )
             {
-                level.setCurrentPage( BTreeFactory.createNode( btree, 0L, nbElems - 1 ) );
+                level.setCurrentPage( BTreeFactory.createNode( btreeInfo, 0L, nbElems - 1
) );
             }
             else
             {
-                level.setCurrentPage( BTreeFactory.createLeaf( btree, 0L, nbElems ) );
+                level.setCurrentPage( BTreeFactory.createLeaf( btreeInfo, 0L, nbElems ) );
             }
         }
         else
@@ -372,11 +371,11 @@ public class BulkLoader<K, V>
 
                 if ( level.isNode() )
                 {
-                    level.setCurrentPage( BTreeFactory.createNode( btree, 0L, pageSize )
);
+                    level.setCurrentPage( BTreeFactory.createNode( btreeInfo, 0L, pageSize
) );
                 }
                 else
                 {
-                    level.setCurrentPage( BTreeFactory.createLeaf( btree, 0L, pageSize )
);
+                    level.setCurrentPage( BTreeFactory.createLeaf( btreeInfo, 0L, pageSize
) );
                 }
             }
             else
@@ -391,11 +390,11 @@ public class BulkLoader<K, V>
                     {
                         if ( level.isNode() )
                         {
-                            level.setCurrentPage( BTreeFactory.createNode( btree, 0L, pageSize
) );
+                            level.setCurrentPage( BTreeFactory.createNode( btreeInfo, 0L,
pageSize ) );
                         }
                         else
                         {
-                            level.setCurrentPage( BTreeFactory.createLeaf( btree, 0L, pageSize
) );
+                            level.setCurrentPage( BTreeFactory.createLeaf( btreeInfo, 0L,
pageSize ) );
                         }
                     }
                     else
@@ -403,11 +402,11 @@ public class BulkLoader<K, V>
                         if ( level.isNode() )
                         {
                             level
-                                .setCurrentPage( BTreeFactory.createNode( btree, 0L, ( pageSize
/ 2 ) + remaining - 1 ) );
+                                .setCurrentPage( BTreeFactory.createNode( btreeInfo, 0L,
( pageSize / 2 ) + remaining - 1 ) );
                         }
                         else
                         {
-                            level.setCurrentPage( BTreeFactory.createLeaf( btree, 0L, ( pageSize
/ 2 ) + remaining ) );
+                            level.setCurrentPage( BTreeFactory.createLeaf( btreeInfo, 0L,
( pageSize / 2 ) + remaining ) );
                         }
                     }
                 }
@@ -417,11 +416,11 @@ public class BulkLoader<K, V>
 
                     if ( level.isNode() )
                     {
-                        level.setCurrentPage( BTreeFactory.createNode( btree, 0L, pageSize
) );
+                        level.setCurrentPage( BTreeFactory.createNode( btreeInfo, 0L, pageSize
) );
                     }
                     else
                     {
-                        level.setCurrentPage( BTreeFactory.createLeaf( btree, 0L, pageSize
) );
+                        level.setCurrentPage( BTreeFactory.createLeaf( btreeInfo, 0L, pageSize
) );
                     }
                 }
             }
@@ -475,8 +474,8 @@ public class BulkLoader<K, V>
 
     private static <K, V> int computeNbElemsLeaf( BTree<K, V> btree, LevelInfo<K,
V> levelInfo )
     {
-        int pageSize = btree.getPageSize();
-        int remaining = levelInfo.getNbElems() - levelInfo.getNbAddedElems();
+        int pageSize = btree.getPageNbElem();
+        int remaining = levelInfo.getNbElemsLimit() - levelInfo.getNbAddedElems();
 
         if ( remaining < pageSize )
         {
@@ -486,7 +485,7 @@ public class BulkLoader<K, V>
         {
             return pageSize;
         }
-        else if ( remaining > levelInfo.getNbElems() - levelInfo.getNbElemsLimit() )
+        else if ( remaining > levelInfo.getNbElemsLimit() - levelInfo.getNbElemsLimit()
)
         {
             return pageSize;
         }
@@ -502,8 +501,8 @@ public class BulkLoader<K, V>
      */
     /* No qualifier */int computeNbElemsNode( BTree<K, V> btree, LevelInfo<K, V>
levelInfo )
     {
-        int pageSize = btree.getPageSize();
-        int remaining = levelInfo.getNbElems() - levelInfo.getNbAddedElems();
+        int pageSize = btree.getPageNbElem();
+        int remaining = levelInfo.getNbElemsLimit() - levelInfo.getNbAddedElems();
 
         if ( remaining < pageSize + 1 )
         {
@@ -513,7 +512,7 @@ public class BulkLoader<K, V>
         {
             return pageSize + 1;
         }
-        else if ( remaining > levelInfo.getNbElems() - levelInfo.getNbElemsLimit() )
+        else if ( remaining > levelInfo.getNbElemsLimit() - levelInfo.getNbElemsLimit()
)
         {
             return pageSize + 1;
         }
@@ -527,7 +526,7 @@ public class BulkLoader<K, V>
     /**
      * Inject a page reference into the root page.
      */
-    private static <K, V> void injectInRoot( BTree<K, V> btree, Page<K, V>
page, PageHolder<K, V> pageHolder,
+    private static <K, V> void injectInRoot( BTree<K, V> btree, Page<K, V>
page, long child,
         LevelInfo<K, V> level ) throws IOException
     {
         Node<K, V> node = ( Node<K, V> ) level.getCurrentPage();
@@ -772,7 +771,7 @@ public class BulkLoader<K, V>
     }
 
 
-    private static <K, V> BTree<K, V> bulkLoadSinglePage( BTree<K, V> btree,
Iterator<Tuple<K, V>> dataIterator,
+    private static <K, V> BTree<K, V> bulkLoadSinglePage( WriteTransaction writeTransaction,
BTree<K, V> btree, Iterator<Tuple<K, V>> dataIterator,
         int nbElems ) throws IOException
     {
         // Use the root page
@@ -821,15 +820,15 @@ public class BulkLoader<K, V>
      * Construct the target BTree from the sorted data. We will use the nb of elements
      * to determinate the structure of the BTree, as it must be balanced
      */
-    private static <K, V> BTree<K, V> bulkLoad( BTree<K, V> btree, Iterator<Tuple<K,
V>> dataIterator, int nbElems )
+    private static <K, V> BTree<K, V> bulkLoad( WriteTransaction writeTransaction,
BTree<K, V> btree, Iterator<Tuple<K, V>> dataIterator, int nbElems )
         throws IOException
     {
-        int pageSize = btree.getPageSize();
+        int pageSize = btree.getBtreeInfo().getPageNbElem();
 
-        // Special case : we can store all the element sin a single page
+        // Special case : we can store all the elements in a single page
         if ( nbElems <= pageSize )
         {
-            return bulkLoadSinglePage( btree, dataIterator, nbElems );
+            return bulkLoadSinglePage( writeTransaction, btree, dataIterator, nbElems );
         }
 
         // Ok, we will need more than one page to store the elements, which
@@ -1002,7 +1001,7 @@ public class BulkLoader<K, V>
             {} );
 
         // First, eliminate the equals keys. We use a map for that
-        Map<K, V> mapTuples = new HashMap<K, V>();
+        Map<K, V> mapTuples = new HashMap<>();
 
         for ( Tuple<K, V> tuple : tuplesArray )
         {
@@ -1012,13 +1011,13 @@ public class BulkLoader<K, V>
             if ( foundSet != null )
             {
                 // We already have had such a key, add the value to the existing key
-                foundSet.add( tuple.value );
+                foundSet = tuple.value;
             }
             else
             {
                 // No such key present in the map : create a new set to store the values,
                 // and add it in the map associated with the new key
-                V set = new TreeV();
+                V set = new TreeMap<>( );
                 set.add( tuple.value );
                 mapTuples.put( tuple.key, set );
             }
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 d1e04db..24285fe 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
@@ -54,11 +54,9 @@ import org.apache.directory.mavibot.btree.serializer.LongSerializer;
 import org.apache.directory.mavibot.btree.util.Strings;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.ehcache.Cache;
-import org.ehcache.CacheManager;
-import org.ehcache.config.builders.CacheConfigurationBuilder;
-import org.ehcache.config.builders.CacheManagerBuilder;
-import org.ehcache.config.builders.ResourcePoolsBuilder;
+
+import com.github.benmanes.caffeine.cache.Cache;
+import com.github.benmanes.caffeine.cache.Caffeine;
 
 
 /**
@@ -238,12 +236,7 @@ public class RecordManager implements TransactionManager
         }
         
         // Create the cache
-        CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder()
-            .withCache( "pageCache", CacheConfigurationBuilder.
-                newCacheConfigurationBuilder( Long.class, Page.class, 
-                ResourcePoolsBuilder.heap( cacheSize ) ) ).build( true );
-
-        pageCache = cacheManager.getCache( "pageCache", Long.class, Page.class ); 
+        pageCache = Caffeine.newBuilder().maximumSize( cacheSize ).build();
 
         // We have to create a new file, if it does not already exist
         boolean isNewFile = createFile( tmpFile );
@@ -2459,7 +2452,7 @@ public class RecordManager implements TransactionManager
      */
     /* no qualifier */<K, V> Page<K, V> getPage( BTreeInfo btreeInfo, int pageSize,
long offset ) throws IOException
     {
-        Page<K, V> page = ( Page<K, V> )pageCache.get( offset );
+        Page<K, V> page = pageCache.getIfPresent( offset );
         
         if ( page == null )
         {
diff --git a/mavibot/src/test/java/org/apache/directory/mavibot/btree/BTreeBrowseTest.java
b/mavibot/src/test/java/org/apache/directory/mavibot/btree/BTreeBrowseTest.java
index ab2f07f..e45d4f7 100644
--- a/mavibot/src/test/java/org/apache/directory/mavibot/btree/BTreeBrowseTest.java
+++ b/mavibot/src/test/java/org/apache/directory/mavibot/btree/BTreeBrowseTest.java
@@ -41,6 +41,7 @@ import org.apache.directory.mavibot.btree.exception.EndOfFileExceededException;
 import org.apache.directory.mavibot.btree.exception.KeyNotFoundException;
 import org.apache.directory.mavibot.btree.serializer.LongSerializer;
 import org.apache.directory.mavibot.btree.serializer.StringSerializer;
+//import org.ehcache.impl.internal.classes.commonslang.SystemUtils;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Ignore;
@@ -122,8 +123,9 @@ public class BTreeBrowseTest
                 recordManager.close();
             }
 
+            System.out.println( "File : " + dataDir.getAbsolutePath() );
             // Now, try to reload the file back
-            recordManager = new RecordManager( dataDir.getAbsolutePath() );
+            recordManager = new RecordManager( dataDir.getAbsolutePath(), 1024, 1000 );
 
             try ( Transaction transaction = recordManager.beginReadTransaction() )
             {
@@ -652,9 +654,10 @@ public class BTreeBrowseTest
     public void testAddRandom() throws Exception
     {
         // Inject some data
-        long increment = 1_000L;
+        long increment = 100_000L;
         long nbRound = 100_000L;
         long t0 = System.currentTimeMillis();
+        btree.setPageNbElem( 32 );  // Long + String(long) : 8 bytes + [2 - 10] bytes, max,
56 elems/page
 
         long[] values = new long[(int)nbRound];
         
@@ -682,32 +685,79 @@ public class BTreeBrowseTest
 
         long t1 = System.currentTimeMillis();
         
-        System.out.println( "Delta for " + nbRound + " : " + ( t1 - t0 ) );
+        System.out.println( "Delta for " + nbRound + " writes : " + ( t1 - t0 ) );
         
         //MavibotInspector.check( recordManager );
+        long[] counters = new long[12];
+        long smaller = Long.MAX_VALUE;
+        long higher =  0L;
+        long sum = 0L;
+        Random rand = new Random( System.nanoTime() ); 
 
-        int counter = 0;
-
-        try ( Transaction readTxn = recordManager.beginReadTransaction() )
+        for ( int k = 0; k < 12; k++ )
         {
-            BTree<Long, String> btree = readTxn.getBTree( "test" );
-            TupleCursor<Long, String> cursor = btree.browse( readTxn );
+            long tread0 = System.currentTimeMillis();
     
-            while ( cursor.hasNext() )
+            for ( int i = 0; i < 1_00; i++ )
             {
-                cursor.next();
-                counter++;
+                int counter = 0;
+                try ( Transaction readTxn = recordManager.beginReadTransaction() )
+                {
+                    BTree<Long, String> btree = readTxn.getBTree( "test" );
+                    
+                    for ( int j = 0; j < 100_000; j++ )
+                    {
+                        long key = Math.abs( rand.nextLong()%100_000L );
+                        btree.get( readTxn, key );
+                        counter++;
+                    }
+                    
+                    /*
+                    TupleCursor<Long, String> cursor = btree.browse( readTxn );
+            
+                    while ( cursor.hasNext() )
+                    {
+                        cursor.next();
+                        counter++;
+                    }
+                    */
+                }
+            
+                assertEquals( nbRound, counter );
             }
+
+            long tread1 = System.currentTimeMillis();
+
+            System.out.println( "Delta for " + ( nbRound * 1000 ) + " reads[" + k + "] :
" + ( tread1 - tread0 ) );
+            counters[k] = ( tread1 - tread0 );
+            
+            if ( counters[k] < smaller )
+            {
+                smaller = counters[k];
+            }
+            
+            if ( counters[k] > higher )
+            {
+                higher = counters[k];
+            }
+            
+            sum += counters[k];
+            
+            System.out.println( "Hits   : " + recordManager.nbCacheHits );
+            System.out.println( "Misses : " + recordManager.nbCacheMisses );
         }
         
-        assertEquals( nbRound, counter );
+        sum -= smaller;
+        sum -= higher;
         
+        System.out.println( "Average : " + ( sum / 10 ) );
+
         // Now delete the elements
         shuffle( values );
         
         long tt0 = System.currentTimeMillis();
 
-        increment = 1L;
+        //increment = 1L;
         
         for ( long i = 0; i < nbRound/increment; i++ )
         {
@@ -728,7 +778,7 @@ public class BTreeBrowseTest
 
         long tt1 = System.currentTimeMillis();
         
-        System.out.println( "Delta for " + nbRound + " : " + ( tt1 - tt0 ) );
+        System.out.println( "Delta for " + nbRound + " deletes : " + ( tt1 - tt0 ) );
     }
     
     
diff --git a/mavibot/src/test/java/org/apache/directory/mavibot/btree/BulkLoaderTest.java
b/mavibot/src/test/java/org/apache/directory/mavibot/btree/BulkLoaderTest.java
index 657dccc..f2078ef 100644
--- a/mavibot/src/test/java/org/apache/directory/mavibot/btree/BulkLoaderTest.java
+++ b/mavibot/src/test/java/org/apache/directory/mavibot/btree/BulkLoaderTest.java
@@ -921,10 +921,12 @@ public class BulkLoaderTest
         try
         {
             RecordManager rm = new RecordManager( file.getAbsolutePath() );
-            BTree<Long, String> btree = ( BTree<Long, String> ) rm.addBTree(
"test",
-                LongSerializer.INSTANCE, StringSerializer.INSTANCE );
-
-            // btree.valueThresholdUp = 8;
+            
+            try ( WriteTransaction writeTransaction = rm.beginWriteTransaction() )
+            {
+                BTree<Long, String> btree = ( BTree<Long, String> ) rm.addBTree(
writeTransaction, "test",
+                    LongSerializer.INSTANCE, StringSerializer.INSTANCE );
+            }
 
             Iterator<Tuple<Long, String>> tupleIterator = new Iterator<Tuple<Long,
String>>()
             {
@@ -956,29 +958,33 @@ public class BulkLoaderTest
             long t0 = System.currentTimeMillis();
             BTree<Long, String> result = null;
 
-            result = BulkLoader.load( btree, tupleIterator, 128 );
-
-            TupleCursor<Long, String> cursor = result.browse();
-            int nbFetched = 0;
-            Tuple<Long, String> prev = null;
-            Tuple<Long, String> elem = null;
+            result = BulkLoader.load( result, tupleIterator, 128 );
 
-            long t2 = System.currentTimeMillis();
-
-            try
+            try ( Transaction transaction = rm.beginReadTransaction() )
             {
-                while ( cursor.hasNext() )
+                BTree<Long, String> btree = rm.getBtree( transaction, "test" );
+                TupleCursor<Long, String> cursor = result.browse( transaction );
+                int nbFetched = 0;
+                Tuple<Long, String> prev = null;
+                Tuple<Long, String> elem = null;
+    
+                long t2 = System.currentTimeMillis();
+    
+                try
+                {
+                    while ( cursor.hasNext() )
+                    {
+                        prev = elem;
+                        elem = cursor.next();
+                        nbFetched++;
+                    }
+                }
+                catch ( Exception e )
                 {
-                    prev = elem;
-                    elem = cursor.next();
-                    nbFetched++;
+                    System.out.println( "--->" + prev );
+                    e.printStackTrace();
                 }
             }
-            catch ( Exception e )
-            {
-                System.out.println( "--->" + prev );
-                e.printStackTrace();
-            }
 
             long t3 = System.currentTimeMillis();
         }
diff --git a/mavibot/src/test/java/org/apache/directory/mavibot/btree/PersistedStoreTest.java
b/mavibot/src/test/java/org/apache/directory/mavibot/btree/PersistedStoreTest.java
index 07fa0dc..319ab34 100644
--- a/mavibot/src/test/java/org/apache/directory/mavibot/btree/PersistedStoreTest.java
+++ b/mavibot/src/test/java/org/apache/directory/mavibot/btree/PersistedStoreTest.java
@@ -51,7 +51,7 @@ public class PersistedStoreTest
         File tempFile = tempFolder.newFile( "mavibot.db" );
         String tempFileName = tempFile.getAbsolutePath();
 
-        RecordManager recordManager = new RecordManager( tempFileName, 4 * 1024 );
+        RecordManager recordManager = new RecordManager( tempFileName, 4 * 1024, 1000 );
         Method method = RecordManager.class.getDeclaredMethod( "store", RecordManagerHeader.class,
long.class, int.class, PageIO[].class );
         method.setAccessible( true );
 
@@ -143,7 +143,7 @@ public class PersistedStoreTest
         File tempFile = tempFolder.newFile( "mavibot.db" );
         String tempFileName = tempFile.getAbsolutePath();
 
-        RecordManager recordManager = new RecordManager( tempFileName, 4 * 1024 );
+        RecordManager recordManager = new RecordManager( tempFileName, 4 * 1024, 1000 );
         Method method = RecordManager.class.getDeclaredMethod( "store", RecordManagerHeader.class,
long.class, long.class, PageIO[].class );
         method.setAccessible( true );
 
@@ -324,7 +324,7 @@ public class PersistedStoreTest
         String tempFileName = tempFile.getAbsolutePath();
 
         // We use smaller pages
-        RecordManager recordManager = new RecordManager( tempFileName, 32 );
+        RecordManager recordManager = new RecordManager( tempFileName, 32, 1000 );
         Method storeMethod = RecordManager.class.getDeclaredMethod( "store", RecordManagerHeader.class,
long.class, byte[].class, PageIO[].class );
         storeMethod.setAccessible( true );
 
diff --git a/mavibot/src/test/java/org/apache/directory/mavibot/btree/ReadTest.java b/mavibot/src/test/java/org/apache/directory/mavibot/btree/ReadTest.java
index c6af5d3..e142a67 100644
--- a/mavibot/src/test/java/org/apache/directory/mavibot/btree/ReadTest.java
+++ b/mavibot/src/test/java/org/apache/directory/mavibot/btree/ReadTest.java
@@ -55,7 +55,7 @@ public class ReadTest
         String tempFileName = tempFile.getAbsolutePath();
 
         // Create page size of 32 only
-        RecordManager recordManager = new RecordManager( tempFileName, 32 );
+        RecordManager recordManager = new RecordManager( tempFileName, 32, 1000 );
         Method storeMethod = RecordManager.class.getDeclaredMethod( "store", RecordManagerHeader.class,
long.class, int.class, PageIO[].class );
         Method readIntMethod = RecordManager.class.getDeclaredMethod( "readInt", int.class,
PageIO[].class, long.class );
         storeMethod.setAccessible( true );
@@ -133,7 +133,7 @@ public class ReadTest
         String tempFileName = tempFile.getAbsolutePath();
 
         // Create page size of 32 only
-        RecordManager recordManager = new RecordManager( tempFileName, 32 );
+        RecordManager recordManager = new RecordManager( tempFileName, 32, 1000 );
         Method storeMethod = RecordManager.class.getDeclaredMethod( "store", RecordManagerHeader.class,
long.class, long.class, PageIO[].class );
         Method readLongMethod = RecordManager.class.getDeclaredMethod( "readLong", int.class,
PageIO[].class, long.class );
         storeMethod.setAccessible( true );
@@ -245,7 +245,7 @@ public class ReadTest
         String tempFileName = tempFile.getAbsolutePath();
 
         // We use smaller pages
-        RecordManager recordManager = new RecordManager( tempFileName, 32 );
+        RecordManager recordManager = new RecordManager( tempFileName, 32, 1000 );
         Method storeMethod = RecordManager.class.getDeclaredMethod( "store", RecordManagerHeader.class,
long.class, byte[].class, 
             PageIO[].class );
         Method readBytesMethod = RecordManager.class.getDeclaredMethod( "readBytes", int.class,
PageIO[].class, long.class );
diff --git a/mavibot/src/test/java/org/apache/directory/mavibot/btree/RecordManagerFreePageTest.java
b/mavibot/src/test/java/org/apache/directory/mavibot/btree/RecordManagerFreePageTest.java
index 399f05b..562db8c 100644
--- a/mavibot/src/test/java/org/apache/directory/mavibot/btree/RecordManagerFreePageTest.java
+++ b/mavibot/src/test/java/org/apache/directory/mavibot/btree/RecordManagerFreePageTest.java
@@ -66,10 +66,10 @@ public class RecordManagerFreePageTest
 
         openRecordManagerAndBtree();
 
-        try
+        try ( WriteTransaction writeTxn = recordManager1.beginWriteTransaction() )
         {
             // Create a new BTree
-            btree = recordManager1.addBTree( "test", LongSerializer.INSTANCE, StringSerializer.INSTANCE
);
+            btree = recordManager1.addBTree( writeTxn, "test", LongSerializer.INSTANCE, StringSerializer.INSTANCE
);
         }
         catch ( Exception e )
         {
@@ -109,7 +109,10 @@ public class RecordManagerFreePageTest
             // load the last created btree
             if ( btree != null )
             {
-                btree = recordManager1.getBtree( btree.getName() );
+                try ( Transaction transaction = recordManager1.beginReadTransaction() )
+                {
+                    btree = recordManager1.getBtree( transaction, btree.getName() );
+                }
             }
         }
         catch ( Exception e )
@@ -127,7 +130,7 @@ public class RecordManagerFreePageTest
     @Test
     public void testRecordManager() throws IOException, BTreeAlreadyManagedException, KeyNotFoundException,
CursorException
     {
-        assertEquals( 1, recordManager1.getNbManagedTrees() );
+        assertEquals( 3, recordManager1.getNbManagedTrees( recordManager1.getCurrentRecordManagerHeader()
) );
 
         Set<String> managedBTrees = recordManager1.getManagedTrees();
 
@@ -146,18 +149,21 @@ public class RecordManagerFreePageTest
             Long key = ( long ) i;
             String value = Long.toString( key );
 
-            btree.insert( key, value );
-
-            if ( i % 10000 == 0 )
+            try ( WriteTransaction writeTransaction = recordManager1.beginWriteTransaction()
)
             {
-                if ( n > 0 )
+                btree.insert( writeTransaction, key, value );
+    
+                if ( i % 10000 == 0 )
                 {
-                    long t0 = System.currentTimeMillis();
-                    System.out.println( "Written " + i + " elements in : " + ( t0 - delta
) + "ms" );
-                    delta = t0;
+                    if ( n > 0 )
+                    {
+                        long t0 = System.currentTimeMillis();
+                        System.out.println( "Written " + i + " elements in : " + ( t0 - delta
) + "ms" );
+                        delta = t0;
+                    }
+    
+                    n++;
                 }
-
-                n++;
             }
         }
 
@@ -181,24 +187,25 @@ public class RecordManagerFreePageTest
 
         openRecordManagerAndBtree();
 
-        assertEquals( 1, recordManager1.getNbManagedTrees() );
+        assertEquals( 3, recordManager1.getNbManagedTrees( recordManager1.getCurrentRecordManagerHeader()
) );
 
         assertTrue( nbElems == btree.getNbElems() );
-
-        TupleCursor<Long, String> cursor = btree.browse();
-
         long i = 0;
 
-        while ( cursor.hasNext() )
+        try ( Transaction transaction = recordManager1.beginReadTransaction() )
         {
-            Tuple<Long, String> t = cursor.next();
-            assertEquals( ( Long ) i, t.getKey() );
-            assertEquals( String.valueOf( i ), t.getValue() );
-            i++;
+            try ( TupleCursor<Long, String> cursor = btree.browse( transaction ) )
+            {
+                while ( cursor.hasNext() )
+                {
+                    Tuple<Long, String> t = cursor.next();
+                    assertEquals( ( Long ) i, t.getKey() );
+                    assertEquals( String.valueOf( i ), t.getValue() );
+                    i++;
+                }
+            }
         }
 
-        cursor.close();
-
         assertEquals( nbElems, i );
     }
 }
diff --git a/mavibot/src/test/java/org/apache/directory/mavibot/btree/RecordManagerPrivateMethodTest.java
b/mavibot/src/test/java/org/apache/directory/mavibot/btree/RecordManagerPrivateMethodTest.java
index 027f026..2d40e39 100644
--- a/mavibot/src/test/java/org/apache/directory/mavibot/btree/RecordManagerPrivateMethodTest.java
+++ b/mavibot/src/test/java/org/apache/directory/mavibot/btree/RecordManagerPrivateMethodTest.java
@@ -62,7 +62,7 @@ public class RecordManagerPrivateMethodTest
         System.out.println( dataDir + "/mavibot.db" );
 
         // Now, try to reload the file back
-        recordManager = new RecordManager( dataDir.getAbsolutePath(), 32 );
+        recordManager = new RecordManager( dataDir.getAbsolutePath(), 32, 1000 );
 
         // Create a new BTree
         try ( WriteTransaction writeTransaction = recordManager.beginWriteTransaction() )

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

Mime
View raw message