Search in sources :

Example 11 with TransactionDataNotColocatedException

use of org.apache.geode.cache.TransactionDataNotColocatedException 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 12 with TransactionDataNotColocatedException

use of org.apache.geode.cache.TransactionDataNotColocatedException 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 13 with TransactionDataNotColocatedException

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

the class RemoteTransactionDUnitTest method testTxRemoveAllNotColocated.

@Test
public void testTxRemoveAllNotColocated() {
    Host host = Host.getHost(0);
    VM acc = host.getVM(0);
    VM datastore1 = host.getVM(1);
    VM datastore2 = host.getVM(3);
    datastore2.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            createRegion(false, /* accessor */
            0, null);
            return null;
        }
    });
    initAccessorAndDataStore(acc, datastore1, 0);
    VM accessor = getVMForTransactions(acc, datastore1);
    final CustId custId0 = new CustId(0);
    final CustId custId1 = new CustId(1);
    final CustId custId2 = new CustId(2);
    final CustId custId3 = new CustId(3);
    final CustId custId4 = new CustId(4);
    final CustId custId20 = new CustId(20);
    final TXId txId = (TXId) accessor.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            Region<CustId, Customer> cust = getGemfireCache().getRegion(CUSTOMER);
            Region<CustId, Customer> ref = getGemfireCache().getRegion(D_REFERENCE);
            TXManagerImpl mgr = getGemfireCache().getTxManager();
            mgr.begin();
            Customer customer = new Customer("customer1", "address1");
            Customer customer2 = new Customer("customer2", "address2");
            Customer fakeCust = new Customer("foo2", "bar2");
            try {
                cust.removeAll(Arrays.asList(custId0, custId4, custId1, custId2, custId3, custId20));
                fail("expected exception not thrown");
            } catch (TransactionDataNotColocatedException e) {
                mgr.rollback();
            }
            assertNotNull(cust.get(custId0));
            assertNotNull(cust.get(custId1));
            assertNotNull(cust.get(custId2));
            assertNotNull(cust.get(custId3));
            assertNotNull(cust.get(custId4));
            return mgr.getTransactionId();
        }
    });
}
Also used : CustId(org.apache.geode.internal.cache.execute.data.CustId) Customer(org.apache.geode.internal.cache.execute.data.Customer) TransactionDataNotColocatedException(org.apache.geode.cache.TransactionDataNotColocatedException) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) Host(org.apache.geode.test.dunit.Host) NamingException(javax.naming.NamingException) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) TransactionWriterException(org.apache.geode.cache.TransactionWriterException) CacheWriterException(org.apache.geode.cache.CacheWriterException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) TransactionDataRebalancedException(org.apache.geode.cache.TransactionDataRebalancedException) TransactionException(org.apache.geode.cache.TransactionException) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) UnsupportedOperationInTransactionException(org.apache.geode.cache.UnsupportedOperationInTransactionException) RollbackException(javax.transaction.RollbackException) TransactionDataNotColocatedException(org.apache.geode.cache.TransactionDataNotColocatedException) CommitConflictException(org.apache.geode.cache.CommitConflictException) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) TXExpiryJUnitTest(org.apache.geode.TXExpiryJUnitTest) Test(org.junit.Test)

Example 14 with TransactionDataNotColocatedException

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

Example 15 with TransactionDataNotColocatedException

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

the class PRTransactionDUnitTest method basicPRTXInFunction.

/**
   * Test all the basic functionality of colocated transactions. This method invokes
   * {@link MyTransactionFunction} and tells it what to test, using different arguments.
   * 
   * @param redundantBuckets redundant buckets for colocated PRs
   * @param populateData if false tests are carried out on empty colocated PRs
   */
protected void basicPRTXInFunction(int redundantBuckets, boolean populateData) {
    if (populateData) {
        createPopulateAndVerifyCoLocatedPRs(redundantBuckets);
    } else {
        createColocatedPRs(redundantBuckets);
    }
    SerializableCallable registerFunction = new SerializableCallable("register Fn") {

        public Object call() throws Exception {
            Function txFunction = new MyTransactionFunction();
            FunctionService.registerFunction(txFunction);
            return Boolean.TRUE;
        }
    };
    dataStore1.invoke(registerFunction);
    dataStore2.invoke(registerFunction);
    dataStore3.invoke(registerFunction);
    accessor.invoke(new SerializableCallable("run function") {

        public Object call() throws Exception {
            PartitionedRegion pr = (PartitionedRegion) basicGetCache().getRegion(Region.SEPARATOR + CustomerPartitionedRegionName);
            PartitionedRegion orderpr = (PartitionedRegion) basicGetCache().getRegion(Region.SEPARATOR + OrderPartitionedRegionName);
            CustId custId = new CustId(2);
            Customer newCus = new Customer("foo", "bar");
            Order order = new Order("fooOrder");
            OrderId orderId = new OrderId(22, custId);
            ArrayList args = new ArrayList();
            Function txFunction = new MyTransactionFunction();
            FunctionService.registerFunction(txFunction);
            Execution e = FunctionService.onRegion(pr);
            Set filter = new HashSet();
            // test transaction non-coLocated operations
            filter.clear();
            args.clear();
            args.add(new Integer(VERIFY_NON_COLOCATION));
            LogWriterUtils.getLogWriter().info("VERIFY_NON_COLOCATION");
            args.add(custId);
            args.add(newCus);
            args.add(orderId);
            args.add(order);
            filter.add(custId);
            try {
                e.withFilter(filter).setArguments(args).execute(txFunction.getId()).getResult();
                fail("Expected exception was not thrown");
            } catch (FunctionException fe) {
                LogWriterUtils.getLogWriter().info("Caught Expected exception");
                if (fe.getCause() instanceof TransactionDataNotColocatedException) {
                } else {
                    throw new TestException("Expected to catch FunctionException with cause TransactionDataNotColocatedException" + " but cause is  " + fe.getCause(), fe.getCause());
                }
            }
            // verify that the transaction modifications are applied
            args.set(0, new Integer(VERIFY_TX));
            LogWriterUtils.getLogWriter().info("VERIFY_TX");
            orderpr.put(orderId, order);
            assertNotNull(orderpr.get(orderId));
            e.withFilter(filter).setArguments(args).execute(txFunction.getId()).getResult();
            assertTrue("Unexpected customer value after commit", newCus.equals(pr.get(custId)));
            Order commitedOrder = (Order) orderpr.get(orderId);
            assertTrue("Unexpected order value after commit. Expected:" + order + " Found:" + commitedOrder, order.equals(commitedOrder));
            // verify conflict detection
            args.set(0, new Integer(VERIFY_TXSTATE_CONFLICT));
            e.withFilter(filter).setArguments(args).execute(txFunction.getId()).getResult();
            // verify that the transaction is rolled back
            args.set(0, new Integer(VERIFY_ROLLBACK));
            LogWriterUtils.getLogWriter().info("VERIFY_ROLLBACK");
            e.withFilter(filter).setArguments(args).execute(txFunction.getId()).getResult();
            // verify destroy
            args.set(0, new Integer(VERIFY_DESTROY));
            LogWriterUtils.getLogWriter().info("VERIFY_DESTROY");
            e.withFilter(filter).setArguments(args).execute(txFunction.getId()).getResult();
            // verify invalidate
            args.set(0, new Integer(VERIFY_INVALIDATE));
            LogWriterUtils.getLogWriter().info("VERIFY_INVALIDATE");
            e.withFilter(filter).setArguments(args).execute(txFunction.getId()).getResult();
            return Boolean.TRUE;
        }
    });
}
Also used : Order(org.apache.geode.internal.cache.execute.data.Order) HashSet(java.util.HashSet) Set(java.util.Set) TestException(util.TestException) Customer(org.apache.geode.internal.cache.execute.data.Customer) ArrayList(java.util.ArrayList) FunctionException(org.apache.geode.cache.execute.FunctionException) OrderId(org.apache.geode.internal.cache.execute.data.OrderId) ForceReattemptException(org.apache.geode.internal.cache.ForceReattemptException) TransactionDataRebalancedException(org.apache.geode.cache.TransactionDataRebalancedException) FunctionException(org.apache.geode.cache.execute.FunctionException) TransactionDataNotColocatedException(org.apache.geode.cache.TransactionDataNotColocatedException) TestException(util.TestException) PRLocallyDestroyedException(org.apache.geode.internal.cache.partitioned.PRLocallyDestroyedException) Function(org.apache.geode.cache.execute.Function) Execution(org.apache.geode.cache.execute.Execution) CustId(org.apache.geode.internal.cache.execute.data.CustId) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) TransactionDataNotColocatedException(org.apache.geode.cache.TransactionDataNotColocatedException) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) HashSet(java.util.HashSet)

Aggregations

TransactionDataNotColocatedException (org.apache.geode.cache.TransactionDataNotColocatedException)27 TransactionDataRebalancedException (org.apache.geode.cache.TransactionDataRebalancedException)13 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)11 CacheException (org.apache.geode.cache.CacheException)10 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)10 TransactionException (org.apache.geode.cache.TransactionException)10 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)9 ArrayList (java.util.ArrayList)8 CustId (org.apache.geode.internal.cache.execute.data.CustId)7 CommitConflictException (org.apache.geode.cache.CommitConflictException)6 Region (org.apache.geode.cache.Region)6 TransactionDataNodeHasDepartedException (org.apache.geode.cache.TransactionDataNodeHasDepartedException)6 RemoteOperationException (org.apache.geode.internal.cache.RemoteOperationException)6 Customer (org.apache.geode.internal.cache.execute.data.Customer)6 Collection (java.util.Collection)5 CancelException (org.apache.geode.CancelException)5 UnsupportedOperationInTransactionException (org.apache.geode.cache.UnsupportedOperationInTransactionException)5 NamingException (javax.naming.NamingException)4 RollbackException (javax.transaction.RollbackException)4 CacheLoaderException (org.apache.geode.cache.CacheLoaderException)4