Search in sources :

Example 6 with TransactionDataRebalancedException

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

the class PartitionedRegionFunctionExecutor method validateExecution.

@Override
public void validateExecution(Function function, Set targetMembers) {
    InternalCache cache = pr.getGemFireCache();
    if (cache != null && cache.getTxManager().getTXState() != null) {
        if (targetMembers.size() > 1) {
            throw new TransactionException(LocalizedStrings.PartitionedRegion_TX_FUNCTION_ON_MORE_THAN_ONE_NODE.toLocalizedString());
        } else {
            assert targetMembers.size() == 1;
            DistributedMember funcTarget = (DistributedMember) targetMembers.iterator().next();
            DistributedMember target = cache.getTxManager().getTXState().getTarget();
            if (target == null) {
                cache.getTxManager().getTXState().setTarget(funcTarget);
            } else if (!target.equals(funcTarget)) {
                throw new TransactionDataRebalancedException(LocalizedStrings.PartitionedRegion_TX_FUNCTION_EXECUTION_NOT_COLOCATED_0_1.toLocalizedString(target, funcTarget));
            }
        }
    }
    if (function.optimizeForWrite() && cache.getInternalResourceManager().getHeapMonitor().containsHeapCriticalMembers(targetMembers) && !MemoryThresholds.isLowMemoryExceptionDisabled()) {
        Set<InternalDistributedMember> hcm = cache.getResourceAdvisor().adviseCritialMembers();
        Set<DistributedMember> sm = SetUtils.intersection(hcm, targetMembers);
        throw new LowMemoryException(LocalizedStrings.ResourceManager_LOW_MEMORY_FOR_0_FUNCEXEC_MEMBERS_1.toLocalizedString(new Object[] { function.getId(), sm }), sm);
    }
}
Also used : TransactionException(org.apache.geode.cache.TransactionException) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember) InternalCache(org.apache.geode.internal.cache.InternalCache) TransactionDataRebalancedException(org.apache.geode.cache.TransactionDataRebalancedException) LowMemoryException(org.apache.geode.cache.LowMemoryException)

Example 7 with TransactionDataRebalancedException

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

the class PartitionedRegion method destroyRemotely.

/**
   * Destroy the entry on the remote node.
   * 
   * @param recipient the member id of the receiver of the message
   * @param bucketId the idenity of the bucket
   * @param event the event prompting this request
   * @param expectedOldValue if not null, then destroy only if entry exists and current value is
   *        equal to expectedOldValue
   * @throws EntryNotFoundException if entry not found OR if expectedOldValue is non-null and
   *         doesn't equal the current value
   * @throws PrimaryBucketException if the bucket on that node is not the primary copy
   * @throws ForceReattemptException if the peer is no longer available
   */
public void destroyRemotely(DistributedMember recipient, Integer bucketId, EntryEventImpl event, Object expectedOldValue) throws EntryNotFoundException, PrimaryBucketException, ForceReattemptException {
    DestroyResponse response = DestroyMessage.send(recipient, this, event, expectedOldValue);
    if (response != null) {
        this.prStats.incPartitionMessagesSent();
        try {
            response.waitForCacheException();
            event.setVersionTag(response.getVersionTag());
        } catch (EntryNotFoundException enfe) {
            throw enfe;
        } catch (TransactionDataNotColocatedException enfe) {
            throw enfe;
        } catch (TransactionDataRebalancedException e) {
            throw e;
        } catch (CacheException ce) {
            throw new PartitionedRegionException(LocalizedStrings.PartitionedRegion_DESTROY_OF_ENTRY_ON_0_FAILED.toLocalizedString(recipient), ce);
        } catch (RegionDestroyedException ignore) {
            throw new RegionDestroyedException(toString(), getFullPath());
        }
    }
}
Also used : CacheException(org.apache.geode.cache.CacheException) DestroyResponse(org.apache.geode.internal.cache.partitioned.DestroyMessage.DestroyResponse) TransactionDataNotColocatedException(org.apache.geode.cache.TransactionDataNotColocatedException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) TransactionDataRebalancedException(org.apache.geode.cache.TransactionDataRebalancedException)

Example 8 with TransactionDataRebalancedException

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

the class PartitionedRegion method invalidateRemotely.

/**
   * invalidates the remote object with the given key.
   * 
   * @param recipient the member id of the recipient of the operation
   * @param bucketId the id of the bucket the key hashed into
   * @throws EntryNotFoundException if the entry does not exist in this region
   * @throws PrimaryBucketException if the bucket on that node is not the primary copy
   * @throws ForceReattemptException if the peer is no longer available
   */
public void invalidateRemotely(DistributedMember recipient, Integer bucketId, EntryEventImpl event) throws EntryNotFoundException, PrimaryBucketException, ForceReattemptException {
    InvalidateResponse response = InvalidateMessage.send(recipient, this, event);
    if (response != null) {
        this.prStats.incPartitionMessagesSent();
        try {
            response.waitForResult();
            event.setVersionTag(response.versionTag);
            return;
        } catch (EntryNotFoundException ex) {
            throw ex;
        } catch (TransactionDataNotColocatedException ex) {
            throw ex;
        } catch (TransactionDataRebalancedException e) {
            throw e;
        } catch (CacheException ce) {
            throw new PartitionedRegionException(LocalizedStrings.PartitionedRegion_INVALIDATION_OF_ENTRY_ON_0_FAILED.toLocalizedString(recipient), ce);
        }
    }
}
Also used : InvalidateResponse(org.apache.geode.internal.cache.partitioned.InvalidateMessage.InvalidateResponse) CacheException(org.apache.geode.cache.CacheException) TransactionDataNotColocatedException(org.apache.geode.cache.TransactionDataNotColocatedException) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) TransactionDataRebalancedException(org.apache.geode.cache.TransactionDataRebalancedException)

Example 9 with TransactionDataRebalancedException

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

the class PartitionedRegion method createRemotely.

/**
   * Creates the key/value pair into the remote target that is managing the key's bucket.
   * 
   * @param recipient member id of the recipient of the operation
   * @param bucketId the id of the bucket that the key hashed to
   * @param event the event prompting this request
   * @throws PrimaryBucketException if the bucket on that node is not the primary copy
   * @throws ForceReattemptException if the peer is no longer available
   */
private boolean createRemotely(DistributedMember recipient, Integer bucketId, EntryEventImpl event, boolean requireOldValue) throws PrimaryBucketException, ForceReattemptException {
    boolean ret = false;
    long eventTime = event.getEventTime(0L);
    PutMessage.PutResponse reply = (PutMessage.PutResponse) PutMessage.send(recipient, this, event, // expectedOldValue
    eventTime, // expectedOldValue
    true, // expectedOldValue
    false, // expectedOldValue
    null, requireOldValue);
    PutResult pr = null;
    if (reply != null) {
        this.prStats.incPartitionMessagesSent();
        try {
            pr = reply.waitForResult();
            event.setOperation(pr.op);
            event.setVersionTag(pr.versionTag);
            if (requireOldValue) {
                event.setOldValue(pr.oldValue, true);
            }
            ret = pr.returnValue;
        } catch (EntryExistsException ignore) {
            // This might not be necessary and is here for safety sake
            ret = false;
        } catch (TransactionDataNotColocatedException tdnce) {
            throw tdnce;
        } catch (TransactionDataRebalancedException e) {
            throw e;
        } catch (CacheException ce) {
            throw new PartitionedRegionException(LocalizedStrings.PartitionedRegion_CREATE_OF_ENTRY_ON_0_FAILED.toLocalizedString(recipient), ce);
        } catch (RegionDestroyedException rde) {
            if (logger.isDebugEnabled()) {
                logger.debug("createRemotely: caught exception", rde);
            }
            throw new RegionDestroyedException(toString(), getFullPath());
        }
    }
    return ret;
}
Also used : CacheException(org.apache.geode.cache.CacheException) TransactionDataNotColocatedException(org.apache.geode.cache.TransactionDataNotColocatedException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) EntryExistsException(org.apache.geode.cache.EntryExistsException) PutResult(org.apache.geode.internal.cache.partitioned.PutMessage.PutResult) PutMessage(org.apache.geode.internal.cache.partitioned.PutMessage) TransactionDataRebalancedException(org.apache.geode.cache.TransactionDataRebalancedException)

Example 10 with TransactionDataRebalancedException

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

the class MyTransactionFunction method verifyInvalidateOperation.

private void verifyInvalidateOperation(RegionFunctionContext ctx) {
    Region custPR = ctx.getDataSet();
    Region orderPR = custPR.getCache().getRegion(PRTransactionDUnitTest.OrderPartitionedRegionName);
    CacheTransactionManager mgr = custPR.getCache().getCacheTransactionManager();
    ArrayList args = (ArrayList) ctx.getArguments();
    CustId custId = (CustId) args.get(1);
    Customer newCus = (Customer) args.get(2);
    OrderId orderId = (OrderId) args.get(3);
    Order order = (Order) args.get(4);
    Customer oldCustomer = (Customer) custPR.get(custId);
    Customer commitedCust = null;
    // test destroy rollback
    mgr.begin();
    custPR.put(custId, newCus);
    custPR.invalidate(custId);
    orderPR.put(orderId, order);
    mgr.rollback();
    commitedCust = (Customer) custPR.get(custId);
    Assert.assertTrue(oldCustomer.equals(commitedCust), "Expected customer to rollback to:" + oldCustomer + " but was:" + commitedCust);
    // test destroy rollback on unmodified entry
    mgr.begin();
    custPR.invalidate(custId);
    orderPR.put(orderId, order);
    mgr.rollback();
    commitedCust = (Customer) custPR.get(custId);
    Assert.assertTrue(oldCustomer.equals(commitedCust), "Expected customer to rollback to:" + oldCustomer + " but was:" + commitedCust);
    // test remote destroy
    boolean caughtEx = false;
    try {
        mgr.begin();
        custPR.put(custId, new Customer("foo", "bar"));
        custPR.invalidate(custId);
        custPR.invalidate(new CustId(1));
        custPR.invalidate(new CustId(3));
        custPR.invalidate(new CustId(7));
        mgr.commit();
    } catch (Exception e) {
        mgr.rollback();
        if ((e instanceof TransactionDataNotColocatedException) || (e instanceof TransactionDataRebalancedException)) {
            caughtEx = true;
        } else if (e instanceof EntryNotFoundException && e.getMessage().matches("Entry not found for key.*1")) {
            caughtEx = true;
        } else {
            throw new TestException("Expected to catch PR remote destroy exception, but caught:" + e.getMessage(), e);
        }
    }
    if (!caughtEx) {
        throw new TestException("An Expected exception was not thrown");
    }
    // test destroy on unmodified entry
    mgr.begin();
    custPR.invalidate(custId);
    orderPR.put(orderId, order);
    mgr.commit();
    commitedCust = (Customer) custPR.get(custId);
    Assert.assertTrue(commitedCust == null, "Expected Customer to be null but was:" + commitedCust);
    Order commitedOrder = (Order) orderPR.get(orderId);
    Assert.assertTrue(order.equals(commitedOrder), "Expected Order to be:" + order + " but was:" + commitedOrder);
// test destroy on new entry
// TODO: This throws EntryNotFound
/*
     * OrderId newOrderId = new OrderId(5000,custId); mgr.begin(); orderPR.put(newOrderId, new
     * Order("New Order to be destroyed")); orderPR.invalidate(newOrderId); mgr.commit();
     * Assert.assertTrue(orderPR.get(newOrderId)==null,"Did not expect orderId to be present");
     */
}
Also used : Order(org.apache.geode.internal.cache.execute.data.Order) TestException(util.TestException) Customer(org.apache.geode.internal.cache.execute.data.Customer) ArrayList(java.util.ArrayList) OrderId(org.apache.geode.internal.cache.execute.data.OrderId) TransactionDataRebalancedException(org.apache.geode.cache.TransactionDataRebalancedException) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) TransactionDataNotColocatedException(org.apache.geode.cache.TransactionDataNotColocatedException) TestException(util.TestException) CommitConflictException(org.apache.geode.cache.CommitConflictException) PartitionedRegionException(org.apache.geode.internal.cache.PartitionedRegionException) TransactionDataRebalancedException(org.apache.geode.cache.TransactionDataRebalancedException) CacheTransactionManager(org.apache.geode.cache.CacheTransactionManager) CustId(org.apache.geode.internal.cache.execute.data.CustId) TransactionDataNotColocatedException(org.apache.geode.cache.TransactionDataNotColocatedException) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) LocalRegion(org.apache.geode.internal.cache.LocalRegion) BucketRegion(org.apache.geode.internal.cache.BucketRegion) Region(org.apache.geode.cache.Region) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion)

Aggregations

TransactionDataRebalancedException (org.apache.geode.cache.TransactionDataRebalancedException)19 TransactionDataNotColocatedException (org.apache.geode.cache.TransactionDataNotColocatedException)9 TransactionException (org.apache.geode.cache.TransactionException)9 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)6 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)6 CommitConflictException (org.apache.geode.cache.CommitConflictException)5 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)5 Entry (org.apache.geode.cache.Region.Entry)4 UnsupportedOperationInTransactionException (org.apache.geode.cache.UnsupportedOperationInTransactionException)4 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)4 ArrayList (java.util.ArrayList)3 CacheException (org.apache.geode.cache.CacheException)3 CacheTransactionManager (org.apache.geode.cache.CacheTransactionManager)3 Region (org.apache.geode.cache.Region)3 TransactionDataNodeHasDepartedException (org.apache.geode.cache.TransactionDataNodeHasDepartedException)3 TransactionWriterException (org.apache.geode.cache.TransactionWriterException)3 ForceReattemptException (org.apache.geode.internal.cache.ForceReattemptException)3 PrimaryBucketException (org.apache.geode.internal.cache.PrimaryBucketException)3 CustId (org.apache.geode.internal.cache.execute.data.CustId)3 HashSet (java.util.HashSet)2