directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1162285 - in /directory/apacheds/trunk/jdbm/src/main/java/jdbm: btree/ recman/
Date Fri, 26 Aug 2011 23:18:04 GMT
Author: elecharny
Date: Fri Aug 26 23:18:04 2011
New Revision: 1162285

URL: http://svn.apache.org/viewvc?rev=1162285&view=rev
Log:
o Added many Javadoc
o Some code formatting
o small improvments
o made some method private

Modified:
    directory/apacheds/trunk/jdbm/src/main/java/jdbm/btree/BTree.java
    directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/BlockIo.java
    directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/DataPage.java
    directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/FileHeader.java
    directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/FreeLogicalRowIdPage.java
    directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/FreeLogicalRowIdPageManager.java
    directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/FreePhysicalRowIdPage.java
    directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/FreePhysicalRowIdPageManager.java
    directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/Location.java
    directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/PageCursor.java
    directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/PageHeader.java
    directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/PhysicalRowIdManager.java
    directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/RecordFile.java
    directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/TranslationPage.java

Modified: directory/apacheds/trunk/jdbm/src/main/java/jdbm/btree/BTree.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm/src/main/java/jdbm/btree/BTree.java?rev=1162285&r1=1162284&r2=1162285&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm/src/main/java/jdbm/btree/BTree.java (original)
+++ directory/apacheds/trunk/jdbm/src/main/java/jdbm/btree/BTree.java Fri Aug 26 23:18:04 2011
@@ -121,7 +121,7 @@ public class BTree<K, V> implements Exte
     private int bTreeHeight;
 
     /** Record id of the root BPage */
-    private transient long rootId;
+    private long rootId;
 
     /** Number of entries in each BPage. */
     protected int pageSize;

Modified: directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/BlockIo.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/BlockIo.java?rev=1162285&r1=1162284&r2=1162285&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/BlockIo.java (original)
+++ directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/BlockIo.java Fri Aug 26 23:18:04 2011
@@ -52,7 +52,6 @@ import java.io.ObjectInput;
 import java.io.ObjectOutput;
 import java.util.concurrent.atomic.AtomicInteger;
 
-
 import org.apache.directory.server.i18n.I18n;
 
 
@@ -364,10 +363,44 @@ public final class BlockIo implements ja
      */
     public String toString() 
     {
-        return "BlockIO ( "
-            + blockId + ", "
-            + dirty   + ", "
-            + view    + " )";
+        if ( view != null )
+        {
+            return view.toString();
+        }
+        
+        StringBuilder sb = new StringBuilder();
+        
+        sb.append( "BlockIO ( " );
+        
+        // The blockID
+        sb.append( blockId ).append( ", " );
+        
+        // Is it dirty ?
+        if ( dirty )
+        {
+            sb.append( "dirty, " );
+        }
+        else
+        {
+            sb.append( "clean, " );
+        }
+        
+        // The view
+        if ( view != null )
+        {
+            sb.append( view.getClass().getSimpleName() ).append( ", " );
+        }
+        else
+        {
+            sb.append( "no view, " );
+        }
+        
+        // The transaction count
+        sb.append( "tx: " ).append( transactionCount.get() );
+
+        sb.append( " )" );
+        
+        return sb.toString();
     }
 
     

Modified: directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/DataPage.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/DataPage.java?rev=1162285&r1=1162284&r2=1162285&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/DataPage.java (original)
+++ directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/DataPage.java Fri Aug 26 23:18:04 2011
@@ -99,7 +99,7 @@ final class DataPage extends PageHeader 
      */
     short getFirst() 
     {
-        return block.readShort( O_FIRST );
+        return blockIo.readShort( O_FIRST );
     }
     
     
@@ -109,11 +109,37 @@ final class DataPage extends PageHeader 
     void setFirst( short value ) 
     {
         paranoiaMagicOk();
+        
         if ( value > 0 && value < O_DATA )
         {
             throw new Error( I18n.err( I18n.ERR_543, value ) );
         }
   
-        block.writeShort( O_FIRST, value );
+        blockIo.writeShort( O_FIRST, value );
+    }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    public String toString() 
+    {
+        StringBuilder sb = new StringBuilder();
+        
+        sb.append( "DataPage ( " );
+        
+        // The blockIO
+        sb.append( super.toString() ).append( ", " );
+        
+        // The first rowId
+        sb.append( "first rowId: " ).append( getFirst() ).append( ", " );
+        
+        // The data per page 
+        sb.append( "[p:" ).append( getPrev() ).append( ", " );
+        
+        // The next page
+        sb.append( "n:" ).append( getNext() ).append( "] )" );
+        
+        return sb.toString();
     }
 }

Modified: directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/FileHeader.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/FileHeader.java?rev=1162285&r1=1162284&r2=1162285&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/FileHeader.java (original)
+++ directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/FileHeader.java Fri Aug 26 23:18:04 2011
@@ -202,4 +202,57 @@ class FileHeader implements BlockView 
     {
         block.writeLong( offsetOfRoot( root ), rowid );
     }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public String toString() 
+    {
+        StringBuilder sb = new StringBuilder();
+        
+        sb.append( "FileHeader ( " );
+        
+        // The blockIO
+        sb.append( block ).append( ", " );
+        
+        // The free pages
+        sb.append( "free[" );
+        sb.append( block.readLong( ( short ) ( 2 + ( 2 * Magic.SZ_LONG * Magic.FREE_PAGE ) ) ) );
+        sb.append( ", " );
+        sb.append( block.readLong( ( short ) ( 2 + ( 2 * Magic.SZ_LONG * Magic.FREE_PAGE )  + Magic.SZ_LONG ) ) );
+        sb.append( "], " );
+
+        // The used pages
+        sb.append( "used[" );
+        sb.append( block.readLong( ( short ) ( 2 + ( 2 * Magic.SZ_LONG * Magic.USED_PAGE ) ) ) );
+        sb.append( ", " );
+        sb.append( block.readLong( ( short ) ( 2 + ( 2 * Magic.SZ_LONG * Magic.USED_PAGE )  + Magic.SZ_LONG ) ) );
+        sb.append( "], " );
+        
+        // The translation pages
+        sb.append( "translation[" );
+        sb.append( block.readLong( ( short ) ( 2 + ( 2 * Magic.SZ_LONG * Magic.TRANSLATION_PAGE ) ) ) );
+        sb.append( ", " );
+        sb.append( block.readLong( ( short ) ( 2 + ( 2 * Magic.SZ_LONG * Magic.TRANSLATION_PAGE )  + Magic.SZ_LONG ) ) );
+        sb.append( "], " );
+
+        // The freeLogIds pages
+        sb.append( "freeLogIds[" );
+        sb.append( block.readLong( ( short ) ( 2 + ( 2 * Magic.SZ_LONG * Magic.FREELOGIDS_PAGE ) ) ) );
+        sb.append( ", " );
+        sb.append( block.readLong( ( short ) ( 2 + ( 2 * Magic.SZ_LONG * Magic.FREELOGIDS_PAGE )  + Magic.SZ_LONG ) ) );
+        sb.append( "], " );
+
+        // The freePhysIds pages
+        sb.append( "freePhysIds[" );
+        sb.append( block.readLong( ( short ) ( 2 + ( 2 * Magic.SZ_LONG * Magic.FREEPHYSIDS_PAGE ) ) ) );
+        sb.append( ", " );
+        sb.append( block.readLong( ( short ) ( 2 + ( 2 * Magic.SZ_LONG * Magic.FREEPHYSIDS_PAGE )  + Magic.SZ_LONG ) ) );
+        sb.append( "]" );
+
+        sb.append( " )" );
+        
+        return sb.toString();
+    }
 }

Modified: directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/FreeLogicalRowIdPage.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/FreeLogicalRowIdPage.java?rev=1162285&r1=1162284&r2=1162285&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/FreeLogicalRowIdPage.java (original)
+++ directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/FreeLogicalRowIdPage.java Fri Aug 26 23:18:04 2011
@@ -59,39 +59,39 @@ class FreeLogicalRowIdPage extends PageH
     /** The offset for the number of free pages */
     private static final short O_COUNT = PageHeader.SIZE; // short count
     
-    /**  */
+    /** Offset of the number of free row Ids */
     static final short O_FREE = O_COUNT + Magic.SZ_SHORT;
     
-    /** */
+    /** The number of elements by page */
     static final short ELEMS_PER_PAGE = ( RecordFile.BLOCK_SIZE - O_FREE ) / PhysicalRowId.SIZE;
 
-    // slots we returned.
+    /** */
     final PhysicalRowId[] slots = new PhysicalRowId[ELEMS_PER_PAGE];
 
     
     /**
      * Constructs a data page view from the indicated block.
      */
-    FreeLogicalRowIdPage( BlockIo block ) 
+    FreeLogicalRowIdPage( BlockIo blockIo ) 
     {
-        super( block );
+        super( blockIo );
     }
     
 
     /**
      * Factory method to create or return a data page for the indicated block.
      */
-    static FreeLogicalRowIdPage getFreeLogicalRowIdPageView( BlockIo block ) 
+    static FreeLogicalRowIdPage getFreeLogicalRowIdPageView( BlockIo blockIo ) 
     {
-        BlockView view = block.getView();
+        BlockView view = blockIo.getView();
         
-        if ( view != null && view instanceof FreeLogicalRowIdPage )
+        if ( ( view != null ) && ( view instanceof FreeLogicalRowIdPage ) )
         {
             return ( FreeLogicalRowIdPage ) view;
         }
         else
         {
-            return new FreeLogicalRowIdPage( block );
+            return new FreeLogicalRowIdPage( blockIo );
         }
     }
 
@@ -101,53 +101,54 @@ class FreeLogicalRowIdPage extends PageH
      */
     short getCount() 
     {
-        return block.readShort( O_COUNT );
+        return blockIo.readShort( O_COUNT );
     }
     
 
     /** 
      * Sets the number of free rowids 
      */
-    private void setCount(short i) 
+    private void setCount( short i ) 
     {
-        block.writeShort(O_COUNT, i);
+        blockIo.writeShort( O_COUNT, i );
     }
     
 
     /** 
      * Frees a slot 
      */
-    void free(int slot) 
+    void free( int slot ) 
     {
-        get(slot).setBlock(0);
-        setCount((short) (getCount() - 1));
+        get( slot ).setBlock( 0 );
+        setCount( (short) ( getCount() - 1 ) );
     }
     
 
     /** 
      * Allocates a slot 
      */
-    PhysicalRowId alloc(int slot) 
+    PhysicalRowId alloc( int slot ) 
     {
-        setCount((short) (getCount() + 1));
-        get(slot).setBlock(-1);
-        return get(slot);
+        setCount( (short) ( getCount() + 1 ) );
+        get( slot ).setBlock( -1 );
+        
+        return get( slot );
     }
     
 
     /** 
      * Returns true if a slot is allocated 
      */
-    boolean isAllocated(int slot) 
+    private boolean isAllocated( int slot ) 
     {
-        return get(slot).getBlock() > 0;
+        return get( slot ).getBlock() > 0;
     }
     
 
     /** 
      * Returns true if a slot is free 
      */
-    boolean isFree(int slot) 
+    private boolean isFree( int slot ) 
     {
         return !isAllocated(slot);
     }
@@ -156,11 +157,11 @@ class FreeLogicalRowIdPage extends PageH
     /** 
      * Returns the value of the indicated slot 
      */
-    PhysicalRowId get(int slot) 
+    PhysicalRowId get( int slot ) 
     {
-        if (slots[slot] == null)
+        if ( slots[slot] == null )
         {
-            slots[slot] = new PhysicalRowId(block, slotToOffset(slot));
+            slots[slot] = new PhysicalRowId( blockIo, slotToOffset( slot ) );
         }
         
         return slots[slot];
@@ -170,9 +171,9 @@ class FreeLogicalRowIdPage extends PageH
     /** 
      * Converts slot to offset 
      */
-    private short slotToOffset(int slot) 
+    private short slotToOffset( int slot ) 
     {
-        return (short) (O_FREE + (slot * PhysicalRowId.SIZE));
+        return (short) ( O_FREE + ( slot * PhysicalRowId.SIZE ) );
     }
     
 
@@ -181,9 +182,9 @@ class FreeLogicalRowIdPage extends PageH
      */
     int getFirstFree() 
     {
-        for (int i = 0; i < ELEMS_PER_PAGE; i++) 
+        for ( int i = 0; i < ELEMS_PER_PAGE; i++ ) 
         {
-            if (isFree(i))
+            if ( isFree( i ) )
             {
                 return i;
             }
@@ -194,13 +195,13 @@ class FreeLogicalRowIdPage extends PageH
     
 
     /**
-     *  Returns first allocated slot, -1 if no slots are available.
+     * @return The first allocated slot, -1 if no slots are available.
      */
     int getFirstAllocated() 
     {
-        for (int i = 0; i < ELEMS_PER_PAGE; i++) 
+        for ( int i = 0; i < ELEMS_PER_PAGE; i++ ) 
         {
-            if (isAllocated(i))
+            if ( isAllocated( i ) )
             {
                 return i;
             }
@@ -208,4 +209,34 @@ class FreeLogicalRowIdPage extends PageH
         
         return -1;
     }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    public String toString() 
+    {
+        StringBuilder sb = new StringBuilder();
+        
+        sb.append( "FreeLogRowIdPage ( " );
+        
+        // The blockIO
+        sb.append( super.toString() ).append( ", " );
+        
+        // The first rowId
+        sb.append( "count: " ).append( getCount() );
+        
+        // Dump the Physical row id
+        for ( int i = 0; i < ELEMS_PER_PAGE; i++ )
+        {
+            if ( slots[i] != null )
+            {
+                sb.append( ", [" ).append( i ).append( "]=<" ).append( slots[i].getBlock() ).append( ", " ).append( slots[i].getOffset() ).append( ">" );
+            }
+        }
+
+        sb.append( ")" );
+
+        return sb.toString();
+    }
 }

Modified: directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/FreeLogicalRowIdPageManager.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/FreeLogicalRowIdPageManager.java?rev=1162285&r1=1162284&r2=1162285&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/FreeLogicalRowIdPageManager.java (original)
+++ directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/FreeLogicalRowIdPageManager.java Fri Aug 26 23:18:04 2011
@@ -55,9 +55,10 @@ import java.io.IOException;
  */
 final class FreeLogicalRowIdPageManager 
 {
-    // our record recordFile
+    /** our record recordFile */
     private RecordFile recordFile;
-    // our page manager
+    
+    /** our page manager */
     private PageManager pageManager;
 
     /**
@@ -78,39 +79,45 @@ final class FreeLogicalRowIdPageManager 
     {
         // Loop through the free Logical rowid list until we find
         // the first rowid.
-        Location retval = null;
-        PageCursor curs = new PageCursor(pageManager, Magic.FREELOGIDS_PAGE);
+        // Create a cursor to browse the pages
+        PageCursor cursor = new PageCursor( pageManager, Magic.FREELOGIDS_PAGE );
         
-        while (curs.next() != 0) 
+        // Loop on the pages now
+        while ( cursor.next() != 0 ) 
         {
-            FreeLogicalRowIdPage fp = FreeLogicalRowIdPage
-                .getFreeLogicalRowIdPageView( recordFile.get( curs.getCurrent() ) );
+            // Get the blockIo associated with the blockId
+            BlockIo blockIo = recordFile.get( cursor.getBlockId() );
+            FreeLogicalRowIdPage fp = FreeLogicalRowIdPage.getFreeLogicalRowIdPageView( blockIo );
+            
+            // Get the first allocated FreeLogicalRowId
             int slot = fp.getFirstAllocated();
             
             if ( slot != -1 ) 
             {
                 // got one!
-                retval = new Location( fp.get( slot ) );
-                fp.free(slot);
+                Location location = new Location( fp.get( slot ) );
+                
+                // Remove the block from the page
+                fp.free( slot );
+                
+                boolean hasMore = fp.getCount() != 0;
                 
-                if ( fp.getCount() == 0 ) 
+                // Upate the recordFile
+                recordFile.release( cursor.getBlockId(), hasMore );
+
+                if ( !hasMore ) 
                 {
                     // page became empty - free it
-                    recordFile.release(curs.getCurrent(), false);
-                    pageManager.free(Magic.FREELOGIDS_PAGE, curs.getCurrent());
+                    pageManager.free( Magic.FREELOGIDS_PAGE, cursor.getBlockId() );
                 }
-                else
-                {
-                    recordFile.release(curs.getCurrent(), true);
-                }    
                 
-                return retval;
+                return location;
             }
             else 
             {
                 // no luck, go to next page
-                recordFile.release(curs.getCurrent(), false);
-            }     
+                recordFile.release( cursor.getBlockId(), false );
+            }
         }
         
         return null;
@@ -119,19 +126,24 @@ final class FreeLogicalRowIdPageManager 
     
     /**
      *  Puts the indicated rowid on the free list
+     *  
+     *  @param rowId The Location where we will store the rowId
      */
-    void put(Location rowid) throws IOException 
+    void put( Location rowId ) throws IOException 
     {
         
         PhysicalRowId free = null;
-        PageCursor curs = new PageCursor(pageManager, Magic.FREELOGIDS_PAGE);
+        
+        // Create a cursor on the FREELOGIDs list
+        PageCursor curs = new PageCursor( pageManager, Magic.FREELOGIDS_PAGE );
         long freePage = 0;
         
-        while (curs.next() != 0) 
+        // Loop on all the list
+        while ( curs.next() != 0 )
         {
-            freePage = curs.getCurrent();
-            BlockIo curBlock = recordFile.get(freePage);
-            FreeLogicalRowIdPage fp = FreeLogicalRowIdPage.getFreeLogicalRowIdPageView(curBlock);
+            freePage = curs.getBlockId();
+            BlockIo curBlockIo = recordFile.get( freePage );
+            FreeLogicalRowIdPage fp = FreeLogicalRowIdPage.getFreeLogicalRowIdPageView( curBlockIo );
             int slot = fp.getFirstFree();
             
             if ( slot != -1 ) 
@@ -140,20 +152,20 @@ final class FreeLogicalRowIdPageManager 
                 break;
             }
             
-            recordFile.release(curBlock);
+            recordFile.release( curBlockIo );
         }
         
-        if (free == null) 
+        if ( free == null ) 
         {
             // No more space on the free list, add a page.
-            freePage = pageManager.allocate(Magic.FREELOGIDS_PAGE);
-            BlockIo curBlock = recordFile.get(freePage);
-            FreeLogicalRowIdPage fp = FreeLogicalRowIdPage.getFreeLogicalRowIdPageView(curBlock);
-            free = fp.alloc(0);
+            freePage = pageManager.allocate( Magic.FREELOGIDS_PAGE );
+            BlockIo curBlockIo = recordFile.get( freePage );
+            FreeLogicalRowIdPage fp = FreeLogicalRowIdPage.getFreeLogicalRowIdPageView( curBlockIo );
+            free = fp.alloc( 0 );
         }
         
-        free.setBlock(rowid.getBlock());
-        free.setOffset(rowid.getOffset());
-        recordFile.release(freePage, true);
+        free.setBlock( rowId.getBlock() );
+        free.setOffset( rowId.getOffset() );
+        recordFile.release( freePage, true );
     }
-}
+}
\ No newline at end of file

Modified: directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/FreePhysicalRowIdPage.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/FreePhysicalRowIdPage.java?rev=1162285&r1=1162284&r2=1162285&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/FreePhysicalRowIdPage.java (original)
+++ directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/FreePhysicalRowIdPage.java Fri Aug 26 23:18:04 2011
@@ -94,7 +94,7 @@ final class FreePhysicalRowIdPage extend
      */
     short getCount() 
     {
-        return block.readShort( O_COUNT );
+        return blockIo.readShort( O_COUNT );
     }
 
     
@@ -103,7 +103,7 @@ final class FreePhysicalRowIdPage extend
      */
     private void setCount( short i ) 
     {
-        block.writeShort( O_COUNT, i );
+        blockIo.writeShort( O_COUNT, i );
     }
 
     
@@ -152,7 +152,7 @@ final class FreePhysicalRowIdPage extend
     {
         if ( slots[slot] == null )
         {
-            slots[slot] = new FreePhysicalRowId( block, slotToOffset( slot ) ) ;
+            slots[slot] = new FreePhysicalRowId( blockIo, slotToOffset( slot ) ) ;
         }
   
         return slots[slot];
@@ -201,4 +201,37 @@ final class FreePhysicalRowIdPage extend
   
         return -1;
     }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    public String toString() 
+    {
+        StringBuilder sb = new StringBuilder();
+        
+        sb.append( "FreePhysRowIdPage ( " );
+        
+        // The blockIO
+        sb.append( super.toString() ).append( ", " );
+        
+        // The first rowId
+        sb.append( "count: " ).append( getCount() );
+        
+        // Dump the Physical row id
+        for ( int i = 0; i < ELEMS_PER_PAGE; i++ )
+        {
+            if ( slots[i] != null )
+            {
+                sb.append( ", [" ).append( i ).append( "]=<" ).
+                append( slots[i].getBlock() ).append( ", " ).
+                append( slots[i].getOffset() ).append( ", " ).
+                append( slots[i].getSize() ).append( ">" );
+            }
+        }
+        
+        sb.append( ")" );
+        
+        return sb.toString();
+    }
 }
\ No newline at end of file

Modified: directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/FreePhysicalRowIdPageManager.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/FreePhysicalRowIdPageManager.java?rev=1162285&r1=1162284&r2=1162285&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/FreePhysicalRowIdPageManager.java (original)
+++ directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/FreePhysicalRowIdPageManager.java Fri Aug 26 23:18:04 2011
@@ -87,7 +87,7 @@ final class FreePhysicalRowIdPageManager
         while ( curs.next() != 0 ) 
         {
             FreePhysicalRowIdPage fp = FreePhysicalRowIdPage
-                .getFreePhysicalRowIdPageView( recordFile.get( curs.getCurrent() ) );
+                .getFreePhysicalRowIdPageView( recordFile.get( curs.getBlockId() ) );
             int slot = fp.getFirstLargerThan( size );
             
             if ( slot != -1 ) 
@@ -99,12 +99,12 @@ final class FreePhysicalRowIdPageManager
                 if ( fp.getCount() == 0 ) 
                 {
                     // page became empty - free it
-                    recordFile.release( curs.getCurrent(), false );
-                    pageManager.free( Magic.FREEPHYSIDS_PAGE, curs.getCurrent() );
+                    recordFile.release( curs.getBlockId(), false );
+                    pageManager.free( Magic.FREEPHYSIDS_PAGE, curs.getBlockId() );
                 } 
                 else 
                 {
-                    recordFile.release( curs.getCurrent(), true );
+                    recordFile.release( curs.getBlockId(), true );
                 }
 
                 return retval;
@@ -112,7 +112,7 @@ final class FreePhysicalRowIdPageManager
             else 
             {
                 // no luck, go to next page
-                recordFile.release( curs.getCurrent(), false );
+                recordFile.release( curs.getBlockId(), false );
             }
         }
         return null;
@@ -130,7 +130,7 @@ final class FreePhysicalRowIdPageManager
         
         while ( curs.next() != 0 ) 
         {
-            freePage = curs.getCurrent();
+            freePage = curs.getBlockId();
             BlockIo curBlock = recordFile.get( freePage );
             FreePhysicalRowIdPage fp = FreePhysicalRowIdPage.getFreePhysicalRowIdPageView( curBlock );
             int slot = fp.getFirstFree();

Modified: directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/Location.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/Location.java?rev=1162285&r1=1162284&r2=1162285&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/Location.java (original)
+++ directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/Location.java Fri Aug 26 23:18:04 2011
@@ -55,7 +55,7 @@ package jdbm.recman;
 final class Location 
 {
     /** The block in which the data is stored */
-    private long block;
+    private long blockId;
     
     /** The offset within this block */
     private short offset;
@@ -63,10 +63,13 @@ final class Location 
     
     /**
      * Creates a location from a (block, offset) tuple.
+     * 
+     * @param blockId The block identifier
+     * @param offset the offset in the block
      */
-    Location( long block, short offset ) 
+    Location( long blockId, short offset ) 
     {
-        this.block = block;
+        this.blockId = blockId;
         this.offset = offset;
     }
 
@@ -74,30 +77,34 @@ final class Location 
     /**
      * Creates a location from a combined block/offset long, as used in the 
      * external representation of logical rowids. A recid is a logical rowid.
+     * 
+     * @param blockOffset The block + offset combinaison
      */
     Location( long blockOffset ) 
     {
         this.offset = ( short ) ( blockOffset & 0xffff );
-        this.block = blockOffset >> 16;
+        this.blockId = blockOffset >> 16;
     }
 
     
     /**
      * Creates a location based on the data of the physical rowid.
+     * 
+     * @param physicalRowId The physical row id used as a base for the Location creation
      */
-    Location( PhysicalRowId src ) 
+    Location( PhysicalRowId physicalRowId ) 
     {
-        block = src.getBlock();
-        offset = src.getOffset();
+        blockId = physicalRowId.getBlock();
+        offset = physicalRowId.getOffset();
     }
 
     
     /**
-     * Returns the file block of the location
+     * @eturn the blockId of the location
      */
     long getBlock() 
     {
-        return block;
+        return blockId;
     }
 
     
@@ -117,7 +124,7 @@ final class Location 
      */
     long toLong() 
     {
-        return ( block << 16 ) + ( long ) offset;
+        return ( blockId << 16 ) + ( long ) offset;
     }
 
     
@@ -136,21 +143,26 @@ final class Location 
     @Override
    public boolean equals( Object o ) 
     {
-        if ( o == null || ! ( o instanceof Location ) )
+        if ( ( o == null ) || ! ( o instanceof Location ) )
         {
             return false;
         }
         
         Location ol = ( Location ) o;
-        return ol.block == block && ol.offset == offset;
+        
+        return ( ol.blockId == blockId ) && ( ol.offset == offset );
     }
 
     
+    /**
+     * {@inheritDoc}
+     */
     public String toString() 
     {
         StringBuilder sb = new StringBuilder();
-        sb.append( "Location ( " ).append( block ).append( " : " );
+        sb.append( "Location ( " ).append( blockId ).append( " : " );
         sb.append( offset ).append( " ) " );
+        
         return sb.toString();
     }
 }

Modified: directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/PageCursor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/PageCursor.java?rev=1162285&r1=1162284&r2=1162285&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/PageCursor.java (original)
+++ directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/PageCursor.java Fri Aug 26 23:18:04 2011
@@ -55,65 +55,85 @@ import java.io.IOException;
  */
 final class PageCursor 
 {
-    PageManager pageman;
-    long current;
+    /** The PageManager */
+    PageManager pageManager;
+    
+    /** The current block ID */
+    long blockId;
+    
+    /** The page type */
     short type;
     
 
     /**
      * Constructs a page cursor that starts at the indicated block.
+     * 
+     * @param pageManager The PageManager
      */
-    PageCursor( PageManager pageman, long current ) 
+    PageCursor( PageManager pageManager, long blockId ) 
     {
-        this.pageman = pageman;
-        this.current = current;
+        this.pageManager = pageManager;
+        this.blockId = blockId;
     }
     
     
     /**
      * Constructs a page cursor that starts at the first block of the 
      * indicated list.
+     * 
+     * @param pageManager The PageManager
+     * @param type The page type
      */
-    PageCursor( PageManager pageman, short type ) throws IOException 
+    PageCursor( PageManager pageManager, short type ) throws IOException 
     {
-        this.pageman = pageman;
+        this.pageManager = pageManager;
         this.type = type;
     }
     
     
     /**
-     * Returns the current value of the cursor.
+     * @return the BlockId
      */
-    long getCurrent() throws IOException 
+    long getBlockId() throws IOException 
     {
-        return current;
+        return blockId;
     }
     
     
     /**
-     * Returns the next value of the cursor.
+     * @return the next blockId 
      */
     long next() throws IOException 
     {
-        if ( current == 0 )
+        if ( blockId == 0 )
         {
-            current = pageman.getFirst( type );
+            blockId = pageManager.getFirst( type );
         }
         else
         {
-            current = pageman.getNext( current );
+            blockId = pageManager.getNext( blockId );
         }
         
-        return current;
+        return blockId;
     } 
     
     
     /**
-     * Returns the previous value of the cursor
+     * @return the previous blockId
      */
     long prev() throws IOException 
     {
-        current = pageman.getPrev( current );
-        return current;
+        blockId = pageManager.getPrev( blockId );
+        
+        return blockId;
+    }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    public String toString()
+    {
+        return "Location( " + blockId + ", " + type + ")";
     }
 }

Modified: directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/PageHeader.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/PageHeader.java?rev=1162285&r1=1162284&r2=1162285&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/PageHeader.java (original)
+++ directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/PageHeader.java Fri Aug 26 23:18:04 2011
@@ -81,23 +81,23 @@ public class PageHeader implements Block
     protected static final short SIZE = O_PREV + Magic.SZ_LONG;
 
     /** the page header block this view is associated with */
-    protected BlockIo block;
+    protected BlockIo blockIo;
 
     
     /**
      * Constructs a PageHeader object from a block
      *
-     * @param block The block that contains the page header
+     * @param blockIo The block that contains the page header
      * @throws IOException if the block is too short to keep the page header.
      */
-    protected PageHeader( BlockIo block ) 
+    protected PageHeader( BlockIo blockIo ) 
     {
-        this.block = block;
-        block.setView( this );
+        this.blockIo = blockIo;
+        blockIo.setView( this );
         
         if ( ! magicOk() )
         {
-            throw new Error( I18n.err( I18n.ERR_546, block.getBlockId(), getMagic() ) );
+            throw new Error( I18n.err( I18n.ERR_546, blockIo.getBlockId(), getMagic() ) );
         }
     }
     
@@ -106,10 +106,10 @@ public class PageHeader implements Block
      * Constructs a new PageHeader of the indicated type. Used for newly
      * created pages.
      */
-    PageHeader( BlockIo block, short type ) 
+    PageHeader( BlockIo blockIo, short type ) 
     {
-        this.block = block;
-        block.setView( this );
+        this.blockIo = blockIo;
+        blockIo.setView( this );
         setType( type );
     }
     
@@ -117,9 +117,9 @@ public class PageHeader implements Block
     /**
      * Factory method to create or return a page header for the indicated block.
      */
-    static PageHeader getView ( BlockIo block ) 
+    static PageHeader getView ( BlockIo blockIo ) 
     {
-        BlockView view = block.getView();
+        BlockView view = blockIo.getView();
         
         if ( view != null && view instanceof PageHeader )
         {
@@ -127,7 +127,7 @@ public class PageHeader implements Block
         }
         else
         {
-            return new PageHeader( block );
+            return new PageHeader( blockIo );
         }
     }
     
@@ -161,7 +161,7 @@ public class PageHeader implements Block
      */
     short getMagic() 
     {
-        return block.readShort( O_MAGIC );
+        return blockIo.readShort( O_MAGIC );
     }
 
     
@@ -172,19 +172,19 @@ public class PageHeader implements Block
     {
         paranoiaMagicOk();
         
-        return block.readLong( O_NEXT );
+        return blockIo.readLong( O_NEXT );
     }
     
     
     /** 
-     * Sets the next block.
+     * Sets the next blockIo.
      * 
      * @param The next Block ID
      */
     void setNext( long next ) 
     {
         paranoiaMagicOk();
-        block.writeLong( O_NEXT, next );
+        blockIo.writeLong( O_NEXT, next );
     }
     
     
@@ -195,7 +195,7 @@ public class PageHeader implements Block
     {
         paranoiaMagicOk();
         
-        return block.readLong( O_PREV );
+        return blockIo.readLong( O_PREV );
     }
     
     
@@ -205,7 +205,7 @@ public class PageHeader implements Block
     void setPrev( long prev ) 
     {
         paranoiaMagicOk();
-        block.writeLong( O_PREV, prev );
+        blockIo.writeLong( O_PREV, prev );
     }
     
     
@@ -216,6 +216,80 @@ public class PageHeader implements Block
      */
     void setType( short type ) 
     {
-        block.writeShort( O_MAGIC, ( short ) ( Magic.BLOCK + type ) );
+        blockIo.writeShort( O_MAGIC, ( short ) ( Magic.BLOCK + type ) );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public String toString() 
+    {
+        StringBuilder sb = new StringBuilder();
+        
+        sb.append( "PageHeader ( " );
+        
+        // The blockIO
+        sb.append( "BlockIO ( " );
+        
+        // The blockID
+        sb.append( blockIo.getBlockId() ).append( ", " );
+        
+        // Is it dirty ?
+        if ( blockIo.isDirty() )
+        {
+            sb.append( "dirty, " );
+        }
+        else
+        {
+            sb.append( "clean, " );
+        }
+        
+        // The transaction count
+        if ( blockIo.isInTransaction() )
+        {
+            sb.append( "in tx" );
+        }
+        else
+        {
+            sb.append( "no tx" );
+        }
+
+        sb.append( " ), " );
+        
+        // The Type
+        int magic = getMagic();
+        
+        switch ( magic - Magic.BLOCK )
+        {
+            case Magic.FREE_PAGE :
+                sb.append( "FREE_PAGE" ).append( ", " );
+                break;
+                
+            case Magic.USED_PAGE :
+                sb.append( "USED_PAGE" ).append( ", " );
+                break;
+                
+            case Magic.TRANSLATION_PAGE :
+                sb.append( "TRANSLATION_PAGE" ).append( ", " );
+                break;
+                
+            case Magic.FREELOGIDS_PAGE :
+                sb.append( "FREELOGIDS_PAGE" ).append( ", " );
+                break;
+                
+            case Magic.FREEPHYSIDS_PAGE :
+                sb.append( "FREEPHYSIDS_PAGE" ).append( ", " );
+                break;
+                
+        }
+        
+        // The previous page
+        sb.append( "[p:" ).append( getPrev() ).append( ", " );
+        
+        // The next page
+        sb.append( "n:" ).append( getNext() ).append( "] )" );
+        
+        return sb.toString();
     }
 }

Modified: directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/PhysicalRowIdManager.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/PhysicalRowIdManager.java?rev=1162285&r1=1162284&r2=1162285&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/PhysicalRowIdManager.java (original)
+++ directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/PhysicalRowIdManager.java Fri Aug 26 23:18:04 2011
@@ -64,8 +64,7 @@ final class PhysicalRowIdManager
      *  Creates a new rowid manager using the indicated record file.
      *  and page manager.
      */
-    PhysicalRowIdManager( PageManager pageManager )
-        throws IOException
+    PhysicalRowIdManager( PageManager pageManager ) throws IOException
     {
         this.pageManager = pageManager;
         this.file = pageManager.getRecordFile();
@@ -75,64 +74,69 @@ final class PhysicalRowIdManager
     /**
      *  Inserts a new record. Returns the new physical rowid.
      */
-    Location insert( byte[] data, int start, int length )
-        throws IOException
+    Location insert( byte[] data, int start, int length ) throws IOException
     {
         Location retval = alloc( length );
         write( retval, data, start, length );
         
         return retval;
     }
+    
 
     /**
      *  Updates an existing record. Returns the possibly changed
      *  physical rowid.
      */
-    Location update( Location rowid, byte[] data, int start, int length )
-        throws IOException
+    Location update( Location rowid, byte[] data, int start, int length ) throws IOException
     {
         // fetch the record header
         BlockIo block = pageManager.getRecordFile().get( rowid.getBlock() );
         RecordHeader head = new RecordHeader( block, rowid.getOffset() );
         
-        if ( length > head.getAvailableSize() ) {
+        if ( length > head.getAvailableSize() ) 
+        {
             // not enough space - we need to copy to a new rowid.
             pageManager.getRecordFile().release( block );
             free( rowid );
             rowid = alloc( length );
-        } else {
+        } 
+        else 
+        {
             pageManager.getRecordFile().release( block );
         }
 
         // 'nuff space, write it in and return the rowid.
         write( rowid, data, start, length );
+        
         return rowid;
     }
+    
 
     /**
      *  Deletes a record.
      */
-    void delete( Location rowid )
-        throws IOException
+    void delete( Location rowid ) throws IOException
     {
         free( rowid );
     }
+    
 
     /**
      *  Retrieves a record.
      */
-    byte[] fetch( Location rowid )
-        throws IOException 
+    byte[] fetch( Location rowid ) throws IOException 
     {
         // fetch the record header
         PageCursor curs = new PageCursor( pageManager, rowid.getBlock() );
-        BlockIo block = file.get( curs.getCurrent() );
+        BlockIo block = file.get( curs.getBlockId() );
         RecordHeader head = new RecordHeader( block, rowid.getOffset() );
 
         // allocate a return buffer
         byte[] retval = new byte[ head.getCurrentSize() ];
-        if ( retval.length == 0 ) {
-            file.release( curs.getCurrent(), false );
+        
+        if ( retval.length == 0 ) 
+        {
+            file.release( curs.getBlockId(), false );
             return retval;
         }
 
@@ -140,12 +144,17 @@ final class PhysicalRowIdManager
         int offsetInBuffer = 0;
         int leftToRead = retval.length;
         short dataOffset = (short) (rowid.getOffset() + RecordHeader.SIZE);
-        while ( leftToRead > 0 ) {
+        
+        while ( leftToRead > 0 ) 
+        {
             // copy current page's data to return buffer
             int toCopy = RecordFile.BLOCK_SIZE - dataOffset;
-            if ( leftToRead < toCopy ) {
+            
+            if ( leftToRead < toCopy ) 
+            {
                 toCopy = leftToRead;
             }
+            
             System.arraycopy( block.getData(), dataOffset,
                               retval, offsetInBuffer,
                               toCopy );
@@ -156,7 +165,8 @@ final class PhysicalRowIdManager
 
             file.release( block );
 
-            if ( leftToRead > 0 ) {
+            if ( leftToRead > 0 ) 
+            {
                 block = file.get( curs.next() );
                 dataOffset = DataPage.O_DATA;
             }
@@ -169,8 +179,7 @@ final class PhysicalRowIdManager
     /**
      *  Allocate a new rowid with the indicated size.
      */
-    private Location alloc( int size )
-        throws IOException
+    private Location alloc( int size ) throws IOException
     {
         Location retval = freeman.get( size );
         
@@ -188,12 +197,13 @@ final class PhysicalRowIdManager
      *  allow for a recursive call - it indicates where the search
      *  should start.
      */
-    private Location allocNew( int size, long start )
-        throws IOException
+    private Location allocNew( int size, long start ) throws IOException
     {
         BlockIo curBlock;
         DataPage curPage;
-        if ( start == 0 ) {
+        
+        if ( start == 0 ) 
+        {
             // we need to create a new page.
             start = pageManager.allocate( Magic.USED_PAGE );
             curBlock = file.get( start );
@@ -202,7 +212,9 @@ final class PhysicalRowIdManager
             RecordHeader hdr = new RecordHeader( curBlock, DataPage.O_DATA );
             hdr.setAvailableSize( 0 );
             hdr.setCurrentSize( 0 );
-        } else {
+        } 
+        else 
+        {
             curBlock = file.get( start );
             curPage = DataPage.getDataPageView( curBlock );
         }
@@ -210,16 +222,22 @@ final class PhysicalRowIdManager
         // follow the rowids on this page to get to the last one. We don't
         // fall off, because this is the last page, remember?
         short pos = curPage.getFirst();
-        if ( pos == 0 ) {
+        
+        if ( pos == 0 ) 
+        {
             // page is exactly filled by the last block of a record
             file.release( curBlock );
             return allocNew( size, 0 );
         }
 
         RecordHeader hdr = new RecordHeader( curBlock, pos );
-        while ( hdr.getAvailableSize() != 0 && pos < RecordFile.BLOCK_SIZE ) {
+        
+        while ( hdr.getAvailableSize() != 0 && pos < RecordFile.BLOCK_SIZE ) 
+        {
             pos += hdr.getAvailableSize() + RecordHeader.SIZE;
-            if ( pos == RecordFile.BLOCK_SIZE ) {
+            
+            if ( pos == RecordFile.BLOCK_SIZE ) 
+            {
                 // Again, a filled page.
                 file.release( curBlock );
                 return allocNew( size, 0 );
@@ -228,7 +246,8 @@ final class PhysicalRowIdManager
             hdr = new RecordHeader( curBlock, pos );
         }
 
-        if ( pos == RecordHeader.SIZE ) {
+        if ( pos == RecordHeader.SIZE ) 
+        {
             // the last record exactly filled the page. Restart forcing
             // a new page.
             file.release( curBlock );
@@ -238,12 +257,16 @@ final class PhysicalRowIdManager
         // enough space.
         Location retval = new Location( start, pos );
         int freeHere = RecordFile.BLOCK_SIZE - pos - RecordHeader.SIZE;
-        if ( freeHere < size ) {
+        
+        if ( freeHere < size ) 
+        {
             // check whether the last page would have only a small bit left.
             // if yes, increase the allocation. A small bit is a record
             // header plus 16 bytes.
             int lastSize = (size - freeHere) % DataPage.DATA_PER_PAGE;
-            if (( DataPage.DATA_PER_PAGE - lastSize ) < (RecordHeader.SIZE + 16) ) {
+            
+            if (( DataPage.DATA_PER_PAGE - lastSize ) < (RecordHeader.SIZE + 16) ) 
+            {
                 size += (DataPage.DATA_PER_PAGE - lastSize);
             }
 
@@ -252,8 +275,10 @@ final class PhysicalRowIdManager
             file.release( start, true );
 
             int neededLeft = size - freeHere;
+            
             // Refactor these two blocks!
-            while ( neededLeft >= DataPage.DATA_PER_PAGE ) {
+            while ( neededLeft >= DataPage.DATA_PER_PAGE ) 
+            {
                 start = pageManager.allocate( Magic.USED_PAGE );
                 curBlock = file.get( start );
                 curPage = DataPage.getDataPageView( curBlock );
@@ -261,7 +286,9 @@ final class PhysicalRowIdManager
                 file.release( start, true );
                 neededLeft -= DataPage.DATA_PER_PAGE;
             }
-            if ( neededLeft > 0 ) {
+            
+            if ( neededLeft > 0 ) 
+            {
                 // done with whole chunks, allocate last fragment.
                 start = pageManager.allocate( Magic.USED_PAGE );
                 curBlock = file.get( start );
@@ -269,23 +296,25 @@ final class PhysicalRowIdManager
                 curPage.setFirst( (short) (DataPage.O_DATA + neededLeft) );
                 file.release( start, true );
             }
-        } else {
+        } else 
+        {
             // just update the current page. If there's less than 16 bytes
             // left, we increase the allocation (16 bytes is an arbitrary
             // number).
-            if ( freeHere - size <= (16 + RecordHeader.SIZE) ) {
+            if ( freeHere - size <= (16 + RecordHeader.SIZE) ) 
+            {
                 size = freeHere;
             }
+            
             hdr.setAvailableSize( size );
             file.release( start, true );
         }
+        
         return retval;
-
     }
 
 
-    private void free( Location id )
-        throws IOException
+    private void free( Location id ) throws IOException
     {
         // get the rowid, and write a zero current size into it.
         BlockIo curBlock = file.get( id.getBlock() );
@@ -296,6 +325,7 @@ final class PhysicalRowIdManager
         // write the rowid to the free list
         freeman.put( id, hdr.getAvailableSize() );
     }
+    
 
     /**
      *  Writes out data to a rowid. Assumes that any resizing has been
@@ -305,11 +335,13 @@ final class PhysicalRowIdManager
         throws IOException
     {
         PageCursor curs = new PageCursor( pageManager, rowid.getBlock() );
-        BlockIo block = file.get( curs.getCurrent() );
+        BlockIo block = file.get( curs.getBlockId() );
         RecordHeader hdr = new RecordHeader( block, rowid.getOffset() );
         hdr.setCurrentSize( length );
-        if ( length == 0 ) {
-            file.release( curs.getCurrent(), true );
+        
+        if ( length == 0 ) 
+        {
+            file.release( curs.getBlockId(), true );
             return;
         }
 
@@ -317,7 +349,9 @@ final class PhysicalRowIdManager
         int offsetInBuffer = start;
         int leftToWrite = length;
         short dataOffset = (short) (rowid.getOffset() + RecordHeader.SIZE);
-        while ( leftToWrite > 0 ) {
+        
+        while ( leftToWrite > 0 ) 
+        {
             // copy current page's data to return buffer
             int toCopy = RecordFile.BLOCK_SIZE - dataOffset;
 
@@ -331,9 +365,10 @@ final class PhysicalRowIdManager
             leftToWrite -= toCopy;
             offsetInBuffer += toCopy;
 
-            file.release( curs.getCurrent(), true );
+            file.release( curs.getBlockId(), true );
 
-            if ( leftToWrite > 0 ) {
+            if ( leftToWrite > 0 ) 
+            {
                 block = file.get( curs.next() );
                 dataOffset = DataPage.O_DATA;
             }

Modified: directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/RecordFile.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/RecordFile.java?rev=1162285&r1=1162284&r2=1162285&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/RecordFile.java (original)
+++ directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/RecordFile.java Fri Aug 26 23:18:04 2011
@@ -60,7 +60,7 @@ import org.apache.directory.server.i18n.
  *  This class represents a random access file as a set of fixed size
  *  records. Each record has a physical record number, and records are
  *  cached in order to improve access.
- *<p>
+ * <p>
  *  The set of dirty records on the in-use list constitutes a transaction.
  *  Later on, we will send these records to some recovery thingy.
  */
@@ -321,9 +321,7 @@ public final class RecordFile 
             // System.out.println("node " + node + " map size now " + dirty.size());
             if ( transactionsDisabled ) 
             {
-                long offset = blockIo.getBlockId() * BLOCK_SIZE;
-                file.seek( offset );
-                file.write( blockIo.getData() );
+                sync( blockIo );
                 blockIo.setClean();
                 free.add( blockIo );
             }
@@ -531,4 +529,76 @@ public final class RecordFile 
             pos += read;
         }
     }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    public String toString()
+    {
+        StringBuilder sb = new StringBuilder();
+        
+        sb.append( "RecordFile<" ).append( fileName ).append( ", " );
+        
+        // The file size
+        sb.append( "size : " );
+        
+        try
+        {
+            sb.append( file.length() ).append( "bytes" );
+        }
+        catch ( IOException ioe )
+        {
+            sb.append( "unknown" );
+        }
+        
+        // Transactions
+        if ( transactionsDisabled )
+        {
+            sb.append( "(noTx)" );
+        }
+        else
+        {
+            sb.append( "(Tx)" );
+        }
+        
+        // Dump the free blocks
+        sb.append( "\n    Free blockIo : " ).append( free.size() );
+                
+        for ( BlockIo blockIo : free )
+        {
+            sb.append( "\n         " );
+            sb.append( blockIo );
+        }
+        
+        // Dump the inUse blocks
+        sb.append( "\n    InUse blockIo : " ).append( inUse.size() );
+        
+        for ( BlockIo blockIo : inUse.values() )
+        {
+            sb.append( "\n         " );
+            sb.append( blockIo );
+        }
+        
+        // Dump the dirty blocks
+        sb.append( "\n    Dirty blockIo : " ).append( dirty.size() );
+        
+        for ( BlockIo blockIo : dirty.values() )
+        {
+            sb.append( "\n         " );
+            sb.append( blockIo );
+        }
+        
+        // Dump the inTxn blocks
+        sb.append( "\n    InTxn blockIo : " ).append( inTxn.size() );
+        
+        for ( BlockIo blockIo : inTxn.values() )
+        {
+            sb.append( "\n         " );
+            sb.append( blockIo );
+        }
+
+        
+        return sb.toString();
+    }
 }

Modified: directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/TranslationPage.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/TranslationPage.java?rev=1162285&r1=1162284&r2=1162285&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/TranslationPage.java (original)
+++ directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/TranslationPage.java Fri Aug 26 23:18:04 2011
@@ -56,37 +56,39 @@ package jdbm.recman;
  */
 final class TranslationPage extends PageHeader 
 {
-    // offsets
+    /** Offset of the PageHeader */
     static final short O_TRANS = PageHeader.SIZE; // short count
+    
+    /** Number of PhysicalRowId in this page */
     static final short ELEMS_PER_PAGE = ( RecordFile.BLOCK_SIZE - O_TRANS ) / PhysicalRowId.SIZE;
     
-    // slots we returned.
+    /** The table of PhysicalRowId */
     final PhysicalRowId[] slots = new PhysicalRowId[ELEMS_PER_PAGE];
 
     
     /**
      * Constructs a data page view from the indicated block.
      */
-    TranslationPage( BlockIo block ) 
+    TranslationPage( BlockIo blockIo ) 
     {
-        super( block );
+        super( blockIo );
     }
     
 
     /**
      * Factory method to create or return a data page for the indicated block.
      */
-    static TranslationPage getTranslationPageView( BlockIo block ) 
+    static TranslationPage getTranslationPageView( BlockIo blockIo ) 
     {
-        BlockView view = block.getView();
+        BlockView view = blockIo.getView();
         
-        if ( view != null && view instanceof TranslationPage )
+        if ( ( view != null ) && view instanceof TranslationPage )
         {
             return ( TranslationPage ) view;
         }
         else
         {
-            return new TranslationPage( block );
+            return new TranslationPage( blockIo );
         }
     }
     
@@ -98,9 +100,37 @@ final class TranslationPage extends Page
         
         if ( slots[slot] == null )
         {
-            slots[slot] = new PhysicalRowId( block, offset );
+            slots[slot] = new PhysicalRowId( blockIo, offset );
         }
         
         return slots[slot];
     }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    public String toString() 
+    {
+        StringBuilder sb = new StringBuilder();
+        
+        sb.append( "TranslationPage ( " );
+        
+        // The blockIO
+        sb.append( super.toString() ).append( ", " );
+        
+        // Dump the Physical row id
+        for ( int i = 0; i < ELEMS_PER_PAGE; i++ )
+        {
+            if ( slots[i] != null )
+            {
+                sb.append( ", [" ).append( i ).append( "]=<" ).
+                append( slots[i].getBlock() ).append( ", " ).
+                append( slots[i].getOffset() ).append( ">" );
+            }
+        }
+        
+        sb.append( ")" );
+        return sb.toString();
+    }
 }



Mime
View raw message