Author: elecharny
Date: Mon Jun 10 15:51:52 2013
New Revision: 1491509

URL: http://svn.apache.org/r1491509
Log:
o Speed up the update by using a global buffer isntead of allocating a new one 
every time we need to update the header
o Removed useless fields

Modified:
    
labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/RecordManager.java

Modified: 
labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/RecordManager.java
URL: 
http://svn.apache.org/viewvc/labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/RecordManager.java?rev=1491509&r1=1491508&r2=1491509&view=diff
==============================================================================
--- 
labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/RecordManager.java
 (original)
+++ 
labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/RecordManager.java
 Mon Jun 10 15:51:52 2013
@@ -115,17 +115,18 @@ public class RecordManager
     private static final int FIRST_FREE_PAGE_SIZE = 8;
     private static final int LAST_FREE_PAGE_SIZE = 8;
 
+    /** The header size */
     private static final int HEADER_SIZE = NB_TREE_SIZE + PAGE_SIZE + 
FIRST_FREE_PAGE_SIZE + LAST_FREE_PAGE_SIZE;
 
+    /** A global buffer used to store the header */
+    private static final ByteBuffer HEADER_BUFFER = ByteBuffer.allocate( 
HEADER_SIZE );
+
     /** The default page size */
     private static final int DEFAULT_PAGE_SIZE = 512;
 
     /** The RecordManager underlying page size. */
     private int pageSize = DEFAULT_PAGE_SIZE;
 
-    /** A buffer used to read a page */
-    private ByteBuffer blockBuffer;
-
     /** The set of managed BTrees */
     private Map<String, BTree<?, ?>> managedBTrees;
 
@@ -145,9 +146,6 @@ public class RecordManager
     /** A flag set to true if we want to keep old revisions */
     private boolean keepRevisions;
 
-    /** A global buffer used for free pages */
-    private static ByteBuffer FREE_PAGE_BUFFER;
-
 
     /**
      * Create a Record manager which will either create the underlying file
@@ -174,8 +172,6 @@ public class RecordManager
     {
         managedBTrees = new LinkedHashMap<String, BTree<?, ?>>();
 
-        FREE_PAGE_BUFFER = ByteBuffer.allocateDirect( pageSize );
-
         // Open the file or create it
         File tmpFile = new File( fileName );
         boolean isNewFile = false;
@@ -1152,27 +1148,25 @@ public class RecordManager
      */
     private void updateRecordManagerHeader() throws IOException
     {
-        // The page size
-        ByteBuffer header = ByteBuffer.allocate( HEADER_SIZE );
+        HEADER_BUFFER.clear();
 
         // The page size
-        header.putInt( pageSize );
+        HEADER_BUFFER.putInt( pageSize );
 
         // The number of managed BTree (currently we have only one : the 
discardedPage BTree
-        header.putInt( nbBtree );
+        HEADER_BUFFER.putInt( nbBtree );
 
         // The first free page
-        header.putLong( firstFreePage );
+        HEADER_BUFFER.putLong( firstFreePage );
 
         // The last free page
-        header.putLong( lastFreePage );
+        HEADER_BUFFER.putLong( lastFreePage );
 
         // Write the header on disk
-        header.rewind();
+        HEADER_BUFFER.rewind();
 
         LOG.debug( "Update RM header, FF : {}, LF : {}", firstFreePage, 
lastFreePage );
-        fileChannel.write( header, 0L );
-        //fileChannel.force( false );
+        fileChannel.write( HEADER_BUFFER, 0L );
     }
 
 



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to