Author: mircea.markus
Date: 2008-03-06 21:43:26 -0500 (Thu, 06 Mar 2008)
New Revision: 5394
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java
core/trunk/src/test/java/org/jboss/cache/api/DeletedChildResurrectionTest.java
Log:
JBCACHE-1296 - if we'll rollback the tx, data should be added to the node again
+ enhanced the test
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java 2008-03-07
00:56:47 UTC (rev 5393)
+++
core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java 2008-03-07
02:43:26 UTC (rev 5394)
@@ -18,17 +18,15 @@
import org.jboss.cache.lock.NodeLock;
import org.jboss.cache.lock.TimeoutException;
import org.jboss.cache.marshall.MethodDeclarations;
+import org.jboss.cache.marshall.MethodCallFactory;
+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 org.jgroups.Address;
import javax.transaction.Transaction;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
/*
* todo refactorings ideas
@@ -624,10 +622,18 @@
*/
private void manageReverseRemove(GlobalTransaction gtx, NodeSPI childNode, boolean
reverseRemoveCheck, List createdNodes)
{
- boolean needToReverseRemove = reverseRemoveCheck && childNode.isDeleted()
&& tx_table.isNodeRemovedInTx(gtx, childNode.getFqn());
- if (gtx != null && needToReverseRemove)
+ if (gtx != null) //if no tx then reverse remove does not make sense
{
+ Fqn fqn = childNode.getFqn();
+ boolean needToReverseRemove = reverseRemoveCheck &&
childNode.isDeleted() && tx_table.isNodeRemovedInTx(gtx, 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());
+ MethodCall undoOp =
MethodCallFactory.create(MethodDeclarations.putDataMethodLocal_id,
+ gtx, fqn, oldData , false);
+ tx_table.get(gtx).addUndoOperation(undoOp);
+ //we're prepared for rollback, now reset the node
childNode.clearDataDirect();
if (createdNodes != null)
{
Modified: core/trunk/src/test/java/org/jboss/cache/api/DeletedChildResurrectionTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/api/DeletedChildResurrectionTest.java 2008-03-07
00:56:47 UTC (rev 5393)
+++
core/trunk/src/test/java/org/jboss/cache/api/DeletedChildResurrectionTest.java 2008-03-07
02:43:26 UTC (rev 5394)
@@ -106,11 +106,13 @@
TransactionManager txManager =
cache.getConfiguration().getRuntimeConfig().getTransactionManager();
root.addChild(A_B).put(KEY, VALUE);
+ cache.put(A, "key","value");
txManager.begin();
root.removeChild(A);
root.addChild(A);
txManager.commit();
assert !root.hasChild(A_B);
+ assert null == cache.get(A, "key");
// do a peek to ensure the node really has been removed and not just marked for
removal
assert spi.peek(A_B, true, true) == null;
assert root.hasChild(A);
Show replies by date