Author: manik.surtani(a)jboss.com
Date: 2008-12-02 07:27:32 -0500 (Tue, 02 Dec 2008)
New Revision: 7234
Modified:
core/branches/flat/src/main/java/org/jboss/starobrno/atomic/AtomicHashMapProxy.java
core/branches/flat/src/main/java/org/jboss/starobrno/container/MVCCEntryCreator.java
core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/LockingInterceptor.java
core/branches/flat/src/main/java/org/jboss/starobrno/tree/TreeStructureSupport.java
core/branches/flat/src/main/java/org/jboss/starobrno/util/concurrent/locks/OwnableReentrantLock.java
core/branches/flat/src/test/java/org/jboss/starobrno/api/tree/NodeMoveAPITest.java
core/branches/flat/src/test/java/org/jboss/starobrno/profiling/TreeProfileTest.java
Log:
Improved performance of tree struct
Modified:
core/branches/flat/src/main/java/org/jboss/starobrno/atomic/AtomicHashMapProxy.java
===================================================================
---
core/branches/flat/src/main/java/org/jboss/starobrno/atomic/AtomicHashMapProxy.java 2008-12-02
11:00:56 UTC (rev 7233)
+++
core/branches/flat/src/main/java/org/jboss/starobrno/atomic/AtomicHashMapProxy.java 2008-12-02
12:27:32 UTC (rev 7234)
@@ -58,11 +58,17 @@
else
{
// acquire WL
- cache.getInvocationContext().getOptionOverrides().setForceWriteLock(true);
+ boolean suppressLocks =
cache.getInvocationContext().getOptionOverrides().isSuppressLocking();
+ if (!suppressLocks)
+ {
+ cache.getInvocationContext().getOptionOverrides().setForceWriteLock(true);
+ }
AtomicHashMap map = getDeltaMapForRead();
// copy for write
AtomicHashMap copy = map == null ? new AtomicHashMap() : map.copyForWrite();
copy.initForWriting();
+ // reinstate the option
+
cache.getInvocationContext().getOptionOverrides().setSuppressLocking(suppressLocks);
cache.put(deltaMapKey, copy);
return copy;
}
Modified:
core/branches/flat/src/main/java/org/jboss/starobrno/container/MVCCEntryCreator.java
===================================================================
---
core/branches/flat/src/main/java/org/jboss/starobrno/container/MVCCEntryCreator.java 2008-12-02
11:00:56 UTC (rev 7233)
+++
core/branches/flat/src/main/java/org/jboss/starobrno/container/MVCCEntryCreator.java 2008-12-02
12:27:32 UTC (rev 7234)
@@ -23,13 +23,13 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.jboss.starobrno.lock.TimeoutException;
import org.jboss.starobrno.config.Configuration;
import org.jboss.starobrno.context.InvocationContext;
import org.jboss.starobrno.factories.EntryFactory;
import org.jboss.starobrno.factories.annotations.Inject;
import org.jboss.starobrno.factories.annotations.Start;
import org.jboss.starobrno.lock.LockManager;
+import org.jboss.starobrno.lock.TimeoutException;
import org.jboss.starobrno.notifications.Notifier;
/**
@@ -161,7 +161,7 @@
* Attempts to lock a node if the lock isn't already held in the current scope,
and records the lock in the context.
*
* @param ctx context
- * @param fqn Fqn to lock
+ * @param key Key to lock
* @return true if a lock was needed and acquired, false if it didn't need to
acquire the lock (i.e., lock was already held)
* @throws InterruptedException if interrupted
* @throws org.jboss.starobrno.lock.TimeoutException
@@ -175,8 +175,13 @@
// Better to check our records and lock again if necessary.
if (!ctx.hasLockedKey(key))
{
- if (!lockManager.lockAndRecord(key, ctx))
+ if (ctx.getOptionOverrides().isSuppressLocking())
{
+ // just record this in the ctx and rtn
+ ctx.addKeyLocked(key);
+ }
+ else if (!lockManager.lockAndRecord(key, ctx))
+ {
Object owner = lockManager.getOwner(key);
throw new TimeoutException("Unable to acquire lock on key [" + key
+ "] after [" + ctx.getLockAcquisitionTimeout(defaultLockAcquisitionTimeout) +
"] milliseconds for requestor [" + lockManager.getLockOwner(ctx) + "]! Lock
held by [" + owner + "]");
}
Modified:
core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/LockingInterceptor.java
===================================================================
---
core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/LockingInterceptor.java 2008-12-02
11:00:56 UTC (rev 7233)
+++
core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/LockingInterceptor.java 2008-12-02
12:27:32 UTC (rev 7234)
@@ -29,12 +29,7 @@
import org.jboss.starobrno.commands.tx.CommitCommand;
import org.jboss.starobrno.commands.tx.PrepareCommand;
import org.jboss.starobrno.commands.tx.RollbackCommand;
-import org.jboss.starobrno.commands.write.ClearCommand;
-import org.jboss.starobrno.commands.write.EvictCommand;
-import org.jboss.starobrno.commands.write.PutKeyValueCommand;
-import org.jboss.starobrno.commands.write.PutMapCommand;
-import org.jboss.starobrno.commands.write.RemoveCommand;
-import org.jboss.starobrno.commands.write.ReplaceCommand;
+import org.jboss.starobrno.commands.write.*;
import org.jboss.starobrno.container.DataContainer;
import org.jboss.starobrno.container.MVCCEntry;
import org.jboss.starobrno.container.MVCCEntryCreator;
@@ -80,10 +75,10 @@
@Override
protected boolean doBeforeCall(InvocationContext ctx, VisitableCommand command)
{
- if (ctx.getOptionOverrides().isSuppressLocking())
- {
- if (log.isWarnEnabled()) log.warn("Lock suppression not supported with
MVCC!");
- }
+// if (ctx.getOptionOverrides().isSuppressLocking())
+// {
+// if (log.isWarnEnabled()) log.warn("Lock suppression not supported with
MVCC!");
+// }
return true;
}
Modified:
core/branches/flat/src/main/java/org/jboss/starobrno/tree/TreeStructureSupport.java
===================================================================
---
core/branches/flat/src/main/java/org/jboss/starobrno/tree/TreeStructureSupport.java 2008-12-02
11:00:56 UTC (rev 7233)
+++
core/branches/flat/src/main/java/org/jboss/starobrno/tree/TreeStructureSupport.java 2008-12-02
12:27:32 UTC (rev 7234)
@@ -60,6 +60,10 @@
{
if (!exists(parent)) createNodeInCache(parent);
AtomicMap<Object, Fqn> parentStructure = getStructure(parent);
+ if (!cache.getConfiguration().isLockParentForChildInsertRemove())
+ {
+
cache.getInvocationContext().getOptionOverrides().setSuppressLocking(true);
+ }
parentStructure.put(fqn.getLastElement(), fqn);
// updateStructure(parent, parentStructure);
}
Modified:
core/branches/flat/src/main/java/org/jboss/starobrno/util/concurrent/locks/OwnableReentrantLock.java
===================================================================
---
core/branches/flat/src/main/java/org/jboss/starobrno/util/concurrent/locks/OwnableReentrantLock.java 2008-12-02
11:00:56 UTC (rev 7233)
+++
core/branches/flat/src/main/java/org/jboss/starobrno/util/concurrent/locks/OwnableReentrantLock.java 2008-12-02
12:27:32 UTC (rev 7234)
@@ -102,7 +102,14 @@
public void unlock()
{
- release(1);
+ try
+ {
+ release(1);
+ }
+ catch (IllegalMonitorStateException imse)
+ {
+ // ignore?
+ }
}
public ConditionObject newCondition()
@@ -136,7 +143,9 @@
{
int c = getState() - releases;
if (!currentRequestor().equals(owner))
+ {
throw new IllegalMonitorStateException(this.toString());
+ }
boolean free = false;
if (c == 0)
{
Modified:
core/branches/flat/src/test/java/org/jboss/starobrno/api/tree/NodeMoveAPITest.java
===================================================================
---
core/branches/flat/src/test/java/org/jboss/starobrno/api/tree/NodeMoveAPITest.java 2008-12-02
11:00:56 UTC (rev 7233)
+++
core/branches/flat/src/test/java/org/jboss/starobrno/api/tree/NodeMoveAPITest.java 2008-12-02
12:27:32 UTC (rev 7234)
@@ -584,15 +584,9 @@
{
TreeCache<Object, Object> tree = cacheTL.get();
Cache<Object, Object> cache = tree.getCache();
- ComponentRegistry cr = TestingUtil.extractComponentRegistry(cache);
- LockManager lm = cr.getComponent(LockManager.class);
- InvocationContextContainer icc =
cr.getComponent(InvocationContextContainer.class);
-// assert !TreeStructureSupport.isLocked(cache, A);
-// assert !TreeStructureSupport.isLocked(cache, Fqn.ROOT);
-
assert TreeStructureSupport.isLocked(cache, C);
- assert TreeStructureSupport.isLocked(cache, A_B);
+ assert !cache.getConfiguration().isLockParentForChildInsertRemove() ||
TreeStructureSupport.isLocked(cache, A_B);
assert TreeStructureSupport.isLocked(cache, A_B_C);
}
@@ -600,14 +594,7 @@
{
TreeCache<Object, Object> tree = cacheTL.get();
Cache<Object, Object> cache = tree.getCache();
- ComponentRegistry cr = TestingUtil.extractComponentRegistry(cache);
- LockManager lm = cr.getComponent(LockManager.class);
- InvocationContextContainer icc =
cr.getComponent(InvocationContextContainer.class);
-// assert !TreeStructureSupport.isLocked(cache, A);
-// assert !TreeStructureSupport.isLocked(cache, Fqn.ROOT);
-// assert !TreeStructureSupport.isLocked(cache, A_B_D);
-
// /a/b, /c, /c/e, /a/b/c and /a/b/c/e should all be locked.
assert TreeStructureSupport.isLocked(cache, A_B);
assert TreeStructureSupport.isLocked(cache, C);
Modified:
core/branches/flat/src/test/java/org/jboss/starobrno/profiling/TreeProfileTest.java
===================================================================
---
core/branches/flat/src/test/java/org/jboss/starobrno/profiling/TreeProfileTest.java 2008-12-02
11:00:56 UTC (rev 7233)
+++
core/branches/flat/src/test/java/org/jboss/starobrno/profiling/TreeProfileTest.java 2008-12-02
12:27:32 UTC (rev 7234)
@@ -42,7 +42,7 @@
/*
Test configuration options
*/
- protected static final long NUM_OPERATIONS = 100000; // DURATION is replaced with a
fixed number of operations instead.
+ protected static final long NUM_OPERATIONS = 1000000; // DURATION is replaced with a
fixed number of operations instead.
protected static final int NUM_THREADS = 25;
protected static final int MAX_RANDOM_SLEEP_MILLIS = 1;
protected static final int MAX_OVERALL_FQNS = 2000;