manifoldcf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwri...@apache.org
Subject svn commit: r1208852 - in /incubator/lcf/branches/CONNECTORS-286/warthog/src: main/java/org/apache/warthog/tablestore/ test/java/org/apache/warthog/tests/
Date Wed, 30 Nov 2011 22:43:58 GMT
Author: kwright
Date: Wed Nov 30 22:43:57 2011
New Revision: 1208852

URL: http://svn.apache.org/viewvc?rev=1208852&view=rev
Log:
Use a segmented hash to get far better parallelism out of the back end.

Modified:
    incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableStore.java
    incubator/lcf/branches/CONNECTORS-286/warthog/src/test/java/org/apache/warthog/tests/InMemAtomicNativeNonblockingKeyValueStore.java
    incubator/lcf/branches/CONNECTORS-286/warthog/src/test/java/org/apache/warthog/tests/MultiThreadTest.java

Modified: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableStore.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableStore.java?rev=1208852&r1=1208851&r2=1208852&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableStore.java
(original)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableStore.java
Wed Nov 30 22:43:57 2011
@@ -200,10 +200,22 @@ public class TableStore implements WHTab
 
   // Non-interface public methods
   
+  protected Map<LongValue,LongValue> startMap = new HashMap<LongValue,LongValue>();
+  protected Map<LongValue,LongValue> endMap = new HashMap<LongValue,LongValue>();
+  
   /** Allocate a new row ID */
   public LongValue allocateNewTableRow(LongValue tableID)
     throws WHException
   {
+    LongValue start = startMap.get(tableID);
+    LongValue end = endMap.get(tableID);
+    
+    if (start != null && start.getValue() < end.getValue())
+    {
+      startMap.put(tableID,new LongValue(start.getValue()+1L));
+      return start;
+    }
+    
     // We always do this in our own transaction to limit the deadlock potential,
     // and we retry until we get the ID.  We only throw a concurrency exception
     // if it seems clear that the table is gone.
@@ -217,8 +229,11 @@ public class TableStore implements WHTab
         LongValue tlv = (LongValue)allocateTransaction.get(tlk);
         if (tlv == null)
           break;
-        allocateTransaction.put(tlk,new LongValue(tlv.getValue()+1L));
+        LongValue newValue = new LongValue(tlv.getValue()+100L);
+        allocateTransaction.put(tlk,newValue);
         allocateTransaction.commit();
+        startMap.put(tableID,new LongValue(tlv.getValue()+1L));
+        endMap.put(tableID,newValue);
         return tlv;
       }
       catch (WHConcurrencyException e)

Modified: incubator/lcf/branches/CONNECTORS-286/warthog/src/test/java/org/apache/warthog/tests/InMemAtomicNativeNonblockingKeyValueStore.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/test/java/org/apache/warthog/tests/InMemAtomicNativeNonblockingKeyValueStore.java?rev=1208852&r1=1208851&r2=1208852&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/test/java/org/apache/warthog/tests/InMemAtomicNativeNonblockingKeyValueStore.java
(original)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/test/java/org/apache/warthog/tests/InMemAtomicNativeNonblockingKeyValueStore.java
Wed Nov 30 22:43:57 2011
@@ -26,18 +26,27 @@ import java.util.*;
 */
 public class InMemAtomicNativeNonblockingKeyValueStore implements WHAtomicKeyValueStore
 {
-  protected Map database;
+  protected static int databaseCount = 1024;
+  protected static int databaseMask = databaseCount - 1;
+  
+  protected Map[] databaseArray;
   
   /** Constructor */
   public InMemAtomicNativeNonblockingKeyValueStore(int initialSize)
   {
-    database = new HashMap(initialSize);
+    initialSize /= databaseCount;
+    databaseArray = new Map[databaseCount];
+    for (int i = 0; i < databaseCount ; i++)
+    {
+      databaseArray[i] = new HashMap(initialSize);
+    }
   }
   
   /** Get a value */
   public WHValue get(WHKey key)
     throws WHException
   {
+    Map database = databaseArray[key.hashCode() & databaseMask];
     synchronized (database)
     {
       return (WHValue)database.get(key);
@@ -129,6 +138,7 @@ public class InMemAtomicNativeNonblockin
   
   protected void put(Object key, Object value)
   {
+    Map database = databaseArray[key.hashCode() & databaseMask];
     synchronized (database)
     {
       database.put(key,value);
@@ -137,6 +147,7 @@ public class InMemAtomicNativeNonblockin
   
   protected void remove(Object key)
   {
+    Map database = databaseArray[key.hashCode() & databaseMask];
     synchronized (database)
     {
       database.remove(key);
@@ -145,6 +156,7 @@ public class InMemAtomicNativeNonblockin
   
   protected boolean setIfNonexisting(Object key, Object value)
   {
+    Map database = databaseArray[key.hashCode() & databaseMask];
     synchronized (database)
     {
       if (database.containsKey(key))

Modified: incubator/lcf/branches/CONNECTORS-286/warthog/src/test/java/org/apache/warthog/tests/MultiThreadTest.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/test/java/org/apache/warthog/tests/MultiThreadTest.java?rev=1208852&r1=1208851&r2=1208852&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/test/java/org/apache/warthog/tests/MultiThreadTest.java
(original)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/test/java/org/apache/warthog/tests/MultiThreadTest.java
Wed Nov 30 22:43:57 2011
@@ -250,8 +250,8 @@ public class MultiThreadTest
       throws InterruptedException
     {
       contentions++;
-      Thread.sleep(r.nextInt(100));
-      //Thread.yield();
+      //Thread.sleep(r.nextInt(100));
+      Thread.yield();
     }
     
     protected void performInserts(WHTableStore ts)
@@ -335,8 +335,8 @@ public class MultiThreadTest
       throws InterruptedException
     {
       contentions++;
-      Thread.sleep(r.nextInt(100));
-      //Thread.yield();
+      //Thread.sleep(r.nextInt(100));
+      Thread.yield();
     }
     
     protected void performTask(WHTableStore ts)



Mime
View raw message