labs-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ka...@apache.org
Subject svn commit: r748887 - in /labs/bananadb/trunk: pom.xml src/main/java/org/apache/labs/bananadb/hashtable/Hashtable.java src/test/java/org/apache/labs/bananadb/hashtable/TestHashtable.java
Date Sat, 28 Feb 2009 17:14:36 GMT
Author: kalle
Date: Sat Feb 28 17:14:36 2009
New Revision: 748887

URL: http://svn.apache.org/viewvc?rev=748887&view=rev
Log:
BananaDB

Too many partitions was created. Added a bit more testing to make sure the data read really
is the data written when using more than one paritition.

Modified:
    labs/bananadb/trunk/pom.xml
    labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/Hashtable.java
    labs/bananadb/trunk/src/test/java/org/apache/labs/bananadb/hashtable/TestHashtable.java

Modified: labs/bananadb/trunk/pom.xml
URL: http://svn.apache.org/viewvc/labs/bananadb/trunk/pom.xml?rev=748887&r1=748886&r2=748887&view=diff
==============================================================================
--- labs/bananadb/trunk/pom.xml (original)
+++ labs/bananadb/trunk/pom.xml Sat Feb 28 17:14:36 2009
@@ -16,7 +16,7 @@
       <artifactId>junit</artifactId>
       <version>3.8.1</version>
       <scope>test</scope>
-    </dependency>
+    </dependency>      
 
     <dependency>
       <groupId>commons-logging</groupId>

Modified: labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/Hashtable.java
URL: http://svn.apache.org/viewvc/labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/Hashtable.java?rev=748887&r1=748886&r2=748887&view=diff
==============================================================================
--- labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/Hashtable.java (original)
+++ labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/Hashtable.java Sat
Feb 28 17:14:36 2009
@@ -90,7 +90,8 @@
 //  private Class<V> valueClass;
 
 
-  private int partitionSize = 10 * (1024 ^ 2);
+  private static final int megaByte = 1024 * 1024;
+  private static final int partitionSize = 100 * megaByte;
 
   private KeyClassHandler<K> keyClassHandler;
 
@@ -316,7 +317,7 @@
 
   }
 
-  private void writeEntry(HashtableAccessor accessor, int nextEntity, byte[] keyBuf, byte[]
valueBuf, int keyHashCode) throws IOException {
+  private synchronized void writeEntry(HashtableAccessor accessor, int nextEntity, byte[]
keyBuf, byte[] valueBuf, int keyHashCode) throws IOException {
 
     int partitionNumber = -1;
     long offset = -1;
@@ -324,9 +325,7 @@
 
       Partition partition = partitions.get(partitions.size() - 1);
       if (partition.bytesLeft < valueBuf.length) {
-        synchronized (this) {
-          partition = this.new Partition();
-        }
+        partition = this.new Partition();
         partition.format(partitionSize);
 
         for (HashtableAccessor tmp : accessors) {
@@ -514,7 +513,9 @@
       return append(accessor, bytes, bytes.length);
     }
 
-    public long append(HashtableAccessor accessor, byte[] bytes, int length) throws IOException
{
+    public synchronized long append(HashtableAccessor accessor, byte[] bytes, int length)
throws IOException {
+
+      bytesLeft -= length;
 
       RandomAccessFile raf = accessor.getPartitionRAF(this);
 
@@ -583,11 +584,13 @@
 
     FileOutputStream fos = new FileOutputStream(file);
     byte[] bytes = new byte[32 * 1024];
-    while (leftToWrite > bytes.length) {
+    while (leftToWrite >= bytes.length) {
       fos.write(bytes);
       leftToWrite -= bytes.length;
     }
-    fos.write(bytes, 0, (int) leftToWrite);
+    if (leftToWrite > 0) {
+      fos.write(bytes, 0, (int) leftToWrite);
+    }
     fos.close();
 
     log.info("It took " + (System.currentTimeMillis() - ms) + " milliseconds to format "
+ file.getAbsolutePath());

Modified: labs/bananadb/trunk/src/test/java/org/apache/labs/bananadb/hashtable/TestHashtable.java
URL: http://svn.apache.org/viewvc/labs/bananadb/trunk/src/test/java/org/apache/labs/bananadb/hashtable/TestHashtable.java?rev=748887&r1=748886&r2=748887&view=diff
==============================================================================
--- labs/bananadb/trunk/src/test/java/org/apache/labs/bananadb/hashtable/TestHashtable.java
(original)
+++ labs/bananadb/trunk/src/test/java/org/apache/labs/bananadb/hashtable/TestHashtable.java
Sat Feb 28 17:14:36 2009
@@ -113,12 +113,15 @@
       sb.append("THIS WILL TURN OUT TO BE A RATHER LONG STRING");
     }
     String str = sb.toString();
-    for (int i = 101; i < 999999; i++) {
-      map.put(accessor, i, str);
-      if (map.getPartitions().size() > 1) {
-        break;
-      }
+    for (int i = 101; i < 5000; i++) {
+      map.put(accessor, i, str + String.valueOf(i));
     }
+    assertEquals(3, map.getPartitions().size());
+
+    for (int i = 101; i < 5000; i++) {
+      assertEquals(str + String.valueOf(i), map.get(accessor, i));
+    }
+
 
     accessor.close();
 



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


Mime
View raw message