Search in sources :

Example 11 with UnsupportedOperationInTransactionException

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

the class DelExecutor method executeCommand.

@Override
public void executeCommand(Command command, ExecutionHandlerContext context) {
    if (context.hasTransaction())
        throw new UnsupportedOperationInTransactionException();
    List<byte[]> commandElems = command.getProcessedCommand();
    if (commandElems.size() < 2) {
        command.setResponse(Coder.getErrorResponse(context.getByteBufAllocator(), ArityDef.DEL));
        return;
    }
    int numRemoved = 0;
    for (int i = 1; i < commandElems.size(); i++) {
        byte[] byteKey = commandElems.get(i);
        ByteArrayWrapper key = new ByteArrayWrapper(byteKey);
        RedisDataType type = context.getRegionProvider().getRedisDataType(key);
        if (removeEntry(key, type, context))
            numRemoved++;
    }
    command.setResponse(Coder.getIntegerResponse(context.getByteBufAllocator(), numRemoved));
}
Also used : RedisDataType(org.apache.geode.redis.internal.RedisDataType) ByteArrayWrapper(org.apache.geode.redis.internal.ByteArrayWrapper) UnsupportedOperationInTransactionException(org.apache.geode.cache.UnsupportedOperationInTransactionException)

Example 12 with UnsupportedOperationInTransactionException

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

the class FlushAllExecutor method executeCommand.

@Override
public void executeCommand(Command command, ExecutionHandlerContext context) {
    if (context.hasTransaction())
        throw new UnsupportedOperationInTransactionException();
    for (Entry<String, RedisDataType> e : context.getRegionProvider().metaEntrySet()) {
        try {
            String skey = e.getKey();
            RedisDataType type = e.getValue();
            removeEntry(Coder.stringToByteWrapper(skey), type, context);
        } catch (EntryDestroyedException e1) {
            continue;
        }
    }
    command.setResponse(Coder.getSimpleStringResponse(context.getByteBufAllocator(), "OK"));
}
Also used : RedisDataType(org.apache.geode.redis.internal.RedisDataType) EntryDestroyedException(org.apache.geode.cache.EntryDestroyedException) UnsupportedOperationInTransactionException(org.apache.geode.cache.UnsupportedOperationInTransactionException)

Example 13 with UnsupportedOperationInTransactionException

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

the class TXJUnitTest method testClearRegionNotSupported.

/**
   * make sure that we throw an UnsupportedOperationInTransactionException
   * 
   * @throws Exception
   */
@Test
public void testClearRegionNotSupported() 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.clear();
        fail("Should have thrown UnsupportedOperation during invalidateRegion");
    } catch (UnsupportedOperationException ee) {
    // expected
    }
    try {
        pr.localClear();
        fail("Should have thrown UnsupportedOperation during localInvalidateRegion");
    } catch (UnsupportedOperationException ee) {
    // expected
    }
    try {
        r.clear();
        fail("Should have thrown UnsupportedOperationInTransactionException during invalidateRegion");
    } catch (UnsupportedOperationInTransactionException ee) {
    // expected
    }
    try {
        r.localClear();
        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 14 with UnsupportedOperationInTransactionException

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

the class Bug34387DUnitTest method doCommitOtherVm.

private void doCommitOtherVm(final boolean doDestroy) {
    VM vm = getOtherVm();
    vm.invoke(new CacheSerializableRunnable("create root") {

        public void run2() throws CacheException {
            AttributesFactory af = new AttributesFactory();
            af.setScope(Scope.DISTRIBUTED_ACK);
            af.setConcurrencyChecksEnabled(true);
            Region r1 = createRootRegion("r1", af.create());
            CacheTransactionManager ctm = getCache().getCacheTransactionManager();
            ctm.begin();
            r1.create("createKey", "createValue");
            if (doDestroy) {
                try {
                    r1.localDestroy("createKey");
                    fail("expected exception not thrown");
                } catch (UnsupportedOperationInTransactionException e) {
                    assertEquals(e.getMessage(), LocalizedStrings.TXStateStub_LOCAL_DESTROY_NOT_ALLOWED_IN_TRANSACTION.toLocalizedString());
                }
            } else {
                try {
                    r1.localInvalidate("createKey");
                    fail("expected exception not thrown");
                } catch (UnsupportedOperationInTransactionException e) {
                    assertEquals(e.getMessage(), LocalizedStrings.TXStateStub_LOCAL_INVALIDATE_NOT_ALLOWED_IN_TRANSACTION.toLocalizedString());
                }
            }
            ctm.commit();
        }
    });
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) CacheException(org.apache.geode.cache.CacheException) VM(org.apache.geode.test.dunit.VM) Region(org.apache.geode.cache.Region) UnsupportedOperationInTransactionException(org.apache.geode.cache.UnsupportedOperationInTransactionException) CacheTransactionManager(org.apache.geode.cache.CacheTransactionManager)

Example 15 with UnsupportedOperationInTransactionException

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

the class DistTXStateProxyImplOnCoordinator method rollback.

@Override
public void rollback() {
    if (logger.isDebugEnabled()) {
        logger.debug("DistTXStateProxyImplOnCoordinator.rollback Going for rollback ");
    }
    boolean finalResult = false;
    final GemFireCacheImpl cache = GemFireCacheImpl.getExisting("Applying Dist TX Rollback");
    final DM dm = cache.getDistributionManager();
    try {
        // Create Tx Participants
        Set<DistributedMember> txRemoteParticpants = getTxRemoteParticpants(dm);
        // create processor and rollback message
        DistTXRollbackMessage.DistTxRollbackReplyProcessor processor = new DistTXRollbackMessage.DistTxRollbackReplyProcessor(this.getTxId(), dm, txRemoteParticpants, target2realDeals);
        // TODO [DISTTX} whats ack threshold?
        processor.enableSevereAlertProcessing();
        final DistTXRollbackMessage rollbackMsg = new DistTXRollbackMessage(this.getTxId(), this.onBehalfOfClientMember, processor);
        // send rollback message to remote nodes
        for (DistributedMember remoteNode : txRemoteParticpants) {
            DistTXCoordinatorInterface remoteTXStateStub = target2realDeals.get(remoteNode);
            if (remoteTXStateStub.isTxState()) {
                throw new UnsupportedOperationInTransactionException(LocalizedStrings.DISTTX_TX_EXPECTED.toLocalizedString("DistPeerTXStateStub", remoteTXStateStub.getClass().getSimpleName()));
            }
            try {
                remoteTXStateStub.setRollbackMessage(rollbackMsg, dm);
                remoteTXStateStub.rollback();
            } finally {
                remoteTXStateStub.setRollbackMessage(null, null);
                remoteTXStateStub.finalCleanup();
            }
            if (logger.isDebugEnabled()) {
                // TODO - make this trace level
                logger.debug("DistTXStateProxyImplOnCoordinator.rollback target = " + remoteNode);
            }
        }
        // Do rollback on local node
        DistTXCoordinatorInterface localTXState = target2realDeals.get(dm.getId());
        if (localTXState != null) {
            if (!localTXState.isTxState()) {
                throw new UnsupportedOperationInTransactionException(LocalizedStrings.DISTTX_TX_EXPECTED.toLocalizedString("DistTXStateOnCoordinator", localTXState.getClass().getSimpleName()));
            }
            localTXState.rollback();
            boolean localResult = localTXState.getRollbackResponse();
            if (logger.isDebugEnabled()) {
                logger.debug("DistTXStateProxyImplOnCoordinator.rollback local = " + dm.getId() + " ,result= " + localResult + " ,finalResult-old= " + finalResult);
            }
            finalResult = finalResult && localResult;
        }
        /*
       * [DISTTX] TODO Any test hooks
       */
        // if (internalAfterIndividualSend != null) {
        // internalAfterIndividualSend.run();
        // }
        /*
       * [DISTTX] TODO see how to handle exception
       */
        /*
       * [DISTTX] TODO Any test hooks
       */
        // if (internalAfterIndividualCommitProcess != null) {
        // // Testing callback
        // internalAfterIndividualCommitProcess.run();
        // }
        {
            // Wait for results
            dm.getCancelCriterion().checkCancelInProgress(null);
            processor.waitForPrecommitCompletion();
            // [DISTTX} TODO Handle stats
            // dm.getStats().incCommitWaits();
            Map<DistributedMember, Boolean> remoteResults = processor.getRollbackResponseMap();
            for (Entry<DistributedMember, Boolean> e : remoteResults.entrySet()) {
                DistributedMember target = e.getKey();
                Boolean remoteResult = e.getValue();
                if (logger.isDebugEnabled()) {
                    // TODO - make this trace level
                    logger.debug("DistTXStateProxyImplOnCoordinator.rollback target = " + target + " ,result= " + remoteResult + " ,finalResult-old= " + finalResult);
                }
                finalResult = finalResult && remoteResult;
            }
        }
    } finally {
        inProgress = false;
        if (this.synchRunnable != null) {
            this.synchRunnable.abort();
        }
    }
    if (logger.isDebugEnabled()) {
        logger.debug("DistTXStateProxyImplOnCoordinator.rollback finalResult= " + finalResult);
    }
}
Also used : DM(org.apache.geode.distributed.internal.DM) UnsupportedOperationInTransactionException(org.apache.geode.cache.UnsupportedOperationInTransactionException) Entry(java.util.Map.Entry) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

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