Author: bstansberry(a)jboss.com
Date: 2007-12-20 17:17:08 -0500 (Thu, 20 Dec 2007)
New Revision: 4901
Modified:
core/branches/1.4.X/src/org/jboss/cache/interceptors/TxInterceptor.java
core/branches/1.4.X/tests/functional/org/jboss/cache/options/OptimisticMemLeakTest.java
Log:
[JBCACHE-1246] Only remove fail-silently txs where we haven't registered a
synchronization
Modified: core/branches/1.4.X/src/org/jboss/cache/interceptors/TxInterceptor.java
===================================================================
--- core/branches/1.4.X/src/org/jboss/cache/interceptors/TxInterceptor.java 2007-12-20
18:17:41 UTC (rev 4900)
+++ core/branches/1.4.X/src/org/jboss/cache/interceptors/TxInterceptor.java 2007-12-20
22:17:08 UTC (rev 4901)
@@ -92,11 +92,20 @@
if (optionOverride!= null && optionOverride.isFailSilently() &&
ctx.getTransaction() != null)
{
- // make sure we remove the tx and global tx from the transaction table, since
we don't care about this transaction
- // and will just suspend it. - JBCACHE-1246
- GlobalTransaction gtx = txTable.remove(ctx.getTransaction());
- if (gtx != null) txTable.remove(gtx);
-
+ // JBCACHE-1246 If we haven't previously registered a synchronization
+ // for the current tx, remove it from the tx table, since we are about to
+ // suspend it and thus won't remove it later via the synchronization.
+ // If we don't do this, we leak the tx and gtx in txTable.
+ // BES -- I'm using the transactions map here as a proxy for whether
+ // the tx has had a synchronization registered. Not really ideal...
+ if (transactions.get(ctx.getTransaction()) == null)
+ {
+ // make sure we remove the tx and global tx from the transaction table,
since we don't care about this transaction
+ // and will just suspend it. - JBCACHE-1246
+ GlobalTransaction gtx = txTable.remove(ctx.getTransaction());
+ if (gtx != null) txTable.remove(gtx);
+ }
+
suspendedTransaction = txManager.suspend();
// set the tx in the invocation context to null now! - JBCACHE-785
ctx.setTransaction(null);
Modified:
core/branches/1.4.X/tests/functional/org/jboss/cache/options/OptimisticMemLeakTest.java
===================================================================
---
core/branches/1.4.X/tests/functional/org/jboss/cache/options/OptimisticMemLeakTest.java 2007-12-20
18:17:41 UTC (rev 4900)
+++
core/branches/1.4.X/tests/functional/org/jboss/cache/options/OptimisticMemLeakTest.java 2007-12-20
22:17:08 UTC (rev 4901)
@@ -18,6 +18,7 @@
private TreeCache cache;
private TransactionManager tm;
private Fqn fqn = Fqn.fromString("/a/b/c");
+ private Fqn fqn1 = Fqn.fromString("/c/d/e");
private String key = "key", value = "value";
protected void tearDown()
@@ -46,5 +47,42 @@
int txCnt = cache.getTransactionTable().getNumLocalTransactions();
assertEquals("Global transaction count is > 0", 0, gtxCnt);
assertEquals("Local transaction count is > 0", 0, txCnt);
+
+ tm.begin();
+ cache.put(fqn1, key, value);
+ option = new Option();
+ option.setFailSilently(true);
+ cache.put(fqn, key, value, option);
+ tm.commit();
+
+ gtxCnt = cache.getTransactionTable().getNumGlobalTransactions();
+ txCnt = cache.getTransactionTable().getNumLocalTransactions();
+ assertEquals("Global transaction count is > 0", 0, gtxCnt);
+ assertEquals("Local transaction count is > 0", 0, txCnt);
+
+ tm.begin();
+ option = new Option();
+ option.setFailSilently(true);
+ cache.put(fqn, key, value, option);
+ cache.put(fqn1, key, value);
+ tm.commit();
+
+ gtxCnt = cache.getTransactionTable().getNumGlobalTransactions();
+ txCnt = cache.getTransactionTable().getNumLocalTransactions();
+ assertEquals("Global transaction count is > 0", 0, gtxCnt);
+ assertEquals("Local transaction count is > 0", 0, txCnt);
+
+ tm.begin();
+ cache.put(fqn1, key, value);
+ option = new Option();
+ option.setFailSilently(true);
+ cache.put(fqn, key, value, option);
+ cache.put(fqn1, key, value);
+ tm.commit();
+
+ gtxCnt = cache.getTransactionTable().getNumGlobalTransactions();
+ txCnt = cache.getTransactionTable().getNumLocalTransactions();
+ assertEquals("Global transaction count is > 0", 0, gtxCnt);
+ assertEquals("Local transaction count is > 0", 0, txCnt);
}
}