Author: manik.surtani(a)jboss.com
Date: 2008-05-09 13:57:36 -0400 (Fri, 09 May 2008)
New Revision: 5824
Modified:
core/trunk/src/main/java/org/jboss/cache/InvocationContext.java
core/trunk/src/main/java/org/jboss/cache/interceptors/ActivationInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/BaseRpcInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/BaseTransactionalContextInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/CacheStoreInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/DataGravitatorInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/InvalidationInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticCreateIfNotExistsInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticLockingInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticNodeInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticReplicationInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticValidatorInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/ReplicationInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java
core/trunk/src/main/java/org/jboss/cache/lock/LockManager.java
core/trunk/src/main/java/org/jboss/cache/transaction/TransactionTable.java
core/trunk/src/test/java/org/jboss/cache/optimistic/OptimisticLockInterceptorTest.java
Log:
JBCACHE-1328 - profile and optimise TxTable lookups
Modified: core/trunk/src/main/java/org/jboss/cache/InvocationContext.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/InvocationContext.java 2008-05-09 17:14:22
UTC (rev 5823)
+++ core/trunk/src/main/java/org/jboss/cache/InvocationContext.java 2008-05-09 17:57:36
UTC (rev 5824)
@@ -13,6 +13,7 @@
import org.jboss.cache.lock.NodeLock;
import org.jboss.cache.marshall.MethodCall;
import org.jboss.cache.transaction.GlobalTransaction;
+import org.jboss.cache.transaction.TransactionEntry;
import org.jboss.cache.transaction.TransactionTable;
import javax.transaction.Transaction;
@@ -33,6 +34,7 @@
private Transaction transaction;
private GlobalTransaction globalTransaction;
+ private TransactionEntry transactionEntry;
private Option optionOverrides;
// defaults to true.
private boolean originLocal = true;
@@ -108,6 +110,26 @@
}
/**
+ * @return the transaction entry associated with the current transaction, or null if
the current thread is not associated with a transaction.
+ * @since 2.2.0
+ */
+ public TransactionEntry getTransactionEntry()
+ {
+ return transactionEntry;
+ }
+
+ /**
+ * Sets the transaction entry to be associated with the current thread.
+ *
+ * @param transactionEntry transaction entry to set
+ * @since 2.2.0
+ */
+ public void setTransactionEntry(TransactionEntry transactionEntry)
+ {
+ this.transactionEntry = transactionEntry;
+ }
+
+ /**
* Retrieves the global transaction associated with this invocation
*
* @return the global transaction associated with this invocation
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/ActivationInterceptor.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/interceptors/ActivationInterceptor.java 2008-05-09
17:14:22 UTC (rev 5823)
+++
core/trunk/src/main/java/org/jboss/cache/interceptors/ActivationInterceptor.java 2008-05-09
17:57:36 UTC (rev 5824)
@@ -285,7 +285,7 @@
private void prepareCacheLoader(InvocationContext ctx) throws Throwable
{
GlobalTransaction gtx = ctx.getGlobalTransaction();
- TransactionEntry entry = txTable.get(gtx);
+ TransactionEntry entry = ctx.getTransactionEntry();
if (entry == null)
{
throw new Exception("entry for transaction " + gtx + " not found
in transaction table");
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/BaseRpcInterceptor.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/interceptors/BaseRpcInterceptor.java 2008-05-09
17:14:22 UTC (rev 5823)
+++
core/trunk/src/main/java/org/jboss/cache/interceptors/BaseRpcInterceptor.java 2008-05-09
17:57:36 UTC (rev 5824)
@@ -108,8 +108,7 @@
Transaction tx = ctx.getTransaction();
if (tx != null)
{
- GlobalTransaction gtx = ctx.getGlobalTransaction();
- TransactionEntry te = txTable.get(gtx);
+ TransactionEntry te = ctx.getTransactionEntry();
if (te != null)
{
if (te.isForceAsyncReplication()) sync = false;
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/BaseTransactionalContextInterceptor.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/interceptors/BaseTransactionalContextInterceptor.java 2008-05-09
17:14:22 UTC (rev 5823)
+++
core/trunk/src/main/java/org/jboss/cache/interceptors/BaseTransactionalContextInterceptor.java 2008-05-09
17:57:36 UTC (rev 5824)
@@ -52,6 +52,7 @@
}
ctx.setTransaction(tx);
ctx.setGlobalTransaction(gtx);
+ ctx.setTransactionEntry(txTable.get(gtx));
}
/**
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java 2008-05-09
17:14:22 UTC (rev 5823)
+++
core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java 2008-05-09
17:57:36 UTC (rev 5824)
@@ -28,7 +28,6 @@
import org.jboss.cache.lock.LockManager;
import org.jboss.cache.lock.NodeLock;
import org.jboss.cache.notifications.Notifier;
-import org.jboss.cache.transaction.GlobalTransaction;
import org.jboss.cache.transaction.TransactionEntry;
import org.jboss.cache.transaction.TransactionTable;
@@ -92,7 +91,7 @@
{
if (command.getFqn() != null)
{
- loadIfNeeded(ctx, command.getFqn(), null, false, true, false,
txTable.get(ctx.getGlobalTransaction()), false, false, false);
+ loadIfNeeded(ctx, command.getFqn(), null, false, true, false,
ctx.getTransactionEntry(), false, false, false);
}
return invokeNextInterceptor(ctx, command);
}
@@ -102,7 +101,7 @@
{
if (command.getFqn() != null)
{
- loadIfNeeded(ctx, command.getFqn(), command.getKey(), false, useCacheStore,
!useCacheStore, txTable.get(ctx.getGlobalTransaction()), false, false, false);
+ loadIfNeeded(ctx, command.getFqn(), command.getKey(), false, useCacheStore,
!useCacheStore, ctx.getTransactionEntry(), false, false, false);
}
return invokeNextInterceptor(ctx, command);
}
@@ -114,9 +113,9 @@
{
if (command.getTo() != null)
{
- loadIfNeeded(ctx, command.getTo(), null, false, false, true,
txTable.get(ctx.getGlobalTransaction()), false, true, false);
+ loadIfNeeded(ctx, command.getTo(), null, false, false, true,
ctx.getTransactionEntry(), false, true, false);
}
- loadIfNeeded(ctx, command.getFqn(), null, false, false, true,
txTable.get(ctx.getGlobalTransaction()), true, true, false);
+ loadIfNeeded(ctx, command.getFqn(), null, false, false, true,
ctx.getTransactionEntry(), true, true, false);
}
return invokeNextInterceptor(ctx, command);
}
@@ -126,7 +125,7 @@
{
if (command.getFqn() != null)
{
- loadIfNeeded(ctx, command.getFqn(), command.getKey(), false, false, true,
txTable.get(ctx.getGlobalTransaction()), false, false, false);
+ loadIfNeeded(ctx, command.getFqn(), command.getKey(), false, false, true,
ctx.getTransactionEntry(), false, false, false);
}
return invokeNextInterceptor(ctx, command);
}
@@ -137,7 +136,7 @@
{
if (command.getFqn() != null)
{
- loadIfNeeded(ctx, command.getFqn(), null, false, false, true,
txTable.get(ctx.getGlobalTransaction()), false, false, !usingOptimisticInvalidation);
+ loadIfNeeded(ctx, command.getFqn(), null, false, false, true,
ctx.getTransactionEntry(), false, false, !usingOptimisticInvalidation);
}
return invokeNextInterceptor(ctx, command);
}
@@ -148,7 +147,7 @@
Fqn fqn = command.getFqn();
if (fqn != null)
{
- loadIfNeeded(ctx, fqn, null, false, false, false,
txTable.get(ctx.getGlobalTransaction()), false, false, true);
+ loadIfNeeded(ctx, fqn, null, false, false, false, ctx.getTransactionEntry(),
false, false, true);
NodeSPI n = dataContainer.peek(fqn, true, true);
loadChildren(fqn, n, false, false, ctx);
}
@@ -161,7 +160,7 @@
{
if (command.getFqn() != null)
{
- loadIfNeeded(ctx, command.getFqn(), null, true, false, true,
txTable.get(ctx.getGlobalTransaction()), false, false, false);
+ loadIfNeeded(ctx, command.getFqn(), null, true, false, true,
ctx.getTransactionEntry(), false, false, false);
}
return invokeNextInterceptor(ctx, command);
}
@@ -171,7 +170,7 @@
{
if (command.getFqn() != null)
{
- loadIfNeeded(ctx, command.getFqn(), null, true, false, true,
txTable.get(ctx.getGlobalTransaction()), false, false, false);
+ loadIfNeeded(ctx, command.getFqn(), null, true, false, true,
ctx.getTransactionEntry(), false, false, false);
}
return invokeNextInterceptor(ctx, command);
}
@@ -183,7 +182,7 @@
if (trace) log.trace("Removing temporarily created nodes from
treecache");
// this needs to be done in reverse order.
- List list =
txTable.get(ctx.getGlobalTransaction()).getDummyNodesCreatedByCacheLoader();
+ List list = ctx.getTransactionEntry().getDummyNodesCreatedByCacheLoader();
if (list != null && list.size() > 0)
{
ListIterator i = list.listIterator(list.size());
@@ -208,7 +207,7 @@
{
if (configuration.isNodeLockingOptimistic() && command.getFqn() != null)
{
- loadIfNeeded(ctx, command.getFqn(), null, false, false, false,
txTable.get(ctx.getGlobalTransaction()), false, false, false);
+ loadIfNeeded(ctx, command.getFqn(), null, false, false, false,
ctx.getTransactionEntry(), false, false, false);
}
return invokeNextInterceptor(ctx, command);
}
@@ -218,7 +217,7 @@
{
if (command.getFqn() != null && !useCacheStore)
{
- loadIfNeeded(ctx, command.getFqn(), command.getKey(), false, false, false,
txTable.get(ctx.getGlobalTransaction()), false, false, false);
+ loadIfNeeded(ctx, command.getFqn(), command.getKey(), false, false, false,
ctx.getTransactionEntry(), false, false, false);
}
return invokeNextInterceptor(ctx, command);
}
@@ -229,7 +228,7 @@
Fqn fqn = command.getFqn();
if (fqn != null && !useCacheStore)
{
- loadIfNeeded(ctx, fqn, null, false, true, false,
txTable.get(ctx.getGlobalTransaction()), false, false, false);
+ loadIfNeeded(ctx, fqn, null, false, true, false, ctx.getTransactionEntry(),
false, false, false);
}
return invokeNextInterceptor(ctx, command);
}
@@ -268,7 +267,7 @@
}
// if (!initNode && !wasRemovedInTx(fqn, ctx.getGlobalTransaction()))
- if (!wasRemovedInTx(fqn, ctx.getGlobalTransaction()))
+ if (!wasRemovedInTx(fqn, ctx))
{
if (bypassLoadingData)
{
@@ -437,10 +436,10 @@
* transaction.
* This is O(N) WRT to the number of modifications so far.
*/
- private boolean wasRemovedInTx(Fqn fqn, GlobalTransaction t)
+ private boolean wasRemovedInTx(Fqn fqn, InvocationContext ctx)
{
- if (t == null) return false;
- TransactionEntry entry = txTable.get(t);
+ TransactionEntry entry = ctx.getTransactionEntry();
+ if (entry == null) return false;
for (ReversibleCommand txCacheCommand : entry.getCacheLoaderModifications())
{
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/CacheStoreInterceptor.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/interceptors/CacheStoreInterceptor.java 2008-05-09
17:14:22 UTC (rev 5823)
+++
core/trunk/src/main/java/org/jboss/cache/interceptors/CacheStoreInterceptor.java 2008-05-09
17:57:36 UTC (rev 5824)
@@ -179,7 +179,7 @@
if (inTransaction())
{
if (trace) log.trace("transactional so don't put stuff in the cloader
yet.");
- prepareCacheLoader(command.getGlobalTransaction(), command.isOnePhaseCommit());
+ prepareCacheLoader(command.getGlobalTransaction(), ctx.getTransactionEntry(),
command.isOnePhaseCommit());
}
return invokeNextInterceptor(ctx, command);
}
@@ -190,7 +190,7 @@
if (inTransaction())
{
if (trace) log.trace("transactional so don't put stuff in the cloader
yet.");
- prepareCacheLoader(command.getGlobalTransaction(), command.isOnePhaseCommit());
+ prepareCacheLoader(command.getGlobalTransaction(), ctx.getTransactionEntry(),
command.isOnePhaseCommit());
}
return invokeNextInterceptor(ctx, command);
}
@@ -346,10 +346,8 @@
return retval;
}
- private void prepareCacheLoader(GlobalTransaction gtx, boolean onePhase) throws
Throwable
+ private void prepareCacheLoader(GlobalTransaction gtx, TransactionEntry entry, boolean
onePhase) throws Throwable
{
-
- TransactionEntry entry = txTable.get(gtx);
if (entry == null)
{
throw new Exception("entry for transaction " + gtx + " not found
in transaction table");
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/DataGravitatorInterceptor.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/interceptors/DataGravitatorInterceptor.java 2008-05-09
17:14:22 UTC (rev 5823)
+++
core/trunk/src/main/java/org/jboss/cache/interceptors/DataGravitatorInterceptor.java 2008-05-09
17:57:36 UTC (rev 5824)
@@ -32,7 +32,6 @@
import org.jboss.cache.factories.annotations.Start;
import org.jboss.cache.marshall.NodeData;
import org.jboss.cache.transaction.GlobalTransaction;
-import org.jboss.cache.transaction.TransactionEntry;
import org.jgroups.Address;
import org.jgroups.blocks.GroupRequest;
import org.jgroups.blocks.RspFilter;
@@ -362,11 +361,6 @@
}
}
- private TransactionEntry getTransactionEntry(GlobalTransaction gtx)
- {
- return cacheSPI.getTransactionTable().get(gtx);
- }
-
private BackupData localBackupGet(Fqn fqn, InvocationContext ctx) throws
CacheException
{
GravitateResult result = cacheSPI.gravitateData(fqn, true, ctx);// a
"local" gravitation
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/InvalidationInterceptor.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/interceptors/InvalidationInterceptor.java 2008-05-09
17:14:22 UTC (rev 5823)
+++
core/trunk/src/main/java/org/jboss/cache/interceptors/InvalidationInterceptor.java 2008-05-09
17:57:36 UTC (rev 5824)
@@ -130,7 +130,7 @@
if (trace) log.trace("Entering InvalidationInterceptor's prepare
phase");
// fetch the modifications before the transaction is committed (and thus removed
from the txTable)
GlobalTransaction gtx = ctx.getGlobalTransaction();
- TransactionEntry entry = txTable.get(gtx);
+ TransactionEntry entry = ctx.getTransactionEntry();
if (entry == null) throw new IllegalStateException("cannot find transaction
entry for " + gtx);
List<ReversibleCommand> modifications = new
LinkedList<ReversibleCommand>(command.getModifications());
if (modifications.size() > 0)
@@ -154,7 +154,7 @@
{
// here we just record the modifications but actually do the invalidate in
commit.
GlobalTransaction gtx = ctx.getGlobalTransaction();
- TransactionEntry entry = txTable.get(gtx);
+ TransactionEntry entry = ctx.getTransactionEntry();
if (entry == null) throw new IllegalStateException("cannot find transaction
entry for " + gtx);
List<ReversibleCommand> modifications = new
LinkedList<ReversibleCommand>(command.getModifications());
if (modifications.size() > 0)
@@ -240,7 +240,7 @@
{
try
{
- TransactionWorkspace workspace = configuration.isNodeLockingOptimistic() ?
getWorkspace(gtx) : null;
+ TransactionWorkspace workspace = configuration.isNodeLockingOptimistic() ?
getWorkspace(ctx) : null;
for (Fqn fqn : filterVisitor.result) invalidateAcrossCluster(fqn,
workspace, defaultSynchronous, ctx);
}
catch (Throwable t)
@@ -383,9 +383,9 @@
return v;
}
- protected TransactionWorkspace getWorkspace(GlobalTransaction gtx)
+ protected TransactionWorkspace getWorkspace(InvocationContext ctx)
{
- OptimisticTransactionEntry entry = (OptimisticTransactionEntry) txTable.get(gtx);
+ OptimisticTransactionEntry entry = (OptimisticTransactionEntry)
ctx.getTransactionEntry();
return entry.getTransactionWorkSpace();
}
}
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticCreateIfNotExistsInterceptor.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticCreateIfNotExistsInterceptor.java 2008-05-09
17:14:22 UTC (rev 5823)
+++
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticCreateIfNotExistsInterceptor.java 2008-05-09
17:57:36 UTC (rev 5824)
@@ -111,7 +111,7 @@
boolean debug = log.isDebugEnabled();
GlobalTransaction gtx = getGlobalTransaction(ctx);
- TransactionWorkspace workspace = getTransactionWorkspace(gtx);
+ TransactionWorkspace workspace = getTransactionWorkspace(ctx);
WorkspaceNode workspaceNode;
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticInterceptor.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticInterceptor.java 2008-05-09
17:14:22 UTC (rev 5823)
+++
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticInterceptor.java 2008-05-09
17:57:36 UTC (rev 5824)
@@ -41,13 +41,13 @@
this.txTable = txTable;
}
- protected TransactionWorkspace getTransactionWorkspace(GlobalTransaction gtx) throws
CacheException
+ protected TransactionWorkspace getTransactionWorkspace(InvocationContext ctx) throws
CacheException
{
- OptimisticTransactionEntry transactionEntry = (OptimisticTransactionEntry)
txTable.get(gtx);
+ OptimisticTransactionEntry transactionEntry = (OptimisticTransactionEntry)
ctx.getTransactionEntry();
if (transactionEntry == null)
{
- throw new CacheException("Unable to map global transaction " + gtx +
" to transaction entry when trying to retrieve transaction workspace.");
+ throw new CacheException("Unable to map global transaction " +
ctx.getGlobalTransaction() + " to transaction entry when trying to retrieve
transaction workspace.");
}
// try and get the workspace from the transaction
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticLockingInterceptor.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticLockingInterceptor.java 2008-05-09
17:14:22 UTC (rev 5823)
+++
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticLockingInterceptor.java 2008-05-09
17:57:36 UTC (rev 5824)
@@ -53,8 +53,8 @@
}
try
{
- TransactionWorkspace<?, ?> workspace = getTransactionWorkspace(gtx);
- TransactionEntry te = txTable.get(gtx);
+ TransactionWorkspace<?, ?> workspace = getTransactionWorkspace(ctx);
+ TransactionEntry te = ctx.getTransactionEntry();
if (log.isDebugEnabled()) log.debug("Locking nodes in transaction workspace
for GlobalTransaction " + gtx);
for (WorkspaceNode workspaceNode : workspace.getNodes().values())
@@ -82,7 +82,7 @@
//we have failed - set to rollback and throw exception
try
{
- unlock(gtx);
+ unlock(ctx, gtx);
}
catch (Throwable t)
{
@@ -121,7 +121,7 @@
{
try
{
- unlock(getGlobalTransaction(ctx));
+ unlock(ctx, getGlobalTransaction(ctx));
}
catch (Exception e)
{
@@ -135,11 +135,11 @@
/**
* Releases all locks held by the specified global transaction.
*
- * @param gtx which holds locks
+ * @param ctx Invocation Context
*/
- private void unlock(GlobalTransaction gtx)
+ private void unlock(InvocationContext ctx, GlobalTransaction gtx)
{
- TransactionEntry entry = txTable.get(gtx);
+ TransactionEntry entry = ctx.getTransactionEntry();
entry.releaseAllLocksFIFO(gtx);
}
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticNodeInterceptor.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticNodeInterceptor.java 2008-05-09
17:14:22 UTC (rev 5823)
+++
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticNodeInterceptor.java 2008-05-09
17:57:36 UTC (rev 5824)
@@ -87,7 +87,7 @@
public Object visitRemoveNodeCommand(InvocationContext ctx, RemoveNodeCommand command)
throws Throwable
{
GlobalTransaction gtx = getGlobalTransaction(ctx);
- TransactionWorkspace workspace = getTransactionWorkspace(gtx);
+ TransactionWorkspace workspace = getTransactionWorkspace(ctx);
WorkspaceNode workspaceNode = fetchWorkspaceNode(ctx, command.getFqn(), workspace,
false, true);
if (workspaceNode != null)
{
@@ -102,7 +102,7 @@
public Object visitPutKeyValueCommand(InvocationContext ctx, PutKeyValueCommand
command) throws Throwable
{
GlobalTransaction gtx = getGlobalTransaction(ctx);
- TransactionWorkspace workspace = getTransactionWorkspace(gtx);
+ TransactionWorkspace workspace = getTransactionWorkspace(ctx);
WorkspaceNode workspaceNode = fetchWorkspaceNode(ctx, command.getFqn(), workspace,
true, true);
if (workspaceNode != null)
{
@@ -125,7 +125,7 @@
public Object visitPutDataMapCommand(InvocationContext ctx, PutDataMapCommand command)
throws Throwable
{
GlobalTransaction gtx = getGlobalTransaction(ctx);
- TransactionWorkspace workspace = getTransactionWorkspace(gtx);
+ TransactionWorkspace workspace = getTransactionWorkspace(ctx);
WorkspaceNode workspaceNode = fetchWorkspaceNode(ctx, command.getFqn(), workspace,
true, true);
if (workspaceNode != null)
{
@@ -149,7 +149,7 @@
public Object visitMoveCommand(InvocationContext ctx, MoveCommand command) throws
Throwable
{
GlobalTransaction gtx = getGlobalTransaction(ctx);
- TransactionWorkspace workspace = getTransactionWorkspace(gtx);
+ TransactionWorkspace workspace = getTransactionWorkspace(ctx);
WorkspaceNode workspaceNode = fetchWorkspaceNode(ctx, command.getFqn(), workspace,
true, true);
if (ctx.isOriginLocal() && ctx.getOptionOverrides() != null &&
ctx.getOptionOverrides().getDataVersion() != null)
{
@@ -168,7 +168,7 @@
public Object visitRemoveKeyCommand(InvocationContext ctx, RemoveKeyCommand command)
throws Throwable
{
GlobalTransaction gtx = getGlobalTransaction(ctx);
- TransactionWorkspace workspace = getTransactionWorkspace(gtx);
+ TransactionWorkspace workspace = getTransactionWorkspace(ctx);
WorkspaceNode workspaceNode = fetchWorkspaceNode(ctx, command.getFqn(), workspace,
true, true);
if (workspaceNode != null)
@@ -184,7 +184,7 @@
public Object visitRemoveDataCommand(InvocationContext ctx, RemoveDataCommand command)
throws Throwable
{
GlobalTransaction gtx = getGlobalTransaction(ctx);
- TransactionWorkspace workspace = getTransactionWorkspace(gtx);
+ TransactionWorkspace workspace = getTransactionWorkspace(ctx);
WorkspaceNode workspaceNode = fetchWorkspaceNode(ctx, command.getFqn(), workspace,
true, true);
if (workspaceNode != null)
{
@@ -198,7 +198,7 @@
@Override
public Object visitGetKeyValueCommand(InvocationContext ctx, GetKeyValueCommand
command) throws Throwable
{
- TransactionWorkspace workspace =
getTransactionWorkspace(getGlobalTransaction(ctx));
+ TransactionWorkspace workspace = getTransactionWorkspace(ctx);
Object result;
WorkspaceNode workspaceNode = fetchWorkspaceNode(ctx, command.getFqn(), workspace,
false, false);
@@ -222,7 +222,7 @@
@Override
public Object visitGetKeysCommand(InvocationContext ctx, GetKeysCommand command)
throws Throwable
{
- TransactionWorkspace workspace =
getTransactionWorkspace(getGlobalTransaction(ctx));
+ TransactionWorkspace workspace = getTransactionWorkspace(ctx);
Object result;
Fqn fqn = command.getFqn();
WorkspaceNode workspaceNode = fetchWorkspaceNode(ctx, fqn, workspace, false,
false);
@@ -245,7 +245,7 @@
@Override
public Object visitGetDataMapCommand(InvocationContext ctx, GetDataMapCommand command)
throws Throwable
{
- TransactionWorkspace workspace =
getTransactionWorkspace(getGlobalTransaction(ctx));
+ TransactionWorkspace workspace = getTransactionWorkspace(ctx);
Object result;
WorkspaceNode workspaceNode = fetchWorkspaceNode(ctx, command.getFqn(), workspace,
false, false);
if (workspaceNode == null)
@@ -267,7 +267,7 @@
@Override
public Object visitGetChildrenNamesCommand(InvocationContext ctx,
GetChildrenNamesCommand command) throws Throwable
{
- TransactionWorkspace workspace =
getTransactionWorkspace(getGlobalTransaction(ctx));
+ TransactionWorkspace workspace = getTransactionWorkspace(ctx);
Object result;
WorkspaceNode workspaceNode = fetchWorkspaceNode(ctx, command.getFqn(), workspace,
false, false);
if (workspaceNode == null)
@@ -289,7 +289,7 @@
@Override
public Object visitGetNodeCommand(InvocationContext ctx, GetNodeCommand command)
throws Throwable
{
- TransactionWorkspace workspace =
getTransactionWorkspace(getGlobalTransaction(ctx));
+ TransactionWorkspace workspace = getTransactionWorkspace(ctx);
Object result;
WorkspaceNode workspaceNode = fetchWorkspaceNode(ctx, command.getFqn(), workspace,
false, false);
if (workspaceNode == null)
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticReplicationInterceptor.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticReplicationInterceptor.java 2008-05-09
17:14:22 UTC (rev 5823)
+++
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticReplicationInterceptor.java 2008-05-09
17:57:36 UTC (rev 5824)
@@ -169,8 +169,7 @@
{
return invokeNextInterceptor(ctx, command);
}
- GlobalTransaction gtx = getGlobalTransaction(ctx);
- if (command.isPutForExternalRead())
txTable.get(gtx).setForceAsyncReplication(true);
+ if (command.isPutForExternalRead())
ctx.getTransactionEntry().setForceAsyncReplication(true);
return invokeNextInterceptor(ctx, command);
}
@@ -196,7 +195,7 @@
// Map method calls to data versioned equivalents.
// See JBCACHE-843 and docs/design/DataVersioning.txt
//TODO: 2.2.0: make the visitor a field
- DataVersionPopulator populator = new
DataVersionPopulator(getTransactionWorkspace(gtx));
+ DataVersionPopulator populator = new
DataVersionPopulator(getTransactionWorkspace(ctx));
List<ReversibleCommand> clonedModifications = new
ArrayList<ReversibleCommand>(command.getModifications().size());
for (ReversibleCommand command1 : command.getModifications())
{
@@ -388,12 +387,12 @@
}
- protected TransactionWorkspace getTransactionWorkspace(GlobalTransaction gtx) throws
CacheException
+ protected TransactionWorkspace getTransactionWorkspace(InvocationContext ctx) throws
CacheException
{
- OptimisticTransactionEntry transactionEntry = (OptimisticTransactionEntry)
txTable.get(gtx);
+ OptimisticTransactionEntry transactionEntry = (OptimisticTransactionEntry)
ctx.getTransactionEntry();
if (transactionEntry == null)
{
- throw new CacheException("unable to map global transaction " + gtx +
" to transaction entry");
+ throw new CacheException("unable to map global transaction " + ctx +
" to transaction entry");
}
// try and get the workspace from the transaction
return transactionEntry.getTransactionWorkSpace();
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticValidatorInterceptor.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticValidatorInterceptor.java 2008-05-09
17:14:22 UTC (rev 5823)
+++
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticValidatorInterceptor.java 2008-05-09
17:57:36 UTC (rev 5824)
@@ -68,7 +68,7 @@
@Override
public Object visitOptimisticPrepareCommand(InvocationContext ctx,
OptimisticPrepareCommand command) throws Throwable
{
- TransactionWorkspace workspace =
getTransactionWorkspace(getGlobalTransaction(ctx));
+ TransactionWorkspace workspace = getTransactionWorkspace(ctx);
// There is no guarantee that this collection is in any order!
Collection<WorkspaceNode> nodes = workspace.getNodes().values();
@@ -146,7 +146,7 @@
TransactionWorkspace workspace;
try
{
- workspace = getTransactionWorkspace(gtx);
+ workspace = getTransactionWorkspace(ctx);
}
catch (CacheException e)
{
@@ -260,7 +260,7 @@
public Object visitRollbackCommand(InvocationContext ctx, RollbackCommand command)
throws Throwable
{
TransactionWorkspace workspace;
- workspace = getTransactionWorkspace(getGlobalTransaction(ctx));
+ workspace = getTransactionWorkspace(ctx);
workspace.clearNodes();
return invokeNextInterceptor(ctx, command);
}
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java 2008-05-09
17:14:22 UTC (rev 5823)
+++
core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java 2008-05-09
17:57:36 UTC (rev 5824)
@@ -103,7 +103,7 @@
Fqn childFqn = Fqn.fromElements(childName);
NodeSPI childNode = n.getChildDirect(childFqn);
if (childNode == null) childNode = n.addChildDirect(childFqn);
- lockManager.manageReverseRemove(ctx.getGlobalTransaction(), childNode, true,
null);
+ lockManager.manageReverseRemove(ctx, childNode, true, null);
n = childNode;
}
}
@@ -122,7 +122,7 @@
if (!command.isOnePhaseCommit()) return invokeNextInterceptor(ctx, command);
// commit propagated up from the tx interceptor
- commit(ctx.getGlobalTransaction());
+ commit(ctx.getTransactionEntry(), ctx.getGlobalTransaction());
Object retVal = invokeNextInterceptor(ctx, command);
txTable.cleanup(ctx.getGlobalTransaction());
return retVal;
@@ -131,7 +131,7 @@
@Override
public Object handleCommitCommand(InvocationContext ctx, CommitCommand command) throws
Throwable
{
- commit(command.getGlobalTransaction());
+ commit(ctx.getTransactionEntry(), command.getGlobalTransaction());
if (trace) log.trace("bypassed locking as method commit() doesn't require
locking");
Object retVal = invokeNextInterceptor(ctx, command);
txTable.cleanup(command.getGlobalTransaction());
@@ -141,7 +141,7 @@
@Override
public Object handleRollbackCommand(InvocationContext ctx, RollbackCommand command)
throws Throwable
{
- TransactionEntry entry = txTable.get(command.getGlobalTransaction());
+ TransactionEntry entry = ctx.getTransactionEntry();
if (trace)
{
log.trace("called to rollback cache with GlobalTransaction=" +
command.getGlobalTransaction());
@@ -180,7 +180,7 @@
lockManager.lock(ctx, command.getFqn(), NodeLock.LockType.WRITE, false, timeout,
true, false, null, false);
if (ctx.getGlobalTransaction() != null)
{
- txTable.get(ctx.getGlobalTransaction()).addRemovedNode(command.getFqn());
+ ctx.getTransactionEntry().addRemovedNode(command.getFqn());
}
lockManager.acquireLocksOnChildren(dataContainer.peek(command.getFqn(), true,
false), NodeLock.LockType.WRITE, ctx);
}
@@ -213,7 +213,7 @@
TransactionEntry entry = null;
if (ctx.getGlobalTransaction() != null)
{
- entry = txTable.get(ctx.getGlobalTransaction());
+ entry = ctx.getTransactionEntry();
entry.addRemovedNode(command.getFqn());
for (NodeSPI nodeSPI : createdNodes)
{
@@ -308,10 +308,9 @@
/**
* Remove all locks held by <tt>tx</tt>, remove the transaction from the
transaction table
*/
- private void commit(GlobalTransaction gtx)
+ private void commit(TransactionEntry entry, GlobalTransaction gtx)
{
if (trace) log.trace("committing cache with gtx " + gtx);
- TransactionEntry entry = txTable.get(gtx);
if (entry == null)
{
log.error("entry for transaction " + gtx + " not found (maybe
already committed)");
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/ReplicationInterceptor.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/interceptors/ReplicationInterceptor.java 2008-05-09
17:14:22 UTC (rev 5823)
+++
core/trunk/src/main/java/org/jboss/cache/interceptors/ReplicationInterceptor.java 2008-05-09
17:57:36 UTC (rev 5824)
@@ -72,7 +72,7 @@
Object returnValue = invokeNextInterceptor(ctx, command);
if (command.isPutForExternalRead())
{
- txTable.get(command.getGlobalTransaction()).setForceAsyncReplication(true);
+ ctx.getTransactionEntry().setForceAsyncReplication(true);
}
return returnValue;
}
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java 2008-05-09
17:14:22 UTC (rev 5823)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java 2008-05-09
17:57:36 UTC (rev 5824)
@@ -349,23 +349,20 @@
// entry for TX in txTable, the modifications
// below will need this entry to add their modifications
// under the GlobalTx key
- TransactionEntry entry;
- if (txTable.get(gtx) == null)
+ TransactionEntry entry = txTable.get(gtx);
+ if (entry == null)
{
// create a new transaction entry
entry = configuration.isNodeLockingOptimistic() ? new
OptimisticTransactionEntry(ltx) : new TransactionEntry(ltx);
log.debug("creating new tx entry");
txTable.put(gtx, entry);
+ ctx.setTransactionEntry(entry);
if (trace) log.trace("TxTable contents: " + txTable);
}
- else
- {
- entry = txTable.get(gtx);
- }
setTransactionalContext(ltx, gtx, ctx);
// register a sync handler for this tx.
- registerHandler(ltx, new RemoteSynchronizationHandler(gtx, ltx), ctx, entry);
+ registerHandler(ltx, new RemoteSynchronizationHandler(gtx, ltx), ctx);
if (configuration.isNodeLockingOptimistic())
{
@@ -469,7 +466,7 @@
if (optionOverride != null
&& (optionOverride.isForceAsynchronous() ||
optionOverride.isForceSynchronous()))
{
- TransactionEntry entry = txTable.get(ctx.getGlobalTransaction());
+ TransactionEntry entry = ctx.getTransactionEntry();
if (entry != null)
{
if (optionOverride.isForceAsynchronous())
@@ -803,7 +800,7 @@
log.warn("Commit failed. Clearing stale locks.");
try
{
- cleanupStaleLocks(gtx);
+ cleanupStaleLocks(ctx);
}
catch (RuntimeException re)
{
@@ -823,12 +820,12 @@
}
- private void cleanupStaleLocks(GlobalTransaction gtx) throws Throwable
+ private void cleanupStaleLocks(InvocationContext ctx) throws Throwable
{
- TransactionEntry entry = txTable.get(gtx);
+ TransactionEntry entry = ctx.getTransactionEntry();
if (entry != null)
{
- entry.releaseAllLocksLIFO(gtx);
+ entry.releaseAllLocksLIFO(ctx.getGlobalTransaction());
}
}
@@ -986,7 +983,7 @@
}
// see the comment in the LocalSyncHandler for the last isOriginLocal param.
LocalSynchronizationHandler myHandler = new LocalSynchronizationHandler(gtx,
tx, !ctx.isOriginLocal());
- registerHandler(tx, myHandler, ctx, txTable.get(gtx));
+ registerHandler(tx, myHandler, ctx);
}
}
else if ((gtx = (GlobalTransaction) rollbackTransactions.get(tx)) != null)
@@ -1008,9 +1005,9 @@
* @param handler
* @throws Exception
*/
- private void registerHandler(Transaction tx, Synchronization handler,
InvocationContext ctx, TransactionEntry entry) throws Exception
+ private void registerHandler(Transaction tx, Synchronization handler,
InvocationContext ctx) throws Exception
{
- OrderedSynchronizationHandler orderedHandler =
entry.getOrderedSynchronizationHandler();
//OrderedSynchronizationHandler.getInstance(tx);
+ OrderedSynchronizationHandler orderedHandler =
ctx.getTransactionEntry().getOrderedSynchronizationHandler();
//OrderedSynchronizationHandler.getInstance(tx);
if (trace) log.trace("registering for TX completion:
SynchronizationHandler(" + handler + ")");
@@ -1161,6 +1158,7 @@
modifications = entry.getModifications();
ctx = invocationContextContainer.get();
+ ctx.setTransactionEntry(entry);
if (ctx.isOptionsUninitialised() && entry.getOption() != null)
ctx.setOptionOverrides(entry.getOption());
assertCanContinue();
@@ -1179,6 +1177,7 @@
}
entry = txTable.get(gtx);
+ ctx.setTransactionEntry(entry);
if (ctx.isOptionsUninitialised() && entry != null &&
entry.getOption() != null)
{
Modified: core/trunk/src/main/java/org/jboss/cache/lock/LockManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/lock/LockManager.java 2008-05-09 17:14:22 UTC
(rev 5823)
+++ core/trunk/src/main/java/org/jboss/cache/lock/LockManager.java 2008-05-09 17:57:36 UTC
(rev 5824)
@@ -148,7 +148,7 @@
// actually acquire the lock we need. This method blocks.
acquireNodeLock(ctx, currentNode, owner, gtx, lockTypeRequired, timeout);
- manageReverseRemove(gtx, currentNode, reverseRemoveCheck, createdNodes);
+ manageReverseRemove(ctx, currentNode, reverseRemoveCheck, createdNodes);
// make sure the lock we acquired isn't on a deleted node/is an orphan!!
// look into invalidated nodes as well
NodeSPI repeek = dataContainer.peek(currentNodeFqn, true, true);
@@ -257,18 +257,18 @@
* Test if this node needs to be 'undeleted'
* reverse the "remove" if the node has been previously removed in the same
tx, if this operation is a put()
*/
- public void manageReverseRemove(GlobalTransaction gtx, NodeSPI childNode, boolean
reverseRemoveCheck, List createdNodes)
+ public void manageReverseRemove(InvocationContext ctx, NodeSPI childNode, boolean
reverseRemoveCheck, List createdNodes)
{
- if (gtx != null) //if no tx then reverse remove does not make sense
+ if (ctx.getGlobalTransaction() != null) //if no tx then reverse remove does not
make sense
{
Fqn fqn = childNode.getFqn();
- TransactionEntry entry = txTable.get(gtx);
+ TransactionEntry entry = ctx.getTransactionEntry();
boolean needToReverseRemove = reverseRemoveCheck &&
childNode.isDeleted() && isNodeRemovedInCurrentTransaction(entry, fqn);
if (!needToReverseRemove) return;
childNode.markAsDeleted(false);
//if we'll rollback the tx data should be added to the node again
Map oldData = new HashMap(childNode.getDataDirect());
- PutDataMapCommand command = commandsFactory.buildPutDataMapCommand(gtx, fqn,
oldData, false, false);
+ PutDataMapCommand command =
commandsFactory.buildPutDataMapCommand(ctx.getGlobalTransaction(), fqn, oldData, false,
false);
// txTable.get(gtx).addUndoOperation(command); --- now need to make sure this is
added to the normal mods list instead
entry.addModification(command);
//we're prepared for rollback, now reset the node
Modified: core/trunk/src/main/java/org/jboss/cache/transaction/TransactionTable.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/transaction/TransactionTable.java 2008-05-09
17:14:22 UTC (rev 5823)
+++ core/trunk/src/main/java/org/jboss/cache/transaction/TransactionTable.java 2008-05-09
17:57:36 UTC (rev 5824)
@@ -52,6 +52,8 @@
*/
protected final Map<GlobalTransaction, TransactionEntry> gtx2EntryMap = new
ConcurrentHashMap<GlobalTransaction, TransactionEntry>();
+ protected final Map<GlobalTransaction, Transaction> gtx2TxMap = new
ConcurrentHashMap<GlobalTransaction, Transaction>();
+
private TransactionManager transactionManager = null;
private RPCManager rpcManager;
@@ -101,9 +103,7 @@
}
/**
- * Returns the local transaction associated with a GlobalTransaction. Not
- * very efficient as the values have to be iterated over, don't use
- * frequently
+ * Returns the local transaction associated with a GlobalTransaction.
*
* @param gtx The GlobalTransaction
* @return Transaction. The local transaction associated with a given
@@ -112,20 +112,8 @@
*/
public Transaction getLocalTransaction(GlobalTransaction gtx)
{
- if (gtx == null)
- return null;
- Transaction localTx;
- GlobalTransaction globalTx;
- for (Map.Entry<Transaction, GlobalTransaction> entry : tx2gtxMap.entrySet())
- {
- localTx = entry.getKey();
- globalTx = entry.getValue();
- if (gtx.equals(globalTx))
- {
- return localTx;
- }
- }
- return null;
+ if (gtx == null) return null;
+ return gtx2TxMap.get(gtx);
}
/**
@@ -160,6 +148,7 @@
return;
}
tx2gtxMap.put(tx, gtx);
+ gtx2TxMap.put(gtx, tx);
}
/**
@@ -190,6 +179,7 @@
public TransactionEntry remove(GlobalTransaction tx)
{
if (tx == null) return null;
+ gtx2TxMap.remove(tx);
return gtx2EntryMap.remove(tx);
}
@@ -205,6 +195,7 @@
public void remove(GlobalTransaction gtx, Transaction tx)
{
+ gtx2TxMap.remove(gtx);
gtx2EntryMap.remove(gtx);
tx2gtxMap.remove(tx);
}
Modified:
core/trunk/src/test/java/org/jboss/cache/optimistic/OptimisticLockInterceptorTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/optimistic/OptimisticLockInterceptorTest.java 2008-05-09
17:14:22 UTC (rev 5823)
+++
core/trunk/src/test/java/org/jboss/cache/optimistic/OptimisticLockInterceptorTest.java 2008-05-09
17:57:36 UTC (rev 5824)
@@ -219,7 +219,7 @@
@Override
public Object handleDefault(InvocationContext ctx, VisitableCommand command) throws
Throwable
{
- TransactionWorkspace w = getTransactionWorkspace(ctx.getGlobalTransaction());
+ TransactionWorkspace w = getTransactionWorkspace(ctx);
Map nodeMap = w.getNodes();
for (Iterator i = nodeMap.keySet().iterator(); i.hasNext();)
{