You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@labs.apache.org by el...@apache.org on 2012/08/20 09:52:46 UTC

svn commit: r1374934 - in /labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree: BTree.java BTreeConfiguration.java

Author: elecharny
Date: Mon Aug 20 07:52:46 2012
New Revision: 1374934

URL: http://svn.apache.org/viewvc?rev=1374934&view=rev
Log:
Added a configurable buffer size

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

Modified: labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/BTree.java
URL: http://svn.apache.org/viewvc/labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/BTree.java?rev=1374934&r1=1374933&r2=1374934&view=diff
==============================================================================
--- labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/BTree.java (original)
+++ labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/BTree.java Mon Aug 20 07:52:46 2012
@@ -55,6 +55,9 @@ public class BTree<K, V>
     /** Default page size (number of entries per node) */
     public static final int DEFAULT_PAGE_SIZE = 16;
 
+    /** Default size of the buffer used to write data n disk. Around 1Mb */
+    public static final int DEFAULT_WRITE_BUFFER_SIZE = 4096 * 250;
+
     /** The default journal name */
     public static final String DEFAULT_JOURNAL = "mavibot.log";
 
@@ -82,6 +85,9 @@ public class BTree<K, V>
     /** Number of entries in each Page. */
     protected int pageSize;
 
+    /** The size of the buffer used to write data in disk */
+    private int writeBufferSize;
+
     /** The type to use to create the keys */
     protected Class<?> keyType;
 
@@ -338,6 +344,7 @@ public class BTree<K, V>
         comparator = configuration.getComparator();
         serializer = configuration.getSerializer();
         readTimeOut = configuration.getReadTimeOut();
+        writeBufferSize = configuration.getWriteBufferSize();
 
         if ( comparator == null )
         {
@@ -482,6 +489,8 @@ public class BTree<K, V>
         }
 
         setPageSize( pageSize );
+        writeBufferSize = DEFAULT_WRITE_BUFFER_SIZE;
+
         this.serializer = serializer;
 
         // Now, call the init() method
@@ -1055,7 +1064,7 @@ public class BTree<K, V>
         FileChannel ch = stream.getChannel();
 
         // Create a buffer containing 200 4Kb pages (around 1Mb)
-        ByteBuffer bb = ByteBuffer.allocateDirect( 4096 * 200 );
+        ByteBuffer bb = ByteBuffer.allocateDirect( writeBufferSize );
 
         Cursor<K, V> cursor = browse();
 
@@ -1281,6 +1290,24 @@ public class BTree<K, V>
 
 
     /**
+     * @return the writeBufferSize
+     */
+    public int getWriteBufferSize()
+    {
+        return writeBufferSize;
+    }
+
+
+    /**
+     * @param writeBufferSize the writeBufferSize to set
+     */
+    public void setWriteBufferSize( int writeBufferSize )
+    {
+        this.writeBufferSize = writeBufferSize;
+    }
+
+
+    /**
      * @see Object#toString()
      */
     public String toString()

Modified: labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/BTreeConfiguration.java
URL: http://svn.apache.org/viewvc/labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/BTreeConfiguration.java?rev=1374934&r1=1374933&r2=1374934&view=diff
==============================================================================
--- labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/BTreeConfiguration.java (original)
+++ labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/BTreeConfiguration.java Mon Aug 20 07:52:46 2012
@@ -39,6 +39,9 @@ public class BTreeConfiguration<K, V>
     /** Number of entries in each Page. */
     private int pageSize = BTree.DEFAULT_PAGE_SIZE;
 
+    /** The size of the buffer used to write data in disk */
+    private int writeBufferSize = BTree.DEFAULT_WRITE_BUFFER_SIZE;
+
     /** Comparator used to order entries. */
     private Comparator<K> comparator;
 
@@ -268,4 +271,22 @@ public class BTreeConfiguration<K, V>
     {
         this.journalName = journalName;
     }
+
+
+    /**
+     * @return the writeBufferSize
+     */
+    public int getWriteBufferSize()
+    {
+        return writeBufferSize;
+    }
+
+
+    /**
+     * @param writeBufferSize the writeBufferSize to set
+     */
+    public void setWriteBufferSize( int writeBufferSize )
+    {
+        this.writeBufferSize = writeBufferSize;
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org