Search in sources :

Example 6 with UnsupportedOperationInTransactionException

use of org.apache.geode.cache.UnsupportedOperationInTransactionException in project geode by apache.

the class DistTXCommitMessage method operateOnTx.

@Override
protected boolean operateOnTx(TXId txId, DistributionManager dm) throws RemoteOperationException {
    if (logger.isDebugEnabled()) {
        logger.debug("DistTXCommitMessage.operateOnTx: Tx {}", txId);
    }
    InternalCache cache = GemFireCacheImpl.getInstance();
    TXManagerImpl txMgr = cache.getTXMgr();
    final TXStateProxy txStateProxy = txMgr.getTXState();
    TXCommitMessage cmsg = null;
    try {
        // do the actual commit, only if it was not done before
        if (txMgr.isHostedTxRecentlyCompleted(txId)) {
            if (logger.isDebugEnabled()) {
                logger.debug("DistTXCommitMessage.operateOnTx: found a previously committed transaction:{}", txId);
            }
            cmsg = txMgr.getRecentlyCompletedMessage(txId);
            if (txMgr.isExceptionToken(cmsg)) {
                throw txMgr.getExceptionForToken(cmsg, txId);
            }
        } else {
            // that don't start remote TX) then ignore
            if (txStateProxy != null) {
                /*
           * [DISTTX] TODO See how other exceptions are caught and send on wire, than throwing?
           * 
           * This can be spared since it will be programming bug
           */
                if (!txStateProxy.isDistTx() || txStateProxy.isCreatedOnDistTxCoordinator()) {
                    throw new UnsupportedOperationInTransactionException(LocalizedStrings.DISTTX_TX_EXPECTED.toLocalizedString("DistTXStateProxyImplOnDatanode", txStateProxy.getClass().getSimpleName()));
                }
                if (logger.isDebugEnabled()) {
                    logger.debug("DistTXCommitMessage.operateOnTx Commiting {} " + " incoming entryEventList:{} coming from {} ", txId, DistTXStateProxyImplOnCoordinator.printEntryEventList(this.entryStateList), this.getSender().getId());
                }
                // Set Member's ID to all entry states
                String memberID = this.getSender().getId();
                for (ArrayList<DistTxThinEntryState> esList : this.entryStateList) {
                    for (DistTxThinEntryState es : esList) {
                        es.setMemberID(memberID);
                    }
                }
                ((DistTXStateProxyImplOnDatanode) txStateProxy).populateDistTxEntryStates(this.entryStateList);
                txStateProxy.setCommitOnBehalfOfRemoteStub(true);
                txMgr.commit();
                cmsg = txStateProxy.getCommitMessage();
            }
        }
    } finally {
        txMgr.removeHostedTXState(txId);
    }
    DistTXCommitReplyMessage.send(getSender(), getProcessorId(), cmsg, getReplySender(dm));
    /*
     * return false so there isn't another reply
     */
    return false;
}
Also used : UnsupportedOperationInTransactionException(org.apache.geode.cache.UnsupportedOperationInTransactionException) DistTxThinEntryState(org.apache.geode.internal.cache.TXEntryState.DistTxThinEntryState)

Example 7 with UnsupportedOperationInTransactionException

use of org.apache.geode.cache.UnsupportedOperationInTransactionException in project geode by apache.

the class TXStateStub method destroyExistingEntry.

/*
   * (non-Javadoc)
   * 
   * @see
   * org.apache.geode.internal.cache.TXStateInterface#destroyExistingEntry(org.apache.geode.internal
   * .cache.EntryEventImpl, boolean, java.lang.Object)
   */
public void destroyExistingEntry(EntryEventImpl event, boolean cacheWrite, Object expectedOldValue) throws EntryNotFoundException {
    if (event.getOperation().isLocal()) {
        throw new UnsupportedOperationInTransactionException(LocalizedStrings.TXStateStub_LOCAL_DESTROY_NOT_ALLOWED_IN_TRANSACTION.toLocalizedString());
    }
    TXRegionStub rs = getTXRegionStub(event.getRegion());
    rs.destroyExistingEntry(event, cacheWrite, expectedOldValue);
}
Also used : TXRegionStub(org.apache.geode.internal.cache.tx.TXRegionStub) UnsupportedOperationInTransactionException(org.apache.geode.cache.UnsupportedOperationInTransactionException)

Example 8 with UnsupportedOperationInTransactionException

use of org.apache.geode.cache.UnsupportedOperationInTransactionException in project geode by apache.

the class TXJUnitTest method testDestroyRegionNotSupported.

/**
   * make sure that we throw an UnsupportedOperationInTransactionException
   * 
   * @throws Exception
   */
@Test
public void testDestroyRegionNotSupported() throws Exception {
    CacheTransactionManager ctm = this.cache.getCacheTransactionManager();
    AttributesFactory af = new AttributesFactory();
    Region r = this.cache.createRegion("dRegion", af.create());
    PartitionAttributes pa = new PartitionAttributesFactory().setRedundantCopies(0).setTotalNumBuckets(1).create();
    af.setPartitionAttributes(pa);
    Region pr = this.cache.createRegion("prRegion", af.create());
    List list = new ArrayList();
    list.add("stuff");
    list.add("stuff2");
    ctm.begin();
    try {
        pr.destroyRegion();
        fail("Should have thrown UnsupportedOperationInTransactionException during destroyRegion");
    } catch (UnsupportedOperationInTransactionException ee) {
    // expected
    }
    try {
        pr.localDestroyRegion();
        fail("Should have thrown UnsupportedOperationInTransactionException during localDestroyRegion");
    } catch (UnsupportedOperationInTransactionException ee) {
    // expected
    }
    try {
        r.destroyRegion();
        fail("Should have thrown UnsupportedOperationInTransactionException during destroyRegion");
    } catch (UnsupportedOperationInTransactionException ee) {
    // expected
    }
    try {
        r.localDestroyRegion();
        fail("Should have thrown UnsupportedOperationInTransactionException during localDestroyRegion");
    } catch (UnsupportedOperationInTransactionException ee) {
    // expected
    }
    assertTrue(!pr.isDestroyed());
    assertTrue(!r.isDestroyed());
    ctm.commit();
    // now we aren't in tx so these shouldn't throw
    pr.destroyRegion();
    r.destroyRegion();
}
Also used : PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) PartitionAttributes(org.apache.geode.cache.PartitionAttributes) ArrayList(java.util.ArrayList) AbstractRegion(org.apache.geode.internal.cache.AbstractRegion) LocalRegion(org.apache.geode.internal.cache.LocalRegion) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) List(java.util.List) ArrayList(java.util.ArrayList) UnsupportedOperationInTransactionException(org.apache.geode.cache.UnsupportedOperationInTransactionException) CacheTransactionManager(org.apache.geode.cache.CacheTransactionManager) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 9 with UnsupportedOperationInTransactionException

use of org.apache.geode.cache.UnsupportedOperationInTransactionException in project geode by apache.

the class TXJUnitTest method testInvalidateRegionNotSupported.

/**
   * make sure that we throw an UnsupportedOperationInTransactionException
   * 
   * @throws Exception
   */
@Test
public void testInvalidateRegionNotSupported() throws Exception {
    CacheTransactionManager ctm = this.cache.getCacheTransactionManager();
    AttributesFactory af = new AttributesFactory();
    Region r = this.cache.createRegion("dRegion", af.create());
    PartitionAttributes pa = new PartitionAttributesFactory().setRedundantCopies(0).setTotalNumBuckets(1).create();
    af.setPartitionAttributes(pa);
    Region pr = this.cache.createRegion("prRegion", af.create());
    ctm.begin();
    try {
        pr.invalidateRegion();
        fail("Should have thrown UnsupportedOperationInTransactionException during invalidateRegion");
    } catch (UnsupportedOperationInTransactionException ee) {
    // expected
    }
    try {
        pr.localInvalidateRegion();
        fail("Should have thrown UnsupportedOperationInTransactionException during localInvalidateRegion");
    } catch (UnsupportedOperationInTransactionException ee) {
    // expected
    }
    try {
        r.invalidateRegion();
        fail("Should have thrown UnsupportedOperationInTransactionException during invalidateRegion");
    } catch (UnsupportedOperationInTransactionException ee) {
    // expected
    }
    try {
        r.localInvalidateRegion();
        fail("Should have thrown UnsupportedOperationInTransactionException during localInvalidateRegion");
    } catch (UnsupportedOperationInTransactionException ee) {
    // expected
    }
    ctm.commit();
    // now we aren't in tx so these shouldn't throw
    pr.invalidateRegion();
    r.invalidateRegion();
}
Also used : PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) PartitionAttributes(org.apache.geode.cache.PartitionAttributes) AbstractRegion(org.apache.geode.internal.cache.AbstractRegion) LocalRegion(org.apache.geode.internal.cache.LocalRegion) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) UnsupportedOperationInTransactionException(org.apache.geode.cache.UnsupportedOperationInTransactionException) CacheTransactionManager(org.apache.geode.cache.CacheTransactionManager) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 10 with UnsupportedOperationInTransactionException

use of org.apache.geode.cache.UnsupportedOperationInTransactionException 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

UnsupportedOperationInTransactionException (org.apache.geode.cache.UnsupportedOperationInTransactionException)17 Region (org.apache.geode.cache.Region)7 CacheTransactionManager (org.apache.geode.cache.CacheTransactionManager)6 Test (org.junit.Test)6 AttributesFactory (org.apache.geode.cache.AttributesFactory)5 ArrayList (java.util.ArrayList)4 CommitConflictException (org.apache.geode.cache.CommitConflictException)4 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Entry (java.util.Map.Entry)3 TreeMap (java.util.TreeMap)3 PartitionAttributes (org.apache.geode.cache.PartitionAttributes)3 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)3 TransactionDataRebalancedException (org.apache.geode.cache.TransactionDataRebalancedException)3 TransactionWriterException (org.apache.geode.cache.TransactionWriterException)3 DistributedMember (org.apache.geode.distributed.DistributedMember)3 DM (org.apache.geode.distributed.internal.DM)3 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)3 AbstractRegion (org.apache.geode.internal.cache.AbstractRegion)3