Search in sources :

Example 1 with PartitionedRegionException

use of org.apache.geode.internal.cache.PartitionedRegionException in project geode by apache.

the class PartitionedRegionDUnitTest method testBadHash.

@Test
public void testBadHash() {
    final String regionName = getUniqueName();
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    SerializableRunnable createPR = new SerializableRunnable("createPartitionedRegion") {

        public void run() {
            try {
                createRegion(regionName, "root", getRegionAttributes());
            } catch (CacheException ex) {
                Assert.fail("While creating Partitioned region", ex);
            }
        }
    };
    vm0.invoke(createPR);
    vm1.invoke(createPR);
    vm0.invoke(new SerializableRunnable("Populate 1") {

        public void run() {
            Region region = getRootRegion().getSubregion(regionName);
            for (int i = 0; i < 10; i++) {
                String st = Integer.toString(i);
                PoisonedKey pk = new PoisonedKey(st);
                region.create(pk, st);
            }
        }
    });
    // Verify values are readily accessible
    vm1.invoke(new SerializableRunnable("Read 1") {

        public void run() {
            Region region = getRootRegion().getSubregion(regionName);
            for (int i = 0; i < 10; i++) {
                String st = Integer.toString(i);
                PoisonedKey pk = new PoisonedKey(st);
                assertTrue("Keys screwed up too early", region.get(pk).equals(st));
            }
        }
    });
    // Bucket ID's will be screwed up with these creates.
    vm0.invoke(new SerializableRunnable("Populate 2") {

        public void run() {
            Region region = getRootRegion().getSubregion(regionName);
            PoisonedKey.poisoned = true;
            try {
                for (int i = 10; i < 20; i++) {
                    String st = Integer.toString(i);
                    PoisonedKey pk = new PoisonedKey(st);
                    region.create(pk, st);
                }
            } catch (PartitionedRegionException e) {
                PoisonedKey.poisonDetected = true;
            } finally {
                // restore default static value
                PoisonedKey.poisoned = false;
            }
        }
    });
    boolean success = vm0.invoke(() -> PoisonedKey.poisonFound());
    assertTrue("Hash mismatch not found", success);
}
Also used : PartitionedRegionException(org.apache.geode.internal.cache.PartitionedRegionException) CacheException(org.apache.geode.cache.CacheException) VM(org.apache.geode.test.dunit.VM) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Region(org.apache.geode.cache.Region) Host(org.apache.geode.test.dunit.Host) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 2 with PartitionedRegionException

use of org.apache.geode.internal.cache.PartitionedRegionException in project geode by apache.

the class RemoveIndexesMessage method process.

/**
   * Processes remove index on the receiver.
   */
@Override
public void process(final DistributionManager dm) {
    Throwable thr = null;
    boolean sendReply = true;
    PartitionedRegion pr = null;
    try {
        logger.info(LocalizedMessage.create(LocalizedStrings.RemoveIndexesMessage_TRYING_TO_GET_PR_WITH_ID___0, this.regionId));
        pr = PartitionedRegion.getPRFromId(this.regionId);
        logger.info(LocalizedMessage.create(LocalizedStrings.RemoveIndexesMessage_REMOVE_INDEXES_MESSAGE_GOT_THE_PR__0, pr));
        if (pr == null) /* && failIfRegionMissing() */
        {
            throw new PartitionedRegionException(LocalizedStrings.RemoveIndexesMessage_COULD_NOT_GET_PARTITIONED_REGION_FROM_ID_0_FOR_MESSAGE_1_RECEIVED_ON_MEMBER_2_MAP_3.toLocalizedString(new Object[] { Integer.valueOf(this.regionId), this, dm.getId(), PartitionedRegion.dumpPRId() }));
        }
        // remove the indexes on the pr.
        sendReply = operateOnPartitionedRegion(dm, pr, 0);
    } catch (PRLocallyDestroyedException pde) {
        if (logger.isDebugEnabled()) {
            logger.debug("Region is locally Destroyed ");
        }
        thr = pde;
    } catch (VirtualMachineError err) {
        SystemFailure.initiateFailure(err);
        // now, so don't let this thread continue.
        throw err;
    } catch (Throwable t) {
        // Whenever you catch Error or Throwable, you must also
        // catch VirtualMachineError (see above). However, there is
        // _still_ a possibility that you are dealing with a cascading
        // error condition, so you also need to check to see if the JVM
        // is still usable:
        SystemFailure.checkFailure();
        // log the exception at fine level if there is no reply to the message
        if (this.processorId == 0) {
            logger.debug("{} exception while processing message: {}", this, t.getMessage(), t);
        } else if (logger.isTraceEnabled(LogMarker.DM) && (t instanceof RuntimeException)) {
            logger.debug("Exception caught while processing message: {}", t.getMessage(), t);
        }
        if (t instanceof RegionDestroyedException && pr != null) {
            if (pr.isClosed) {
                logger.info(LocalizedMessage.create(LocalizedStrings.RemoveIndexesMessage_REGION_IS_LOCALLY_DESTROYED_THROWING_REGIONDESTROYEDEXCEPTION_FOR__0, pr));
                thr = new RegionDestroyedException(LocalizedStrings.RemoveIndexesMessage_REGION_IS_LOCALLY_DESTROYED_ON_0.toLocalizedString(dm.getId()), pr.getFullPath());
            }
        } else {
            thr = t;
        }
    } finally {
        if (sendReply && this.processorId != 0) {
            ReplyException rex = null;
            if (thr != null) {
                rex = new ReplyException(thr);
            }
            sendReply(getSender(), this.processorId, dm, rex, pr, 0);
        }
    }
}
Also used : PartitionedRegionException(org.apache.geode.internal.cache.PartitionedRegionException) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) ReplyException(org.apache.geode.distributed.internal.ReplyException)

Example 3 with PartitionedRegionException

use of org.apache.geode.internal.cache.PartitionedRegionException in project geode by apache.

the class IndexCreationMsg method process.

/**
   * Process this index creation message on the receiver.
   */
@Override
public void process(final DistributionManager dm) {
    final boolean isDebugEnabled = logger.isDebugEnabled();
    Throwable thr = null;
    boolean sendReply = true;
    PartitionedRegion pr = null;
    try {
        if (isDebugEnabled) {
            logger.debug("Trying to get pr with id: {}", this.regionId);
        }
        try {
            if (isDebugEnabled) {
                logger.debug("Again trying to get pr with id : {}", this.regionId);
            }
            pr = PartitionedRegion.getPRFromId(this.regionId);
            if (isDebugEnabled) {
                logger.debug("Index creation message got the pr {}", pr);
            }
            if (null == pr) {
                boolean wait = true;
                int attempts = 0;
                while (wait && attempts < 30) {
                    // max 30 seconds of wait.
                    dm.getCancelCriterion().checkCancelInProgress(null);
                    if (isDebugEnabled) {
                        logger.debug("Waiting for Partitioned Region to be intialized with id {}for processing index creation messages", this.regionId);
                    }
                    try {
                        boolean interrupted = Thread.interrupted();
                        try {
                            Thread.sleep(500);
                        } catch (InterruptedException e) {
                            interrupted = true;
                            dm.getCancelCriterion().checkCancelInProgress(e);
                        } finally {
                            if (interrupted)
                                Thread.currentThread().interrupt();
                        }
                        pr = PartitionedRegion.getPRFromId(this.regionId);
                        if (null != pr) {
                            wait = false;
                            if (isDebugEnabled) {
                                logger.debug("Indexcreation message got the pr {}", pr);
                            }
                        }
                        attempts++;
                    } catch (CancelException ignorAndLoopWait) {
                        if (isDebugEnabled) {
                            logger.debug("IndexCreationMsg waiting for pr to be properly created with prId : {}", this.regionId);
                        }
                    }
                }
            }
        } catch (CancelException letPRInitialized) {
            // to the PR being initialized.
            if (logger.isDebugEnabled()) {
                logger.debug("Waiting for notification from pr being properly created on {}", this.regionId);
            }
            boolean wait = true;
            while (wait) {
                dm.getCancelCriterion().checkCancelInProgress(null);
                try {
                    boolean interrupted = Thread.interrupted();
                    try {
                        Thread.sleep(500);
                    } catch (InterruptedException e) {
                        interrupted = true;
                        dm.getCancelCriterion().checkCancelInProgress(e);
                    } finally {
                        if (interrupted)
                            Thread.currentThread().interrupt();
                    }
                    pr = PartitionedRegion.getPRFromId(this.regionId);
                    wait = false;
                    if (logger.isDebugEnabled()) {
                        logger.debug("Indexcreation message got the pr {}", pr);
                    }
                } catch (CancelException ignorAndLoopWait) {
                    if (logger.isDebugEnabled()) {
                        logger.debug("IndexCreationMsg waiting for pr to be properly created with prId : {}", this.regionId);
                    }
                }
            }
        }
        if (pr == null) /* && failIfRegionMissing() */
        {
            String msg = LocalizedStrings.IndexCreationMsg_COULD_NOT_GET_PARTITIONED_REGION_FROM_ID_0_FOR_MESSAGE_1_RECEIVED_ON_MEMBER_2_MAP_3.toLocalizedString(new Object[] { Integer.valueOf(this.regionId), this, dm.getId(), PartitionedRegion.dumpPRId() });
            throw new PartitionedRegionException(msg, new RegionNotFoundException(msg));
        }
        sendReply = operateOnPartitionedRegion(dm, pr, 0);
    } catch (PRLocallyDestroyedException pre) {
        if (isDebugEnabled) {
            logger.debug("Region is locally Destroyed ");
        }
        thr = pre;
    } catch (VirtualMachineError err) {
        SystemFailure.initiateFailure(err);
        // now, so don't let this thread continue.
        throw err;
    } catch (Throwable t) {
        // Whenever you catch Error or Throwable, you must also
        // catch VirtualMachineError (see above). However, there is
        // _still_ a possibility that you are dealing with a cascading
        // error condition, so you also need to check to see if the JVM
        // is still usable:
        SystemFailure.checkFailure();
        // log the exception at fine level if there is no reply to the message
        if (this.processorId == 0) {
            logger.debug("{} exception while processing message:{}", this, t.getMessage(), t);
        } else if (logger.isDebugEnabled(LogMarker.DM) && (t instanceof RuntimeException)) {
            logger.debug(LogMarker.DM, "Exception caught while processing message: {}", t.getMessage(), t);
        }
        if (t instanceof RegionDestroyedException && pr != null) {
            if (pr.isClosed) {
                logger.info(LocalizedMessage.create(LocalizedStrings.IndexCreationMsg_REGION_IS_LOCALLY_DESTROYED_THROWING_REGIONDESTROYEDEXCEPTION_FOR__0, pr));
                thr = new RegionDestroyedException(LocalizedStrings.IndexCreationMsg_REGION_IS_LOCALLY_DESTROYED_ON_0.toLocalizedString(dm.getId()), pr.getFullPath());
            }
        } else {
            thr = t;
        }
    } finally {
        if (sendReply && this.processorId != 0) {
            ReplyException rex = null;
            if (thr != null) {
                rex = new ReplyException(thr);
            }
            sendReply(getSender(), this.processorId, dm, rex, pr, 0);
        }
    }
}
Also used : PartitionedRegionException(org.apache.geode.internal.cache.PartitionedRegionException) RegionNotFoundException(org.apache.geode.cache.query.RegionNotFoundException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) ReplyException(org.apache.geode.distributed.internal.ReplyException) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) CancelException(org.apache.geode.CancelException)

Example 4 with PartitionedRegionException

use of org.apache.geode.internal.cache.PartitionedRegionException in project geode by apache.

the class DistributedTXRegionStub method destroyExistingEntry.

public void destroyExistingEntry(EntryEventImpl event, boolean cacheWrite, Object expectedOldValue) {
    // this.prStats.incPartitionMessagesSent();
    try {
        RemoteOperationResponse response = RemoteDestroyMessage.send(state.getTarget(), event.getLocalRegion(), event, expectedOldValue, DistributionManager.PARTITIONED_REGION_EXECUTOR, true, false);
        response.waitForCacheException();
    } catch (EntryNotFoundException enfe) {
        throw enfe;
    } catch (TransactionDataNotColocatedException enfe) {
        throw enfe;
    } catch (CacheException ce) {
        throw new PartitionedRegionException(LocalizedStrings.PartitionedRegion_DESTROY_OF_ENTRY_ON_0_FAILED.toLocalizedString(state.getTarget()), ce);
    } catch (RegionDestroyedException rde) {
        throw new TransactionDataNotColocatedException(LocalizedStrings.RemoteMessage_REGION_0_NOT_COLOCATED_WITH_TRANSACTION.toLocalizedString(rde.getRegionFullPath()), rde);
    } catch (RemoteOperationException roe) {
        throw new TransactionDataNodeHasDepartedException(roe);
    }
}
Also used : PartitionedRegionException(org.apache.geode.internal.cache.PartitionedRegionException) CacheException(org.apache.geode.cache.CacheException) TransactionDataNotColocatedException(org.apache.geode.cache.TransactionDataNotColocatedException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) RemoteOperationException(org.apache.geode.internal.cache.RemoteOperationException) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) RemoteOperationResponse(org.apache.geode.internal.cache.RemoteOperationMessage.RemoteOperationResponse) TransactionDataNodeHasDepartedException(org.apache.geode.cache.TransactionDataNodeHasDepartedException)

Example 5 with PartitionedRegionException

use of org.apache.geode.internal.cache.PartitionedRegionException in project geode by apache.

the class DistributedTXRegionStub 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();
    try {
        RemotePutResponse response = RemotePutMessage.txSend(state.getTarget(), r, event, lastModified, ifNew, ifOld, expectedOldValue, requireOldValue);
        PutResult result = response.waitForResult();
        event.setOldValue(result.oldValue, true);
        retVal = result.returnValue;
    } catch (TransactionDataNotColocatedException enfe) {
        throw enfe;
    } catch (CacheException ce) {
        throw new PartitionedRegionException(LocalizedStrings.PartitionedRegion_DESTROY_OF_ENTRY_ON_0_FAILED.toLocalizedString(state.getTarget()), ce);
    } catch (RegionDestroyedException rde) {
        throw new TransactionDataNotColocatedException(LocalizedStrings.RemoteMessage_REGION_0_NOT_COLOCATED_WITH_TRANSACTION.toLocalizedString(rde.getRegionFullPath()), rde);
    } catch (RemoteOperationException roe) {
        throw new TransactionDataNodeHasDepartedException(roe);
    }
    return retVal;
}
Also used : PartitionedRegionException(org.apache.geode.internal.cache.PartitionedRegionException) CacheException(org.apache.geode.cache.CacheException) TransactionDataNotColocatedException(org.apache.geode.cache.TransactionDataNotColocatedException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) RemoteOperationException(org.apache.geode.internal.cache.RemoteOperationException) RemotePutResponse(org.apache.geode.internal.cache.RemotePutMessage.RemotePutResponse) LocalRegion(org.apache.geode.internal.cache.LocalRegion) PutResult(org.apache.geode.internal.cache.RemotePutMessage.PutResult) TransactionDataNodeHasDepartedException(org.apache.geode.cache.TransactionDataNodeHasDepartedException)

Aggregations

PartitionedRegionException (org.apache.geode.internal.cache.PartitionedRegionException)5 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)4 CacheException (org.apache.geode.cache.CacheException)3 TransactionDataNodeHasDepartedException (org.apache.geode.cache.TransactionDataNodeHasDepartedException)2 TransactionDataNotColocatedException (org.apache.geode.cache.TransactionDataNotColocatedException)2 ReplyException (org.apache.geode.distributed.internal.ReplyException)2 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)2 RemoteOperationException (org.apache.geode.internal.cache.RemoteOperationException)2 CancelException (org.apache.geode.CancelException)1 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)1 Region (org.apache.geode.cache.Region)1 RegionNotFoundException (org.apache.geode.cache.query.RegionNotFoundException)1 LocalRegion (org.apache.geode.internal.cache.LocalRegion)1 RemoteOperationResponse (org.apache.geode.internal.cache.RemoteOperationMessage.RemoteOperationResponse)1 PutResult (org.apache.geode.internal.cache.RemotePutMessage.PutResult)1 RemotePutResponse (org.apache.geode.internal.cache.RemotePutMessage.RemotePutResponse)1 Host (org.apache.geode.test.dunit.Host)1 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)1 VM (org.apache.geode.test.dunit.VM)1 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)1