Search in sources :

Example 16 with TransactionException

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;
    }
}
Also used : TransactionException(org.apache.geode.cache.TransactionException) ForceReattemptException(org.apache.geode.internal.cache.ForceReattemptException) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) PrimaryBucketException(org.apache.geode.internal.cache.PrimaryBucketException) TransactionDataNodeHasDepartedException(org.apache.geode.cache.TransactionDataNodeHasDepartedException)

Example 17 with TransactionException

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;
}
Also used : TransactionException(org.apache.geode.cache.TransactionException) ForceReattemptException(org.apache.geode.internal.cache.ForceReattemptException) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) LocalRegion(org.apache.geode.internal.cache.LocalRegion) PrimaryBucketException(org.apache.geode.internal.cache.PrimaryBucketException)

Example 18 with TransactionException

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);
    }
}
Also used : TXManagerImpl(org.apache.geode.internal.cache.TXManagerImpl) TransactionException(org.apache.geode.cache.TransactionException) TXStateProxy(org.apache.geode.internal.cache.TXStateProxy) InternalCache(org.apache.geode.internal.cache.InternalCache)

Example 19 with TransactionException

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) {
    }
}
Also used : CommitConflictException(org.apache.geode.cache.CommitConflictException) TXManagerImpl(org.apache.geode.internal.cache.TXManagerImpl) TransactionException(org.apache.geode.cache.TransactionException) UnsupportedOperationInTransactionException(org.apache.geode.cache.UnsupportedOperationInTransactionException) TXStateProxy(org.apache.geode.internal.cache.TXStateProxy) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 20 with TransactionException

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);
}
Also used : TransactionException(org.apache.geode.cache.TransactionException) UnsupportedOperationInTransactionException(org.apache.geode.cache.UnsupportedOperationInTransactionException) UnsupportedOperationInTransactionException(org.apache.geode.cache.UnsupportedOperationInTransactionException) ByteBuf(io.netty.buffer.ByteBuf) DecoderException(io.netty.handler.codec.DecoderException) RegionNotFoundException(org.apache.geode.cache.query.RegionNotFoundException) IOException(java.io.IOException) TransactionException(org.apache.geode.cache.TransactionException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) UnsupportedOperationInTransactionException(org.apache.geode.cache.UnsupportedOperationInTransactionException) CacheClosedException(org.apache.geode.cache.CacheClosedException) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) CacheTransactionManager(org.apache.geode.cache.CacheTransactionManager) TransactionId(org.apache.geode.cache.TransactionId)

Aggregations

TransactionException (org.apache.geode.cache.TransactionException)31 TransactionDataRebalancedException (org.apache.geode.cache.TransactionDataRebalancedException)12 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)11 TransactionDataNotColocatedException (org.apache.geode.cache.TransactionDataNotColocatedException)9 ForceReattemptException (org.apache.geode.internal.cache.ForceReattemptException)9 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)9 PrimaryBucketException (org.apache.geode.internal.cache.PrimaryBucketException)9 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)7 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)7 LowMemoryException (org.apache.geode.cache.LowMemoryException)6 DistributedMember (org.apache.geode.distributed.DistributedMember)6 InternalCache (org.apache.geode.internal.cache.InternalCache)6 CacheLoaderException (org.apache.geode.cache.CacheLoaderException)5 CacheWriterException (org.apache.geode.cache.CacheWriterException)5 UnsupportedOperationInTransactionException (org.apache.geode.cache.UnsupportedOperationInTransactionException)5 IOException (java.io.IOException)4 RollbackException (javax.transaction.RollbackException)4 CancelException (org.apache.geode.CancelException)4 CacheClosedException (org.apache.geode.cache.CacheClosedException)4 CommitConflictException (org.apache.geode.cache.CommitConflictException)4