directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1811971 - in /directory/mavibot/branches/single-value/mavibot/src: main/java/org/apache/directory/mavibot/btree/ test/java/org/apache/directory/mavibot/btree/
Date Thu, 12 Oct 2017 14:44:45 GMT
Author: elecharny
Date: Thu Oct 12 14:44:45 2017
New Revision: 1811971

URL: http://svn.apache.org/viewvc?rev=1811971&view=rev
Log:
o Fixed the getManagedTrees() method to return the nb of managed trees
o The RMH.copy() method was not copying the page size
o Added a getBtree() method that does not require the position
o Fixed some failing tests

Modified:
    directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/RecordManager.java
    directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/RecordManagerHeader.java
    directory/mavibot/branches/single-value/mavibot/src/test/java/org/apache/directory/mavibot/btree/PersistedStoreTest.java
    directory/mavibot/branches/single-value/mavibot/src/test/java/org/apache/directory/mavibot/btree/ReadTest.java

Modified: directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/RecordManager.java
URL: http://svn.apache.org/viewvc/directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/RecordManager.java?rev=1811971&r1=1811970&r2=1811971&view=diff
==============================================================================
--- directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/RecordManager.java
(original)
+++ directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/RecordManager.java
Thu Oct 12 14:44:45 2017
@@ -209,7 +209,6 @@ public class RecordManager implements Tr
     {
         // Create the RMH
         RecordManagerHeader recordManagerHeader = new RecordManagerHeader();
-        recordManagerHeaderReference.set( recordManagerHeader );
         
         // Create the map of managed b-trees
         managedBtrees = new LinkedHashMap<>();
@@ -224,6 +223,8 @@ public class RecordManager implements Tr
             recordManagerHeader.pageSize = pageSize;
         }
 
+        recordManagerHeaderReference.set( recordManagerHeader );
+
         recordManagerHeaderBuffer = ByteBuffer.allocate( recordManagerHeader.pageSize );
         recordManagerHeaderBytes = new byte[recordManagerHeader.pageSize];
         recordManagerHeaderSize = recordManagerHeader.pageSize;
@@ -1812,7 +1813,7 @@ public class RecordManager implements Tr
 
         if ( LOG_CHECK.isDebugEnabled() )
         {
-            MavibotInspector.check( this, recordManagerHeader );
+            MavibotInspector.check( this );
         }
 
         return newBtreeHeaderOffset;
@@ -2960,7 +2961,7 @@ public class RecordManager implements Tr
      */
     public Set<String> getManagedTrees()
     {
-        return new HashSet<>( managedBtrees.keySet() );
+        return new HashSet<>( getCurrentRecordManagerHeader().btreeMap.keySet() );
     }
 
 
@@ -3005,17 +3006,33 @@ public class RecordManager implements Tr
 
         if ( LOG_CHECK.isDebugEnabled() )
         {
-            MavibotInspector.check( this, transaction.getRecordManagerHeader() );
+            MavibotInspector.check( this );
         }
     }
 
 
     /**
-     * Get one managed b-tree, knowing its name. It will return the b-tree version
-     * of the given transaction.
+     * Get one managed B-tree, knowing its name. It will return the B-tree latest version.
      *
-     * @param name The b-tree name we are looking for
+     * @param transaction The {@link Transaction} we are running in
+     * @param name The B-tree name we are looking for
      * @return The managed b-tree
+     * @throws IOException If we can't find the B-tree in the file
+     */
+    public <K, V> BTree<K, V> getBtree( Transaction transaction, String name
) throws IOException
+    {
+        return getBtree( transaction, name, 0L );
+    }
+
+
+    /**
+     * Get one managed B-tree, knowing its name and its version. It will return the B-tree
requested version
+     *
+     * @param transaction The {@link Transaction} we are running in
+     * @param name The B-tree name we are looking for
+     * @param revision The B-tree} revision we are looking for (if <=0, the latest one)
+     * @return The managed b-tree
+     * @throws IOException If we can't find the B-tree in the file
      */
     public <K, V> BTree<K, V> getBtree( Transaction transaction, String name,
long revision ) throws IOException
     {
@@ -3033,7 +3050,16 @@ public class RecordManager implements Tr
         BTree<NameRevision, Long> btreeOfBtrees = recordManagerHeader.getBtreeOfBtrees();
         
         // Find the next B-tree reference in the BOB (so revision +1, as we will pick the
prev revision)
-        NameRevision nameRevision = new NameRevision( name, revision + 1L );
+        if ( ( revision <= 0L ) || ( revision == Long.MAX_VALUE ) )
+        {
+            revision = Long.MAX_VALUE;
+        }
+        else
+        {
+            revision++;
+        }
+        
+        NameRevision nameRevision = new NameRevision( name, revision  );
         
         TupleCursor<NameRevision, Long> cursor = btreeOfBtrees.browseFrom( transaction,
nameRevision );
         

Modified: directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/RecordManagerHeader.java
URL: http://svn.apache.org/viewvc/directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/RecordManagerHeader.java?rev=1811971&r1=1811970&r2=1811971&view=diff
==============================================================================
--- directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/RecordManagerHeader.java
(original)
+++ directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/RecordManagerHeader.java
Thu Oct 12 14:44:45 2017
@@ -99,6 +99,7 @@ public class RecordManagerHeader
             copy.copiedPagesBtree = copiedPagesBtree;
             copy.lastOffset = lastOffset;
             copy.idCounter = idCounter;
+            copy.pageSize = pageSize;
             
             // Copy the map
             Map<String, BTree> newBTreeMap = new HashMap<>( btreeMap.size() );

Modified: directory/mavibot/branches/single-value/mavibot/src/test/java/org/apache/directory/mavibot/btree/PersistedStoreTest.java
URL: http://svn.apache.org/viewvc/directory/mavibot/branches/single-value/mavibot/src/test/java/org/apache/directory/mavibot/btree/PersistedStoreTest.java?rev=1811971&r1=1811970&r2=1811971&view=diff
==============================================================================
--- directory/mavibot/branches/single-value/mavibot/src/test/java/org/apache/directory/mavibot/btree/PersistedStoreTest.java
(original)
+++ directory/mavibot/branches/single-value/mavibot/src/test/java/org/apache/directory/mavibot/btree/PersistedStoreTest.java
Thu Oct 12 14:44:45 2017
@@ -52,18 +52,20 @@ public class PersistedStoreTest
         String tempFileName = tempFile.getAbsolutePath();
 
         RecordManager recordManager = new RecordManager( tempFileName, 4 * 1024 );
-        Method method = RecordManager.class.getDeclaredMethod( "store", long.class, int.class,
PageIO[].class );
+        Method method = RecordManager.class.getDeclaredMethod( "store", RecordManagerHeader.class,
long.class, int.class, PageIO[].class );
         method.setAccessible( true );
 
         // Allocate some Pages
         PageIO[] pageIos = new PageIO[2];
         pageIos[0] = new PageIO();
-        pageIos[0].setData( ByteBuffer.allocate( recordManager.getPageSize() ) );
+        pageIos[0].setData( ByteBuffer.allocate( recordManager.getPageSize( 
+            recordManager.getCurrentRecordManagerHeader() ) ) );
         pageIos[1] = new PageIO();
-        pageIos[1].setData( ByteBuffer.allocate( recordManager.getPageSize() ) );
+        pageIos[1].setData( ByteBuffer.allocate( recordManager.getPageSize( 
+            recordManager.getCurrentRecordManagerHeader() ) ) );
 
         // Set the int at the beginning
-        long position = ( Long ) method.invoke( recordManager, 0, 0x12345678, pageIos );
+        long position = ( Long ) method.invoke( recordManager, recordManager.getCurrentRecordManagerHeader(),
0, 0x12345678, pageIos );
 
         assertEquals( 4, position );
         int pos = 12;
@@ -73,7 +75,7 @@ public class PersistedStoreTest
         assertEquals( 0x78, pageIos[0].getData().get( pos++ ) );
 
         // Set the int at the end of the first page
-        position = ( Long ) method.invoke( recordManager, 4080, 0x12345678, pageIos );
+        position = ( Long ) method.invoke( recordManager, recordManager.getCurrentRecordManagerHeader(),
4080, 0x12345678, pageIos );
 
         assertEquals( 4084, position );
         pos = 4092;
@@ -84,7 +86,7 @@ public class PersistedStoreTest
 
         // Set the int at the end of the first page and overlapping on the second page
         // 1 byte overlapping
-        position = ( Long ) method.invoke( recordManager, 4081, 0x12345678, pageIos );
+        position = ( Long ) method.invoke( recordManager, recordManager.getCurrentRecordManagerHeader(),
4081, 0x12345678, pageIos );
 
         assertEquals( 4085, position );
         pos = 4093;
@@ -96,7 +98,7 @@ public class PersistedStoreTest
 
         // Set the int at the end of the first page and overlapping on the second page
         // 2 bytes overlapping
-        position = ( Long ) method.invoke( recordManager, 4082, 0x12345678, pageIos );
+        position = ( Long ) method.invoke( recordManager, recordManager.getCurrentRecordManagerHeader(),
4082, 0x12345678, pageIos );
 
         assertEquals( 4086, position );
         pos = 4094;
@@ -108,7 +110,7 @@ public class PersistedStoreTest
 
         // Set the int at the end of the first page and overlapping on the second page
         // 3 bytes overlapping
-        position = ( Long ) method.invoke( recordManager, 4083, 0x12345678, pageIos );
+        position = ( Long ) method.invoke( recordManager, recordManager.getCurrentRecordManagerHeader(),
4083, 0x12345678, pageIos );
 
         assertEquals( 4087, position );
         pos = 4095;
@@ -119,7 +121,7 @@ public class PersistedStoreTest
         assertEquals( 0x78, pageIos[1].getData().get( pos++ ) );
 
         // Set the int at the beginning of the second page
-        position = ( Long ) method.invoke( recordManager, 4084, 0x12345678, pageIos );
+        position = ( Long ) method.invoke( recordManager, recordManager.getCurrentRecordManagerHeader(),
4084, 0x12345678, pageIos );
 
         assertEquals( 4088, position );
         pos = 8;
@@ -142,18 +144,20 @@ public class PersistedStoreTest
         String tempFileName = tempFile.getAbsolutePath();
 
         RecordManager recordManager = new RecordManager( tempFileName, 4 * 1024 );
-        Method method = RecordManager.class.getDeclaredMethod( "store", long.class, long.class,
PageIO[].class );
+        Method method = RecordManager.class.getDeclaredMethod( "store", RecordManagerHeader.class,
long.class, long.class, PageIO[].class );
         method.setAccessible( true );
 
         // Allocate some Pages
         PageIO[] pageIos = new PageIO[2];
         pageIos[0] = new PageIO();
-        pageIos[0].setData( ByteBuffer.allocate( recordManager.getPageSize() ) );
+        pageIos[0].setData( ByteBuffer.allocate( recordManager.getPageSize( 
+            recordManager.getCurrentRecordManagerHeader() ) ) );
         pageIos[1] = new PageIO();
-        pageIos[1].setData( ByteBuffer.allocate( recordManager.getPageSize() ) );
+        pageIos[1].setData( ByteBuffer.allocate( recordManager.getPageSize( 
+            recordManager.getCurrentRecordManagerHeader() ) ) );
 
         // Set the long at the beginning
-        long position = ( Long ) method.invoke( recordManager, 0, 0x0123456789ABCDEFL, pageIos
);
+        long position = ( Long ) method.invoke( recordManager, recordManager.getCurrentRecordManagerHeader(),
0, 0x0123456789ABCDEFL, pageIos );
 
         assertEquals( 8, position );
         int pos = 12;
@@ -167,7 +171,7 @@ public class PersistedStoreTest
         assertEquals( ( byte ) 0xEF, pageIos[0].getData().get( pos++ ) );
 
         // Set the long at the end of the first page
-        position = ( Long ) method.invoke( recordManager, 4076, 0x0123456789ABCDEFL, pageIos
);
+        position = ( Long ) method.invoke( recordManager, recordManager.getCurrentRecordManagerHeader(),
4076, 0x0123456789ABCDEFL, pageIos );
 
         assertEquals( 4084, position );
         pos = 4088;
@@ -182,7 +186,7 @@ public class PersistedStoreTest
 
         // Set the long at the end of the first page and overlapping on the second page
         // 1 byte overlapping
-        position = ( Long ) method.invoke( recordManager, 4077, 0x0123456789ABCDEFL, pageIos
);
+        position = ( Long ) method.invoke( recordManager, recordManager.getCurrentRecordManagerHeader(),
4077, 0x0123456789ABCDEFL, pageIos );
 
         assertEquals( 4085, position );
         pos = 4089;
@@ -198,7 +202,7 @@ public class PersistedStoreTest
 
         // Set the long at the end of the first page and overlapping on the second page
         // 2 bytes overlapping
-        position = ( Long ) method.invoke( recordManager, 4078, 0x0123456789ABCDEFL, pageIos
);
+        position = ( Long ) method.invoke( recordManager, recordManager.getCurrentRecordManagerHeader(),
4078, 0x0123456789ABCDEFL, pageIos );
 
         assertEquals( 4086, position );
         pos = 4090;
@@ -214,7 +218,7 @@ public class PersistedStoreTest
 
         // Set the long at the end of the first page and overlapping on the second page
         // 3 bytes overlapping
-        position = ( Long ) method.invoke( recordManager, 4079, 0x0123456789ABCDEFL, pageIos
);
+        position = ( Long ) method.invoke( recordManager, recordManager.getCurrentRecordManagerHeader(),
4079, 0x0123456789ABCDEFL, pageIos );
 
         assertEquals( 4087, position );
         pos = 4091;
@@ -230,7 +234,7 @@ public class PersistedStoreTest
 
         // Set the long at the end of the first page and overlapping on the second page
         // 4 byte overlapping
-        position = ( Long ) method.invoke( recordManager, 4080, 0x0123456789ABCDEFL, pageIos
);
+        position = ( Long ) method.invoke( recordManager, recordManager.getCurrentRecordManagerHeader(),
4080, 0x0123456789ABCDEFL, pageIos );
 
         assertEquals( 4088, position );
         pos = 4092;
@@ -246,7 +250,7 @@ public class PersistedStoreTest
 
         // Set the long at the end of the first page and overlapping on the second page
         // 5 bytes overlapping
-        position = ( Long ) method.invoke( recordManager, 4081, 0x0123456789ABCDEFL, pageIos
);
+        position = ( Long ) method.invoke( recordManager, recordManager.getCurrentRecordManagerHeader(),
4081, 0x0123456789ABCDEFL, pageIos );
 
         assertEquals( 4089, position );
         pos = 4093;
@@ -262,7 +266,7 @@ public class PersistedStoreTest
 
         // Set the long at the end of the first page and overlapping on the second page
         // 6 bytes overlapping
-        position = ( Long ) method.invoke( recordManager, 4082, 0x0123456789ABCDEFL, pageIos
);
+        position = ( Long ) method.invoke( recordManager, recordManager.getCurrentRecordManagerHeader(),
4082, 0x0123456789ABCDEFL, pageIos );
 
         assertEquals( 4090, position );
         pos = 4094;
@@ -278,7 +282,7 @@ public class PersistedStoreTest
 
         // Set the long at the end of the first page and overlapping on the second page
         // 7 bytes overlapping
-        position = ( Long ) method.invoke( recordManager, 4083, 0x0123456789ABCDEFL, pageIos
);
+        position = ( Long ) method.invoke( recordManager, recordManager.getCurrentRecordManagerHeader(),
4083, 0x0123456789ABCDEFL, pageIos );
 
         assertEquals( 4091, position );
         pos = 4095;
@@ -293,7 +297,7 @@ public class PersistedStoreTest
         assertEquals( ( byte ) 0xEF, pageIos[1].getData().get( pos++ ) );
 
         // Set the long at the beginning of the second page
-        position = ( Long ) method.invoke( recordManager, 4084, 0x0123456789ABCDEFL, pageIos
);
+        position = ( Long ) method.invoke( recordManager, recordManager.getCurrentRecordManagerHeader(),
4084, 0x0123456789ABCDEFL, pageIos );
 
         assertEquals( 4092, position );
         pos = 8;
@@ -321,17 +325,20 @@ public class PersistedStoreTest
 
         // We use smaller pages
         RecordManager recordManager = new RecordManager( tempFileName, 32 );
-        Method storeMethod = RecordManager.class.getDeclaredMethod( "store", long.class,
byte[].class, PageIO[].class );
+        Method storeMethod = RecordManager.class.getDeclaredMethod( "store", RecordManagerHeader.class,
long.class, byte[].class, PageIO[].class );
         storeMethod.setAccessible( true );
 
         // Allocate some Pages
         PageIO[] pageIos = new PageIO[3];
         pageIos[0] = new PageIO();
-        pageIos[0].setData( ByteBuffer.allocate( recordManager.getPageSize() ) );
+        pageIos[0].setData( ByteBuffer.allocate( recordManager.getPageSize( 
+            recordManager.getCurrentRecordManagerHeader() ) ) );
         pageIos[1] = new PageIO();
-        pageIos[1].setData( ByteBuffer.allocate( recordManager.getPageSize() ) );
+        pageIos[1].setData( ByteBuffer.allocate( recordManager.getPageSize( 
+            recordManager.getCurrentRecordManagerHeader() ) ) );
         pageIos[2] = new PageIO();
-        pageIos[2].setData( ByteBuffer.allocate( recordManager.getPageSize() ) );
+        pageIos[2].setData( ByteBuffer.allocate( recordManager.getPageSize( 
+            recordManager.getCurrentRecordManagerHeader() ) ) );
 //        pageIos[3] = new PageIO();
 //        pageIos[3].setData( ByteBuffer.allocate( recordManager.getPageSize() ) );
 
@@ -340,7 +347,7 @@ public class PersistedStoreTest
             { 0x01, 0x23, 0x45, 0x67 };
 
         // Set the bytes at the beginning
-        long position = ( Long ) storeMethod.invoke( recordManager, 0L, bytes, pageIos );
+        long position = ( Long ) storeMethod.invoke( recordManager, recordManager.getCurrentRecordManagerHeader(),
0L, bytes, pageIos );
 
         assertEquals( 8, position );
         int pos = 12;
@@ -356,7 +363,7 @@ public class PersistedStoreTest
         assertEquals( 0x67, pageIos[0].getData().get( pos++ ) );
 
         // Set the bytes at the end of the first page
-        position = ( Long ) storeMethod.invoke( recordManager, 12L, bytes, pageIos );
+        position = ( Long ) storeMethod.invoke( recordManager, recordManager.getCurrentRecordManagerHeader(),
12L, bytes, pageIos );
 
         assertEquals( 20, position );
         pos = 24;
@@ -379,7 +386,7 @@ public class PersistedStoreTest
             bytes[i] = ( byte ) ( i + 1 );
         }
 
-        position = ( Long ) storeMethod.invoke( recordManager, 0L, bytes, pageIos );
+        position = ( Long ) storeMethod.invoke( recordManager, recordManager.getCurrentRecordManagerHeader(),
0L, bytes, pageIos );
 
         assertEquals( 20, position );
         pos = 12;
@@ -396,7 +403,7 @@ public class PersistedStoreTest
         }
 
         // Write the bytes over 2 pages
-        position = ( Long ) storeMethod.invoke( recordManager, 47L, bytes, pageIos );
+        position = ( Long ) storeMethod.invoke( recordManager, recordManager.getCurrentRecordManagerHeader(),
47L, bytes, pageIos );
 
         assertEquals( 67, position );
         pos = 59;
@@ -425,7 +432,7 @@ public class PersistedStoreTest
             bytes[i] = ( byte ) ( i + 1 );
         }
 
-        position = ( Long ) storeMethod.invoke( recordManager, 2L, bytes, pageIos );
+        position = ( Long ) storeMethod.invoke( recordManager, recordManager.getCurrentRecordManagerHeader(),
2L, bytes, pageIos );
 
         assertEquals( 118, position );
         pos = 14;

Modified: directory/mavibot/branches/single-value/mavibot/src/test/java/org/apache/directory/mavibot/btree/ReadTest.java
URL: http://svn.apache.org/viewvc/directory/mavibot/branches/single-value/mavibot/src/test/java/org/apache/directory/mavibot/btree/ReadTest.java?rev=1811971&r1=1811970&r2=1811971&view=diff
==============================================================================
--- directory/mavibot/branches/single-value/mavibot/src/test/java/org/apache/directory/mavibot/btree/ReadTest.java
(original)
+++ directory/mavibot/branches/single-value/mavibot/src/test/java/org/apache/directory/mavibot/btree/ReadTest.java
Thu Oct 12 14:44:45 2017
@@ -72,7 +72,8 @@ public class ReadTest
         storeMethod.invoke( recordManager, recordManager.getCurrentRecordManagerHeader(),
0, 0x12345678, pageIos );
 
         // Read it back
-        int readValue = ( Integer ) readIntMethod.invoke( recordManager, recordManager.getPageSize(
recordManager.getCurrentRecordManagerHeader() ), pageIos, 0 );
+        int readValue = ( Integer ) readIntMethod.invoke( recordManager, recordManager.getPageSize(

+            recordManager.getCurrentRecordManagerHeader() ), pageIos, 0 );
 
         assertEquals( 0x12345678, readValue );
 
@@ -80,7 +81,8 @@ public class ReadTest
         storeMethod.invoke( recordManager, recordManager.getCurrentRecordManagerHeader(),
16, 0x12345678, pageIos );
 
         // Read it back
-        readValue = ( Integer ) readIntMethod.invoke( recordManager, recordManager.getPageSize(
recordManager.getCurrentRecordManagerHeader() ), pageIos, 16 );
+        readValue = ( Integer ) readIntMethod.invoke( recordManager, recordManager.getPageSize(

+            recordManager.getCurrentRecordManagerHeader() ), pageIos, 16 );
 
         assertEquals( 0x12345678, readValue );
 



Mime
View raw message