You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@labs.apache.org by ka...@apache.org on 2009/03/14 12:56:59 UTC

svn commit: r753640 - in /labs/bananadb/trunk: CHANGES.txt src/main/java/org/apache/labs/bananadb/hashtable/Hashtable.java

Author: kalle
Date: Sat Mar 14 11:56:59 2009
New Revision: 753640

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

Write lock on remove

Modified:
    labs/bananadb/trunk/CHANGES.txt
    labs/bananadb/trunk/src/main/java/org/apache/labs/bananadb/hashtable/Hashtable.java

Modified: labs/bananadb/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/labs/bananadb/trunk/CHANGES.txt?rev=753640&r1=753639&r2=753640&view=diff
==============================================================================
--- labs/bananadb/trunk/CHANGES.txt (original)
+++ labs/bananadb/trunk/CHANGES.txt Sat Mar 14 11:56:59 2009
@@ -13,13 +13,16 @@
  1. Hashtable and Key postings 1024 bytes headers.
     (Karl Wettin)
 
-    Th headers contains data start offset (and more) that is read at every
+    The headers contains data start offset (and more) that is read at every
     access and thus made the way for rehashing on one JVM to "notify" other
     JVMs to start accessing rehashed data.
 
 
 Bug fixes
 
+ 1. Write lock on remove.
+    (Karl Wettin)
+
 
 New features
 

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=753640&r1=753639&r2=753640&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 Mar 14 11:56:59 2009
@@ -379,16 +379,12 @@
    * @throws IOException
    */
   public V put(final HashtableAccessor accessor, final K key, final V value) throws IOException {
-    if (writeLock == null) {
-      return doPut(accessor, key, value);
-    } else {
-      Lock.With<V> with = new Lock.With<V>(writeLock, lockWaitTimeoutMilliseconds) {
-        protected V doBody() throws IOException {
-          return doPut(accessor, key, value);
-        }
-      };
-      return with.run();
-    }
+    Lock.With<V> with = new Lock.With<V>(writeLock, lockWaitTimeoutMilliseconds) {
+      protected V doBody() throws IOException {
+        return doPut(accessor, key, value);
+      }
+    };
+    return with.run();
   }
 
   /**
@@ -662,9 +658,30 @@
 
 
   /**
-   * todo doRemove and lock in remove.
+   * @param accessor
+   * @param key
+   * @return value of removed key
+   * @throws IOException
+   */
+  public V remove(final HashtableAccessor accessor, final K key) throws IOException {
+    Lock.With<V> with = new Lock.With<V>(writeLock, lockWaitTimeoutMilliseconds) {
+      protected V doBody() throws IOException {
+        return doremove(accessor, key);
+      }
+    };
+    return with.run();
+
+  }
+
+  /**
+   * EXPERT: a write lock should be in place when calling this method
+   *
+   * @param accessor
+   * @param key
+   * @return
+   * @throws IOException
    */
-  public V remove(HashtableAccessor accessor, K key) throws IOException {
+  private V doremove(HashtableAccessor accessor, K key) throws IOException {
 
     HashtableFileHeader hashtableFileHeader = new HashtableFileHeader(accessor);
     KeyPostingsFileHeader keyPostingsFileHeader = new KeyPostingsFileHeader(accessor);
@@ -738,15 +755,15 @@
 
   /**
    * Rehashing (allows for growing hashtable capacity)
-   *
+   * <p/>
    * The hashtable and key postings files are appended with null data
    * on which the rehashed postings are written.
-   *
+   * <p/>
    * When rehash finish the start and end offset in the file headers are updated
    * and thus any JVM running using the DB will start reading from the rehashed data.
-   *
+   * <p/>
    * This will require a read and write locking optimize() method in the future.
-   *
+   * <p/>
    * Cursors iterating values will throw an exception in case there has been a rehash.
    *
    * @param accessor
@@ -901,7 +918,6 @@
     outputKeyPostingsFileHeader.save(accessor);
 
 
-
     System.currentTimeMillis();
 
   }



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