You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@manifoldcf.apache.org by kw...@apache.org on 2011/11/30 17:38:47 UTC
svn commit: r1208500 - in /incubator/lcf/branches/CONNECTORS-286/warthog/src:
main/java/org/apache/warthog/interfaces/ test/java/org/apache/warthog/tests/
Author: kwright
Date: Wed Nov 30 16:38:45 2011
New Revision: 1208500
URL: http://svn.apache.org/viewvc?rev=1208500&view=rev
Log:
Use 'nonblocking' underlying atomic store to increase concurrency for a more realistic test.
Modified:
incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHByteKeyMap.java
incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHKeyMap.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/InMemByteTransactionImpl.java
incubator/lcf/branches/CONNECTORS-286/warthog/src/test/java/org/apache/warthog/tests/InMemNativeTransactionImpl.java
incubator/lcf/branches/CONNECTORS-286/warthog/src/test/java/org/apache/warthog/tests/InMemTransactionImpl.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/interfaces/WHByteKeyMap.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHByteKeyMap.java?rev=1208500&r1=1208499&r2=1208500&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHByteKeyMap.java (original)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHByteKeyMap.java Wed Nov 30 16:38:45 2011
@@ -35,5 +35,11 @@ public interface WHByteKeyMap
*/
public WHByteKeyIterator iterator()
throws WHException;
+
+ /** Get the size of the map.
+ */
+ public long size()
+ throws WHException;
+
}
Modified: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHKeyMap.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHKeyMap.java?rev=1208500&r1=1208499&r2=1208500&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHKeyMap.java (original)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHKeyMap.java Wed Nov 30 16:38:45 2011
@@ -34,5 +34,10 @@ public interface WHKeyMap
*/
public WHKeyIterator iterator()
throws WHException;
+
+ /** Get the size of the map.
+ */
+ public long size()
+ throws WHException;
}
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=1208500&r1=1208499&r2=1208500&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 16:38:45 2011
@@ -26,12 +26,12 @@ import java.util.*;
*/
public class InMemAtomicNativeNonblockingKeyValueStore implements WHAtomicKeyValueStore
{
- protected Map<WHKey,WHValue> database;
+ protected Map database;
/** Constructor */
public InMemAtomicNativeNonblockingKeyValueStore(int initialSize)
{
- database = new HashMap<WHKey,WHValue>(initialSize);
+ database = new HashMap(initialSize);
}
/** Get a value */
@@ -40,7 +40,7 @@ public class InMemAtomicNativeNonblockin
{
synchronized (database)
{
- return database.get(key);
+ return (WHValue)database.get(key);
}
}
@@ -51,21 +51,18 @@ public class InMemAtomicNativeNonblockin
public void check(WHKeyMap checkValues)
throws WHException
{
- synchronized (database)
+ WHKeyIterator iterator = checkValues.iterator();
+ while (iterator.hasNext())
{
- WHKeyIterator iterator = checkValues.iterator();
- while (iterator.hasNext())
- {
- WHKey key = iterator.next();
- WHValue value = database.get(key);
- WHValue otherValue = checkValues.get(key);
- if (value == null && otherValue == null)
- continue;
- if (value != null && otherValue != null && value.equals(otherValue))
- continue;
- //System.out.println("Type of key in contention = "+key.getClass().getName());
- throw new WHConcurrencyException();
- }
+ WHKey key = iterator.next();
+ WHValue value = get(key);
+ WHValue otherValue = checkValues.get(key);
+ if (value == null && otherValue == null)
+ continue;
+ if (value != null && otherValue != null && value.equals(otherValue))
+ continue;
+ //System.out.println("Type of key in contention = "+key.getClass().getName());
+ throw new WHConcurrencyException();
}
}
@@ -79,25 +76,58 @@ public class InMemAtomicNativeNonblockin
public void setAll(WHKeyMap checkValues, WHKeyMap setValues)
throws WHException
{
- synchronized (database)
+ // First, get the identifier of the thread making the request
+ Long threadID = new Long(Thread.currentThread().getId());
+ // Allocate a lock vector, to be filled in as we assert the locks
+ LockKey[] locks = new LockKey[(int)checkValues.size()];
+ int lockPointer = 0;
+ try
{
- check(checkValues);
- WHKeyIterator iterator = setValues.iterator();
+ WHKeyIterator iterator = checkValues.iterator();
+ while (iterator.hasNext())
+ {
+ WHKey key = iterator.next();
+ LockKey lockKey = new LockKey(key);
+ if (setIfNonexisting(lockKey,threadID) == false)
+ {
+ throw new WHConcurrencyException();
+ }
+ locks[lockPointer++] = lockKey;
+ WHValue value = get(key);
+ WHValue otherValue = checkValues.get(key);
+ if (value == null && otherValue == null)
+ continue;
+ if (value != null && otherValue != null && value.equals(otherValue))
+ continue;
+ //System.out.println("Type of key in contention = "+key.getClass().getName());
+ throw new WHConcurrencyException();
+ }
+ // We got all the locks and passed the checks! Do the commit
+ iterator = setValues.iterator();
while (iterator.hasNext())
{
WHKey key = iterator.next();
WHValue value = setValues.get(key);
if (value == null)
- database.remove(key);
+ remove(key);
else
- database.put(key,value);
+ put(key,value);
+ }
+ }
+ finally
+ {
+ // Undo locks so far set
+ while (lockPointer > 0)
+ {
+ LockKey lockKey = locks[--lockPointer];
+ remove(lockKey);
}
}
}
// Basic operations
- protected void put(WHKey key, WHValue value)
+ protected void put(Object key, Object value)
{
synchronized (database)
{
@@ -105,7 +135,7 @@ public class InMemAtomicNativeNonblockin
}
}
- protected void remove(WHKey key)
+ protected void remove(Object key)
{
synchronized (database)
{
@@ -113,7 +143,7 @@ public class InMemAtomicNativeNonblockin
}
}
- protected boolean setIfNonexisting(WHKey key, WHValue value)
+ protected boolean setIfNonexisting(Object key, Object value)
{
synchronized (database)
{
Modified: incubator/lcf/branches/CONNECTORS-286/warthog/src/test/java/org/apache/warthog/tests/InMemByteTransactionImpl.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/test/java/org/apache/warthog/tests/InMemByteTransactionImpl.java?rev=1208500&r1=1208499&r2=1208500&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/test/java/org/apache/warthog/tests/InMemByteTransactionImpl.java (original)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/test/java/org/apache/warthog/tests/InMemByteTransactionImpl.java Wed Nov 30 16:38:45 2011
@@ -188,6 +188,14 @@ public class InMemByteTransactionImpl im
return new KeyIterator(map.keySet().iterator());
}
+ /** Get the size of the map.
+ */
+ public long size()
+ throws WHException
+ {
+ return (long)map.size();
+ }
+
/** Check if the map contains the specified key.
*/
public boolean containsKey(byte[] key)
Modified: incubator/lcf/branches/CONNECTORS-286/warthog/src/test/java/org/apache/warthog/tests/InMemNativeTransactionImpl.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/test/java/org/apache/warthog/tests/InMemNativeTransactionImpl.java?rev=1208500&r1=1208499&r2=1208500&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/test/java/org/apache/warthog/tests/InMemNativeTransactionImpl.java (original)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/test/java/org/apache/warthog/tests/InMemNativeTransactionImpl.java Wed Nov 30 16:38:45 2011
@@ -119,6 +119,14 @@ public class InMemNativeTransactionImpl
return new KeyIterator(map.keySet().iterator());
}
+ /** Get the size of the map.
+ */
+ public long size()
+ throws WHException
+ {
+ return (long)map.size();
+ }
+
/** Check if the map contains the specified key.
*/
public boolean containsKey(WHKey key)
Modified: incubator/lcf/branches/CONNECTORS-286/warthog/src/test/java/org/apache/warthog/tests/InMemTransactionImpl.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/test/java/org/apache/warthog/tests/InMemTransactionImpl.java?rev=1208500&r1=1208499&r2=1208500&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/test/java/org/apache/warthog/tests/InMemTransactionImpl.java (original)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/test/java/org/apache/warthog/tests/InMemTransactionImpl.java Wed Nov 30 16:38:45 2011
@@ -117,7 +117,15 @@ public class InMemTransactionImpl implem
{
return new KeyIterator(map.keySet().iterator());
}
-
+
+ /** Get the size of the map.
+ */
+ public long size()
+ throws WHException
+ {
+ return (long)map.size();
+ }
+
/** Check if the map contains the specified key.
*/
public boolean containsKey(WHKey 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=1208500&r1=1208499&r2=1208500&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 16:38:45 2011
@@ -39,7 +39,7 @@ public class MultiThreadTest
public void writeOnlyTest()
throws Exception
{
- doWrites(8);
+ doWrites(24);
}
protected void doWrites(int threadCount)
@@ -122,7 +122,7 @@ public class MultiThreadTest
throws Exception
{
int totalCount = 10000/4;
- int threadCount = 4;
+ int threadCount = 24;
int repeatCount = totalCount/threadCount;