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/12/01 02:18:08 UTC
svn commit: r1208927 - in /incubator/lcf/branches/CONNECTORS-286/warthog/src:
main/java/org/apache/warthog/tablestore/ test/java/org/apache/warthog/tests/
Author: kwright
Date: Thu Dec 1 01:18:07 2011
New Revision: 1208927
URL: http://svn.apache.org/viewvc?rev=1208927&view=rev
Log:
Break up table head/tail keys into multiple bins for reduced contention
Added:
incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableBaseKey.java (with props)
Modified:
incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/Table.java
incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableAccessor.java
incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableHeadKey.java
incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableTailKey.java
incubator/lcf/branches/CONNECTORS-286/warthog/src/test/java/org/apache/warthog/tests/InMemAtomicNativeNonblockingKeyValueStore.java
Modified: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/Table.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/Table.java?rev=1208927&r1=1208926&r2=1208927&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/Table.java (original)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/Table.java Thu Dec 1 01:18:07 2011
@@ -32,6 +32,9 @@ public class Table implements WHTable
protected long tableIDValue;
protected String[] columns;
+ protected static final int maxInstanceCount = 128;
+ protected static final int maxInstanceMask = maxInstanceCount-1;
+
/** Constructor */
public Table(TableStore ts, LongValue tableID, String[] columns)
{
@@ -164,20 +167,20 @@ public class Table implements WHTable
}
/** Add a table row to the linked list for that table.
- * We add it at the end, although technically we could just as well add at the
- * beginning.
*/
protected void addTableRow(LongValue rowID)
throws WHException
{
+ int instanceNumber = rowID.hashCode() & maxInstanceMask;
+
if (ts.randomDecision())
{
- TableTailKey tailKey = new TableTailKey(tableIDValue);
+ TableTailKey tailKey = new TableTailKey(tableIDValue,instanceNumber);
LongValue tailValue = (LongValue)ts.get(tailKey);
if (tailValue == null)
{
// First row. Set the head.
- ts.put(new TableHeadKey(tableIDValue),rowID);
+ ts.put(new TableHeadKey(tableIDValue,instanceNumber),rowID);
}
else
{
@@ -190,12 +193,12 @@ public class Table implements WHTable
}
else
{
- TableHeadKey headKey = new TableHeadKey(tableIDValue);
+ TableHeadKey headKey = new TableHeadKey(tableIDValue,instanceNumber);
LongValue headValue = (LongValue)ts.get(headKey);
if (headValue == null)
{
// First row. Set the tail.
- ts.put(new TableTailKey(tableIDValue),rowID);
+ ts.put(new TableTailKey(tableIDValue,instanceNumber),rowID);
}
else
{
@@ -213,12 +216,14 @@ public class Table implements WHTable
protected void removeTableRow(LongValue rowID)
throws WHException
{
+ int instanceNumber = rowID.hashCode() & maxInstanceMask;
+
LongValue prevValue = (LongValue)ts.get(new TableRowPrevKey(tableIDValue,rowID.getValue()));
LongValue nextValue = (LongValue)ts.get(new TableRowNextKey(tableIDValue,rowID.getValue()));
// Fix up the previous pointer reference
if (prevValue == null)
{
- ts.put(new TableHeadKey(tableIDValue),nextValue);
+ ts.put(new TableHeadKey(tableIDValue,instanceNumber),nextValue);
}
else
{
@@ -227,7 +232,7 @@ public class Table implements WHTable
// Fix up the next pointer reference
if (nextValue == null)
{
- ts.put(new TableTailKey(tableIDValue),prevValue);
+ ts.put(new TableTailKey(tableIDValue,instanceNumber),prevValue);
}
else
{
@@ -251,13 +256,19 @@ public class Table implements WHTable
return ts.get(new TableColumnKey(tableIDValue,rowID.getValue(),columnName));
}
+ /** Get the max number of instances.
+ */
+ protected int getMaxInstanceNumber()
+ {
+ return maxInstanceCount;
+ }
/** Read the first table row ID.
*/
- protected LongValue readFirstTableRowID()
+ protected LongValue readFirstTableRowID(int instanceNumber)
throws WHException
{
- return (LongValue)ts.get(new TableHeadKey(tableIDValue));
+ return (LongValue)ts.get(new TableHeadKey(tableIDValue,instanceNumber));
}
/** Reade the next table row ID.
Modified: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableAccessor.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableAccessor.java?rev=1208927&r1=1208926&r2=1208927&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableAccessor.java (original)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableAccessor.java Thu Dec 1 01:18:07 2011
@@ -29,14 +29,19 @@ public class TableAccessor implements WH
protected Table table;
/** This is the next row to be returned. */
protected LongValue currentRowID;
+ /** This is the current instance number */
+ protected int currentInstanceNumber;
/** Constructor */
public TableAccessor(Table table)
throws WHException
{
this.table = table;
- currentRowID = table.readFirstTableRowID();
+ currentInstanceNumber = 0;
+ currentRowID = null;
+ seekToNext();
}
+
/** Are there any more rows?
*/
@@ -52,10 +57,37 @@ public class TableAccessor implements WH
throws WHException
{
WHRowID rval = currentRowID;
- if (currentRowID != null)
+ seekToNext();
+ return rval;
+ }
+
+ // Protected methods
+
+ protected void seekToNext()
+ throws WHException
+ {
+ if (currentInstanceNumber == table.getMaxInstanceNumber())
+ return;
+
+ while (true)
{
- currentRowID = table.readNextTableRowID(currentRowID);
+ if (currentRowID == null)
+ {
+ currentRowID = table.readFirstTableRowID(currentInstanceNumber);
+ }
+ else
+ {
+ currentRowID = table.readNextTableRowID(currentRowID);
+ }
+ if (currentRowID == null)
+ {
+ currentInstanceNumber++;
+ if (currentInstanceNumber == table.getMaxInstanceNumber())
+ return;
+ }
+ else
+ return;
}
- return rval;
}
+
}
Added: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableBaseKey.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableBaseKey.java?rev=1208927&view=auto
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableBaseKey.java (added)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableBaseKey.java Thu Dec 1 01:18:07 2011
@@ -0,0 +1,87 @@
+/* $Id$ */
+
+/**
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You under the Apache License, Version 2.0
+* (the "License"); you may not use this file except in compliance with
+* the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.apache.warthog.tablestore;
+
+import org.apache.warthog.interfaces.*;
+import org.apache.warthog.common.*;
+
+/** Base class for table row prev/next keys */
+public class TableBaseKey implements WHKey
+{
+ protected long tableID;
+ protected int instanceNumber;
+
+ /** Constructor */
+ public TableBaseKey(long tableID, int instanceNumber)
+ {
+ this.tableID = tableID;
+ this.instanceNumber = instanceNumber;
+ }
+
+ public TableBaseKey(byte[] data)
+ {
+ BufferPointer bp = new BufferPointer(data);
+ this.tableID = LongKey.readObject(bp);
+ this.instanceNumber = IntegerKey.readObject(bp);
+ }
+
+ public byte[] serializeObject()
+ {
+ byte[] rval = new byte[LongKey.sizeObject()+
+ IntegerKey.sizeObject()];
+ BufferPointer bp = new BufferPointer(rval);
+ LongKey.writeObject(bp,tableID);
+ IntegerKey.writeObject(bp,instanceNumber);
+ return rval;
+ }
+
+ public long getHashCode()
+ {
+ return calculateHashCode(tableID,instanceNumber);
+ }
+
+ public static long calculateHashCode(long tableID, int instanceNumber)
+ {
+ return LongKey.calculateHashCode(tableID) + IntegerKey.calculateHashCode(instanceNumber);
+ }
+
+ public boolean isEquals(WHValue o)
+ {
+ TableBaseKey key = (TableBaseKey)o;
+ return key.tableID == tableID &&
+ key.instanceNumber == instanceNumber;
+ }
+
+ public int hashCode()
+ {
+ return ((int)((tableID << 5) ^ (tableID >> 3))) +
+ ((instanceNumber << 5) ^ (instanceNumber >> 3));
+ }
+
+ public boolean equals(Object o)
+ {
+ if (getClass() != o.getClass())
+ return false;
+ TableBaseKey other = (TableBaseKey)o;
+ return other.tableID == tableID &&
+ other.instanceNumber == instanceNumber;
+ }
+
+}
Propchange: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableBaseKey.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableBaseKey.java
------------------------------------------------------------------------------
svn:keywords = Id
Modified: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableHeadKey.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableHeadKey.java?rev=1208927&r1=1208926&r2=1208927&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableHeadKey.java (original)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableHeadKey.java Thu Dec 1 01:18:07 2011
@@ -22,12 +22,12 @@ package org.apache.warthog.tablestore;
import org.apache.warthog.interfaces.*;
import org.apache.warthog.common.*;
-public class TableHeadKey extends LongKey
+public class TableHeadKey extends TableBaseKey
{
/** Constructor */
- public TableHeadKey(long tableID)
+ public TableHeadKey(long tableID, int instanceNumber)
{
- super(tableID);
+ super(tableID,instanceNumber);
}
public TableHeadKey(byte[] data)
Modified: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableTailKey.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableTailKey.java?rev=1208927&r1=1208926&r2=1208927&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableTailKey.java (original)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableTailKey.java Thu Dec 1 01:18:07 2011
@@ -22,12 +22,12 @@ package org.apache.warthog.tablestore;
import org.apache.warthog.interfaces.*;
import org.apache.warthog.common.*;
-public class TableTailKey extends LongKey
+public class TableTailKey extends TableBaseKey
{
/** Constructor */
- public TableTailKey(long tableID)
+ public TableTailKey(long tableID, int instanceNumber)
{
- super(tableID);
+ super(tableID,instanceNumber);
}
public TableTailKey(byte[] data)
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=1208927&r1=1208926&r2=1208927&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 Thu Dec 1 01:18:07 2011
@@ -99,6 +99,7 @@ public class InMemAtomicNativeNonblockin
LockKey lockKey = new LockKey(key);
if (setIfNonexisting(lockKey,threadID) == false)
{
+ //System.out.println("Type of key in lock contention = "+key.getClass().getName());
throw new WHConcurrencyException();
}
locks[lockPointer++] = lockKey;
@@ -108,7 +109,7 @@ public class InMemAtomicNativeNonblockin
continue;
if (value != null && otherValue != null && value.equals(otherValue))
continue;
- //System.out.println("Type of key in contention = "+key.getClass().getName());
+ //System.out.println("Type of key in check contention = "+key.getClass().getName());
throw new WHConcurrencyException();
}
// We got all the locks and passed the checks! Do the commit