Search in sources :

Example 1 with DistributedRegion

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

the class PRSanityCheckMessage method schedule.

/**
   * Send a sanity check message and schedule a timer to send another one in
   * gemfire.PRSanityCheckInterval (default 5000) milliseconds. This can be enabled with
   * gemfire.PRSanityCheckEnabled=true.
   */
public static void schedule(final PartitionedRegion pr) {
    if (Boolean.getBoolean(DistributionConfig.GEMFIRE_PREFIX + "PRSanityCheckEnabled")) {
        final DM dm = pr.getDistributionManager();
        // RegionAdvisor ra = pr.getRegionAdvisor();
        // final Set recipients = ra.adviseAllPRNodes();
        DistributedRegion prRoot = (DistributedRegion) PartitionedRegionHelper.getPRRoot(pr.getCache(), false);
        if (prRoot == null) {
            return;
        }
        final Set recipients = prRoot.getDistributionAdvisor().adviseGeneric();
        if (recipients.size() <= 0) {
            return;
        }
        final PRSanityCheckMessage delayedInstance = new PRSanityCheckMessage(recipients, pr.getPRId(), null, pr.getRegionIdentifier());
        PRSanityCheckMessage instance = new PRSanityCheckMessage(recipients, pr.getPRId(), null, pr.getRegionIdentifier());
        dm.putOutgoing(instance);
        int sanityCheckInterval = Integer.getInteger(DistributionConfig.GEMFIRE_PREFIX + "PRSanityCheckInterval", 5000).intValue();
        if (sanityCheckInterval != 0) {
            final SystemTimer tm = new SystemTimer(dm.getSystem(), true);
            SystemTimer.SystemTimerTask st = new SystemTimer.SystemTimerTask() {

                @Override
                public void run2() {
                    try {
                        if (!pr.isLocallyDestroyed && !pr.isClosed && !pr.isDestroyed()) {
                            dm.putOutgoing(delayedInstance);
                        }
                    } catch (CancelException cce) {
                    // cache is closed - can't send the message
                    } finally {
                        tm.cancel();
                    }
                }
            };
            tm.schedule(st, sanityCheckInterval);
        }
    }
}
Also used : Set(java.util.Set) DM(org.apache.geode.distributed.internal.DM) CancelException(org.apache.geode.CancelException) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) SystemTimer(org.apache.geode.internal.SystemTimer)

Example 2 with DistributedRegion

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

the class ParallelGatewaySenderEventProcessor method enqueueEvent.

@Override
public void enqueueEvent(EnumListenerEvent operation, EntryEvent event, Object substituteValue) throws IOException, CacheException {
    GatewaySenderEventImpl gatewayQueueEvent = null;
    Region region = event.getRegion();
    if (!(region instanceof DistributedRegion) && ((EntryEventImpl) event).getTailKey() == -1) {
        // Fix for #49081 and EntryDestroyedException in #49367.
        if (logger.isDebugEnabled()) {
            logger.debug("ParallelGatewaySenderEventProcessor not enqueing the following event since tailKey is not set. {}", event);
        }
        return;
    }
    // TODO: Looks like for PDX region bucket id is set to -1.
    boolean queuedEvent = false;
    try {
        EventID eventID = ((EntryEventImpl) event).getEventId();
        // while merging 42004, kept substituteValue as it is(it is barry's
        // change 42466). bucketID is merged with eventID.getBucketID
        gatewayQueueEvent = new GatewaySenderEventImpl(operation, event, substituteValue, true, eventID.getBucketID());
        if (getSender().beforeEnqueue(gatewayQueueEvent)) {
            long start = getSender().getStatistics().startTime();
            try {
                queuedEvent = this.queue.put(gatewayQueueEvent);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            getSender().getStatistics().endPut(start);
        } else {
            if (logger.isDebugEnabled()) {
                logger.debug("The Event {} is filtered.", gatewayQueueEvent);
            }
            getSender().getStatistics().incEventsFiltered();
        }
    } finally {
        if (!queuedEvent) {
            // it was not queued for some reason
            gatewayQueueEvent.release();
        }
    }
}
Also used : EntryEventImpl(org.apache.geode.internal.cache.EntryEventImpl) GatewaySenderEventImpl(org.apache.geode.internal.cache.wan.GatewaySenderEventImpl) LocalRegion(org.apache.geode.internal.cache.LocalRegion) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) Region(org.apache.geode.cache.Region) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) EventID(org.apache.geode.internal.cache.EventID) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion)

Example 3 with DistributedRegion

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

the class ParallelGatewaySenderQueue method remove.

@Override
public void remove() throws CacheException {
    if (!this.peekedEvents.isEmpty()) {
        GatewaySenderEventImpl event = this.peekedEvents.remove();
        try {
            PartitionedRegion prQ = null;
            int bucketId = -1;
            Object key = null;
            if (event.getRegion() != null) {
                if (isDREvent(event)) {
                    prQ = this.userRegionNameToshadowPRMap.get(event.getRegion().getFullPath());
                    bucketId = event.getEventId().getBucketID();
                    key = event.getEventId();
                } else {
                    prQ = this.userRegionNameToshadowPRMap.get(ColocationHelper.getLeaderRegion((PartitionedRegion) event.getRegion()).getFullPath());
                    bucketId = event.getBucketId();
                    key = event.getShadowKey();
                }
            } else {
                String regionPath = event.getRegionPath();
                InternalCache cache = this.sender.getCache();
                Region region = (PartitionedRegion) cache.getRegion(regionPath);
                if (region != null && !region.isDestroyed()) {
                    // TODO: We have to get colocated parent region for this region
                    if (region instanceof DistributedRegion) {
                        prQ = this.userRegionNameToshadowPRMap.get(region.getFullPath());
                        event.getBucketId();
                        key = event.getEventId();
                    } else {
                        prQ = this.userRegionNameToshadowPRMap.get(ColocationHelper.getLeaderRegion((PartitionedRegion) region).getFullPath());
                        event.getBucketId();
                        key = event.getShadowKey();
                    }
                }
            }
            if (prQ != null) {
                destroyEventFromQueue(prQ, bucketId, key);
            }
        } finally {
            try {
                event.release();
            } catch (IllegalStateException e) {
                logger.error("Exception caught and logged.  The thread will continue running", e);
            }
        }
    }
}
Also used : PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) GatewaySenderEventImpl(org.apache.geode.internal.cache.wan.GatewaySenderEventImpl) InternalCache(org.apache.geode.internal.cache.InternalCache) LocalRegion(org.apache.geode.internal.cache.LocalRegion) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) BucketRegion(org.apache.geode.internal.cache.BucketRegion) Region(org.apache.geode.cache.Region) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion)

Example 4 with DistributedRegion

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

the class MembershipViewRequest method process.

@Override
protected void process(DistributionManager dm) {
    int initLevel = this.targetReinitializing ? LocalRegion.AFTER_INITIAL_IMAGE : LocalRegion.ANY_INIT;
    int oldLevel = LocalRegion.setThreadInitLevelRequirement(initLevel);
    PersistentMembershipView view = null;
    ReplyException exception = null;
    try {
        // get the region from the path, but do NOT wait on initialization,
        // otherwise we could have a distributed deadlock
        Cache cache = CacheFactory.getInstance(dm.getSystem());
        Region region = cache.getRegion(this.regionPath);
        PersistenceAdvisor persistenceAdvisor = null;
        if (region instanceof DistributedRegion) {
            persistenceAdvisor = ((DistributedRegion) region).getPersistenceAdvisor();
        } else if (region == null) {
            Bucket proxy = PartitionedRegionHelper.getProxyBucketRegion(GemFireCacheImpl.getInstance(), this.regionPath, false);
            if (proxy != null) {
                persistenceAdvisor = proxy.getPersistenceAdvisor();
            }
        }
        if (persistenceAdvisor != null) {
            view = persistenceAdvisor.getMembershipView();
        }
    } catch (RegionDestroyedException e) {
        // exception = new ReplyException(e);
        logger.debug("<RegionDestroyed> {}", this);
    } catch (CancelException e) {
        // exception = new ReplyException(e);
        logger.debug("<CancelException> {}", this);
    } catch (VirtualMachineError e) {
        SystemFailure.initiateFailure(e);
        throw e;
    } catch (Throwable t) {
        SystemFailure.checkFailure();
        exception = new ReplyException(t);
    } finally {
        LocalRegion.setThreadInitLevelRequirement(oldLevel);
        MembershipViewReplyMessage replyMsg = new MembershipViewReplyMessage();
        replyMsg.setRecipient(getSender());
        replyMsg.setProcessorId(processorId);
        replyMsg.view = view;
        if (logger.isDebugEnabled()) {
            logger.debug("MembershipViewRequest returning view {} for region {}", view, this.regionPath);
        }
        if (exception != null) {
            replyMsg.setException(exception);
        }
        dm.putOutgoing(replyMsg);
    }
}
Also used : RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) ReplyException(org.apache.geode.distributed.internal.ReplyException) Bucket(org.apache.geode.internal.cache.partitioned.Bucket) LocalRegion(org.apache.geode.internal.cache.LocalRegion) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) Region(org.apache.geode.cache.Region) CancelException(org.apache.geode.CancelException) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) Cache(org.apache.geode.cache.Cache)

Example 5 with DistributedRegion

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

the class PrepareNewPersistentMemberMessage method process.

@Override
protected void process(DistributionManager dm) {
    // Set thread local flag to allow entrance through initialization Latch
    int oldLevel = LocalRegion.setThreadInitLevelRequirement(LocalRegion.ANY_INIT);
    PersistentMemberState state = null;
    PersistentMemberID myId = null;
    ReplyException exception = null;
    try {
        // get the region from the path, but do NOT wait on initialization,
        // otherwise we could have a distributed deadlock
        Cache cache = CacheFactory.getInstance(dm.getSystem());
        Region region = cache.getRegion(this.regionPath);
        PersistenceAdvisor persistenceAdvisor = null;
        if (region instanceof DistributedRegion) {
            persistenceAdvisor = ((DistributedRegion) region).getPersistenceAdvisor();
        } else if (region == null) {
            Bucket proxy = PartitionedRegionHelper.getProxyBucketRegion(GemFireCacheImpl.getInstance(), this.regionPath, false);
            if (proxy != null) {
                persistenceAdvisor = proxy.getPersistenceAdvisor();
            }
        }
        if (persistenceAdvisor != null) {
            persistenceAdvisor.prepareNewMember(getSender(), oldId, newId);
        }
    } catch (RegionDestroyedException e) {
        logger.debug("<RegionDestroyed> {}", this);
    } catch (CancelException e) {
        logger.debug("<CancelException> {}", this);
    } catch (VirtualMachineError e) {
        SystemFailure.initiateFailure(e);
        throw e;
    } catch (Throwable t) {
        SystemFailure.checkFailure();
        exception = new ReplyException(t);
    } finally {
        LocalRegion.setThreadInitLevelRequirement(oldLevel);
        ReplyMessage replyMsg = new ReplyMessage();
        replyMsg.setRecipient(getSender());
        replyMsg.setProcessorId(processorId);
        if (exception != null) {
            replyMsg.setException(exception);
        }
        dm.putOutgoing(replyMsg);
    }
}
Also used : RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) ReplyException(org.apache.geode.distributed.internal.ReplyException) ReplyMessage(org.apache.geode.distributed.internal.ReplyMessage) Bucket(org.apache.geode.internal.cache.partitioned.Bucket) LocalRegion(org.apache.geode.internal.cache.LocalRegion) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) Region(org.apache.geode.cache.Region) CancelException(org.apache.geode.CancelException) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) Cache(org.apache.geode.cache.Cache)

Aggregations

DistributedRegion (org.apache.geode.internal.cache.DistributedRegion)36 Region (org.apache.geode.cache.Region)25 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)16 LocalRegion (org.apache.geode.internal.cache.LocalRegion)14 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)9 VM (org.apache.geode.test.dunit.VM)9 Test (org.junit.Test)9 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)8 Cache (org.apache.geode.cache.Cache)7 Host (org.apache.geode.test.dunit.Host)7 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)7 FunctionException (org.apache.geode.cache.execute.FunctionException)6 IOException (java.io.IOException)5 AttributesFactory (org.apache.geode.cache.AttributesFactory)5 CacheException (org.apache.geode.cache.CacheException)5 IgnoredException (org.apache.geode.test.dunit.IgnoredException)5 WaitCriterion (org.apache.geode.test.dunit.WaitCriterion)5 Set (java.util.Set)4 CancelException (org.apache.geode.CancelException)4 CacheLoaderException (org.apache.geode.cache.CacheLoaderException)4