use of org.apache.geode.cache.TransactionException in project geode by apache.
the class PartitionedTXRegionStub method containsKey.
public boolean containsKey(KeyInfo keyInfo) {
PartitionedRegion pr = (PartitionedRegion) region;
try {
boolean retVal = pr.containsKeyRemotely((InternalDistributedMember) state.getTarget(), keyInfo.getBucketId(), keyInfo.getKey());
trackBucketForTx(keyInfo);
return retVal;
} catch (TransactionException e) {
RuntimeException re = getTransactionException(keyInfo, e);
re.initCause(e.getCause());
throw re;
} catch (PrimaryBucketException e) {
RuntimeException re = getTransactionException(keyInfo, e);
re.initCause(e);
throw re;
} catch (ForceReattemptException e) {
if (isBucketNotFoundException(e)) {
RuntimeException re = getTransactionException(keyInfo, e);
re.initCause(e);
throw re;
}
waitToRetry();
RuntimeException re = new TransactionDataNodeHasDepartedException(LocalizedStrings.PartitionedRegion_TRANSACTION_DATA_NODE_0_HAS_DEPARTED_TO_PROCEED_ROLLBACK_THIS_TRANSACTION_AND_BEGIN_A_NEW_ONE.toLocalizedString(state.getTarget()));
re.initCause(e);
throw re;
}
}
use of org.apache.geode.cache.TransactionException in project geode by apache.
the class PartitionedTXRegionStub method putEntry.
public boolean putEntry(EntryEventImpl event, boolean ifNew, boolean ifOld, Object expectedOldValue, boolean requireOldValue, long lastModified, boolean overwriteDestroyed) {
boolean retVal = false;
final LocalRegion r = event.getLocalRegion();
PartitionedRegion pr = (PartitionedRegion) r;
try {
retVal = pr.putRemotely(state.getTarget(), event, ifNew, ifOld, expectedOldValue, requireOldValue);
} catch (TransactionException e) {
RuntimeException re = getTransactionException(event.getKeyInfo(), e);
re.initCause(e.getCause());
throw re;
} catch (PrimaryBucketException e) {
RuntimeException re = getTransactionException(event.getKeyInfo(), e);
re.initCause(e);
throw re;
} catch (ForceReattemptException e) {
waitToRetry();
RuntimeException re = getTransactionException(event.getKeyInfo(), e);
re.initCause(e);
throw re;
}
trackBucketForTx(event.getKeyInfo());
return retVal;
}
use of org.apache.geode.cache.TransactionException in project geode by apache.
the class PeerTypeRegistration method updateRegion.
private void updateRegion(Object k, Object v) {
Region<Object, Object> r = getIdToType();
InternalCache cache = (InternalCache) r.getRegionService();
checkDistributedTypeRegistryState();
TXManagerImpl txManager = (TXManagerImpl) cache.getCacheTransactionManager();
TXStateProxy currentState = suspendTX();
boolean state = useUDPMessagingIfNecessary();
try {
// The loop might not be necessary because we're
// updating a replicated region inside a dlock,
// but just in case we'll make sure to retry the transaction.
int failureCount = 0;
while (true) {
txManager.begin();
try {
r.put(k, v);
txManager.commit();
return;
} catch (TransactionException e) {
// even put can now throw a TransactionException, rollback if required
if (txManager.exists()) {
txManager.rollback();
}
// Let's just make sure things don't get out of hand.
if (++failureCount > MAX_TRANSACTION_FAILURES) {
throw e;
}
}
}
} finally {
releaseUDPMessaging(state);
resumeTX(currentState);
}
}
use of org.apache.geode.cache.TransactionException in project geode by apache.
the class TXJUnitTest method testConflicts.
@Test
public void testConflicts() throws CacheException {
final TXManagerImpl txMgrImpl = (TXManagerImpl) this.txMgr;
TXStateProxy tx;
// try a put with no conflict to show that commit works
txMgrImpl.begin();
this.region.put("key1", "value1");
txMgrImpl.commit();
assertEquals("value1", this.region.get("key1"));
this.region.localDestroy("key1");
// now try a put with a conflict and make sure it is detected
txMgrImpl.begin();
this.region.put("key1", "value1");
tx = txMgrImpl.internalSuspend();
// do a non-tx put to force conflict
this.region.put("key1", "value2");
txMgrImpl.internalResume(tx);
try {
txMgrImpl.commit();
fail("expected CommitConflictException");
} catch (CommitConflictException ex) {
}
assertEquals("value2", this.region.get("key1"));
this.region.localDestroy("key1");
// slightly difference version where value already exists in cmt state
this.region.put("key1", "value0");
txMgrImpl.begin();
this.region.put("key1", "value1");
txMgrImpl.commit();
assertEquals("value1", this.region.get("key1"));
this.region.localDestroy("key1");
// now the conflict
this.region.put("key1", "value0");
txMgrImpl.begin();
this.region.put("key1", "value1");
tx = txMgrImpl.internalSuspend();
// do a non-tx put to force conflict
this.region.put("key1", "value2");
txMgrImpl.internalResume(tx);
try {
txMgrImpl.commit();
fail("expected CommitConflictException");
} catch (CommitConflictException ex) {
}
assertEquals("value2", this.region.get("key1"));
this.region.localDestroy("key1");
// now test create
txMgrImpl.begin();
this.region.create("key1", "value1");
txMgrImpl.commit();
assertEquals("value1", this.region.get("key1"));
this.region.localDestroy("key1");
// now try a create with a conflict and make sure it is detected
txMgrImpl.begin();
this.region.create("key1", "value1");
tx = txMgrImpl.internalSuspend();
// do a non-tx put to force conflict
this.region.put("key1", "value2");
txMgrImpl.internalResume(tx);
try {
txMgrImpl.commit();
fail("expected CommitConflictException");
} catch (CommitConflictException ex) {
}
assertEquals("value2", this.region.get("key1"));
this.region.localDestroy("key1");
// test localInvalidate
this.region.put("key1", "value0");
txMgrImpl.begin();
this.region.localInvalidate("key1");
txMgrImpl.commit();
assertTrue(this.region.containsKey("key1") && !this.region.containsValueForKey("key1"));
this.region.localDestroy("key1");
// now the conflict
this.region.put("key1", "value0");
txMgrImpl.begin();
this.region.localInvalidate("key1");
tx = txMgrImpl.internalSuspend();
// do a non-tx put to force conflict
this.region.put("key1", "value2");
txMgrImpl.internalResume(tx);
try {
txMgrImpl.commit();
fail("expected CommitConflictException");
} catch (CommitConflictException ex) {
}
assertEquals("value2", this.region.get("key1"));
this.region.localDestroy("key1");
// test invalidate
this.region.put("key1", "value0");
txMgrImpl.begin();
this.region.invalidate("key1");
txMgrImpl.commit();
assertTrue(this.region.containsKey("key1") && !this.region.containsValueForKey("key1"));
this.region.localDestroy("key1");
// now the conflict
this.region.put("key1", "value0");
txMgrImpl.begin();
this.region.invalidate("key1");
tx = txMgrImpl.internalSuspend();
// do a non-tx put to force conflict
this.region.put("key1", "value2");
txMgrImpl.internalResume(tx);
try {
txMgrImpl.commit();
fail("expected CommitConflictException");
} catch (CommitConflictException ex) {
}
assertEquals("value2", this.region.get("key1"));
this.region.localDestroy("key1");
// check C + DD is a NOOP that still gets conflict if non-tx entry created */
this.txMgr.begin();
this.region.create("newKey", "valueTX");
tx = txMgrImpl.internalSuspend();
this.region.create("newKey", "valueNONTX");
txMgrImpl.internalResume(tx);
this.region.destroy("newKey");
assertTrue(!this.region.containsKey("key1"));
try {
txMgrImpl.commit();
fail("expected CommitConflictException");
} catch (CommitConflictException ex) {
}
assertEquals("valueNONTX", this.region.get("newKey"));
this.region.localDestroy("newKey");
// check C + LD is a NOOP that still gets conflict if non-tx entry created */
this.txMgr.begin();
this.region.create("newKey", "valueTX");
tx = txMgrImpl.internalSuspend();
this.region.create("newKey", "valueNONTX");
txMgrImpl.internalResume(tx);
this.region.localDestroy("newKey");
assertTrue(!this.region.containsKey("key1"));
try {
txMgrImpl.commit();
fail("expected CommitConflictException");
} catch (CommitConflictException ex) {
}
assertEquals("valueNONTX", this.region.get("newKey"));
this.region.localDestroy("newKey");
// test localDestroy
this.region.put("key1", "value0");
txMgrImpl.begin();
this.region.localDestroy("key1");
txMgrImpl.commit();
assertTrue(!this.region.containsKey("key1"));
// now the conflict
this.region.put("key1", "value0");
txMgrImpl.begin();
this.region.localDestroy("key1");
tx = txMgrImpl.internalSuspend();
// do a non-tx put to force conflict
this.region.put("key1", "value2");
txMgrImpl.internalResume(tx);
try {
txMgrImpl.commit();
fail("expected CommitConflictException");
} catch (CommitConflictException ex) {
}
assertEquals("value2", this.region.get("key1"));
this.region.localDestroy("key1");
// test destroy
this.region.put("key1", "value0");
txMgrImpl.begin();
this.region.destroy("key1");
txMgrImpl.commit();
assertTrue(!this.region.containsKey("key1"));
// now the conflict
this.region.put("key1", "value0");
txMgrImpl.begin();
this.region.destroy("key1");
tx = txMgrImpl.internalSuspend();
// do a non-tx put to force conflict
this.region.put("key1", "value2");
txMgrImpl.internalResume(tx);
try {
txMgrImpl.commit();
fail("expected CommitConflictException");
} catch (CommitConflictException ex) {
}
assertEquals("value2", this.region.get("key1"));
this.region.localDestroy("key1");
checkUserAttributeConflict(txMgrImpl);
// make sure non-tx local-invalidate followed by invalidate
// does not cause conflict
this.region.create("key1", "val1");
this.region.localInvalidate("key1");
txMgrImpl.begin();
this.region.put("key1", "txVal1");
tx = txMgrImpl.internalSuspend();
this.region.invalidate("key1");
txMgrImpl.internalResume(tx);
txMgrImpl.commit();
assertEquals("txVal1", this.region.getEntry("key1").getValue());
this.region.destroy("key1");
// now try a put and a region destroy.
txMgrImpl.begin();
this.region.create("key1", "value1");
TXStateProxy tis = txMgrImpl.internalSuspend();
// non-tx
this.region.localDestroyRegion();
txMgrImpl.internalResume(tis);
try {
txMgrImpl.commit();
fail("expected CommitConflictException");
} catch (TransactionException ex) {
}
}
use of org.apache.geode.cache.TransactionException in project geode by apache.
the class ExecutionHandlerContext method executeWithTransaction.
private void executeWithTransaction(ChannelHandlerContext ctx, final Executor exec, Command command) throws Exception {
CacheTransactionManager txm = cache.getCacheTransactionManager();
TransactionId transactionId = getTransactionID();
txm.resume(transactionId);
try {
exec.executeCommand(command, this);
} catch (UnsupportedOperationInTransactionException e) {
command.setResponse(Coder.getErrorResponse(this.byteBufAllocator, RedisConstants.ERROR_UNSUPPORTED_OPERATION_IN_TRANSACTION));
} catch (TransactionException e) {
command.setResponse(Coder.getErrorResponse(this.byteBufAllocator, RedisConstants.ERROR_TRANSACTION_EXCEPTION));
} catch (Exception e) {
ByteBuf response = getExceptionResponse(ctx, e);
command.setResponse(response);
}
getTransactionQueue().add(command);
transactionId = txm.suspend();
setTransactionID(transactionId);
}
Aggregations