Author: jbellis
Date: Tue Aug 17 21:15:44 2010
New Revision: 986486
URL: http://svn.apache.org/viewvc?rev=986486&view=rev
Log:
fix sharded lock hashing on index write path. patch by jbellis; reviewed by
eevans for CASSANDRA-1402
Modified:
cassandra/trunk/src/java/org/apache/cassandra/db/Table.java
cassandra/trunk/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java
Modified: cassandra/trunk/src/java/org/apache/cassandra/db/Table.java
URL:
http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/db/Table.java?rev=986486&r1=986485&r2=986486&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/db/Table.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/db/Table.java Tue Aug 17
21:15:44 2010
@@ -386,7 +386,7 @@ public class Table
}
else
{
- synchronized (indexLocks[Arrays.hashCode(mutation.key()) %
indexLocks.length])
+ synchronized (indexLockFor(mutation.key()))
{
// read old indexed values
QueryFilter filter = QueryFilter.getNamesFilter(key,
new QueryPath(cfs.getColumnFamilyName()), mutatedIndexedColumns);
@@ -443,7 +443,7 @@ public class Table
flusherLock.readLock().lock();
try
{
- synchronized (indexLocks[Arrays.hashCode(rowKey.key) %
indexLocks.length])
+ synchronized (indexLockFor(rowKey.key))
{
memtableToFlush = indexedCfs.apply(indexedKey,
indexedColumnFamily);
}
@@ -456,7 +456,12 @@ public class Table
if (memtableToFlush != null)
indexedCfs.maybeSwitchMemtable(memtableToFlush, false);
}
-
+
+ private Object indexLockFor(byte[] key)
+ {
+ return indexLocks[Math.abs(Arrays.hashCode(key) % indexLocks.length)];
+ }
+
private static void applyCF(ColumnFamilyStore cfs, DecoratedKey key,
ColumnFamily columnFamily, HashMap<ColumnFamilyStore, Memtable>
memtablesToFlush)
{
Memtable memtableToFlush = cfs.apply(key, columnFamily);
Modified:
cassandra/trunk/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java
URL:
http://svn.apache.org/viewvc/cassandra/trunk/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java?rev=986486&r1=986485&r2=986486&view=diff
==============================================================================
---
cassandra/trunk/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java
(original)
+++
cassandra/trunk/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java
Tue Aug 17 21:15:44 2010
@@ -173,6 +173,11 @@ public class ColumnFamilyStoreTest exten
rm.add(new QueryPath("Indexed1", null,
"notbirthdate".getBytes("UTF8")), FBUtilities.toByteArray(1L), new
TimestampClock(0));
rm.add(new QueryPath("Indexed1", null, "birthdate".getBytes("UTF8")),
FBUtilities.toByteArray(1L), new TimestampClock(0));
rm.apply();
+
+ rm = new RowMutation("Keyspace1", "k4aaaa".getBytes());
+ rm.add(new QueryPath("Indexed1", null,
"notbirthdate".getBytes("UTF8")), FBUtilities.toByteArray(2L), new
TimestampClock(0));
+ rm.add(new QueryPath("Indexed1", null, "birthdate".getBytes("UTF8")),
FBUtilities.toByteArray(3L), new TimestampClock(0));
+ rm.apply();
IndexExpression expr = new
IndexExpression("birthdate".getBytes("UTF8"), IndexOperator.EQ,
FBUtilities.toByteArray(1L));
IndexClause clause = new IndexClause(Arrays.asList(expr),
ArrayUtils.EMPTY_BYTE_ARRAY, 100);