Search in sources :

Example 11 with AbstractGatewaySender

use of org.apache.geode.internal.cache.wan.AbstractGatewaySender in project geode by apache.

the class AbstractBucketRegionQueue method notifyEventProcessor.

protected void notifyEventProcessor() {
    AbstractGatewaySender sender = getPartitionedRegion().getParallelGatewaySender();
    if (sender != null) {
        AbstractGatewaySenderEventProcessor ep = sender.getEventProcessor();
        if (ep != null) {
            ConcurrentParallelGatewaySenderQueue queue = (ConcurrentParallelGatewaySenderQueue) ep.getQueue();
            if (logger.isDebugEnabled()) {
                logger.debug("notifyEventProcessor : {} event processor {} queue {}", sender, ep, queue);
            }
            queue.notifyEventProcessorIfRequired(this.getId());
        }
    }
}
Also used : ConcurrentParallelGatewaySenderQueue(org.apache.geode.internal.cache.wan.parallel.ConcurrentParallelGatewaySenderQueue) AbstractGatewaySender(org.apache.geode.internal.cache.wan.AbstractGatewaySender) AbstractGatewaySenderEventProcessor(org.apache.geode.internal.cache.wan.AbstractGatewaySenderEventProcessor)

Example 12 with AbstractGatewaySender

use of org.apache.geode.internal.cache.wan.AbstractGatewaySender in project geode by apache.

the class GemFireCacheImpl method close.

public void close(String reason, Throwable systemFailureCause, boolean keepAlive, boolean keepDS) {
    this.securityService.close();
    if (isClosed()) {
        return;
    }
    final boolean isDebugEnabled = logger.isDebugEnabled();
    synchronized (GemFireCacheImpl.class) {
        // static synchronization is necessary due to static resources
        if (isClosed()) {
            return;
        }
        /*
       * First close the ManagementService as it uses a lot of infra which will be closed by
       * cache.close()
       */
        this.system.handleResourceEvent(ResourceEvent.CACHE_REMOVE, this);
        if (this.resourceEventsListener != null) {
            this.system.removeResourceListener(this.resourceEventsListener);
            this.resourceEventsListener = null;
        }
        if (systemFailureCause != null) {
            this.forcedDisconnect = systemFailureCause instanceof ForcedDisconnectException;
            if (this.forcedDisconnect) {
                this.disconnectCause = new ForcedDisconnectException(reason);
            } else {
                this.disconnectCause = systemFailureCause;
            }
        }
        this.keepAlive = keepAlive;
        this.isClosing = true;
        logger.info(LocalizedMessage.create(LocalizedStrings.GemFireCache_0_NOW_CLOSING, this));
        // available to anyone "fishing" for a cache...
        if (GemFireCacheImpl.instance == this) {
            GemFireCacheImpl.instance = null;
        }
        // threads may be hung trying to communicate with the map locked
        if (systemFailureCause == null) {
            PartitionedRegion.clearPRIdMap();
        }
        TXStateProxy tx = null;
        try {
            if (this.transactionManager != null) {
                tx = this.transactionManager.internalSuspend();
            }
            // do this before closing regions
            this.resourceManager.close();
            try {
                this.resourceAdvisor.close();
            } catch (CancelException ignore) {
            // ignore
            }
            try {
                this.jmxAdvisor.close();
            } catch (CancelException ignore) {
            // ignore
            }
            for (GatewaySender sender : this.allGatewaySenders) {
                try {
                    sender.stop();
                    GatewaySenderAdvisor advisor = ((AbstractGatewaySender) sender).getSenderAdvisor();
                    if (advisor != null) {
                        if (isDebugEnabled) {
                            logger.debug("Stopping the GatewaySender advisor");
                        }
                        advisor.close();
                    }
                } catch (CancelException ignore) {
                }
            }
            destroyGatewaySenderLockService();
            if (this.eventThreadPool != null) {
                if (isDebugEnabled) {
                    logger.debug("{}: stopping event thread pool...", this);
                }
                this.eventThreadPool.shutdown();
            }
            /*
         * IMPORTANT: any operation during shut down that can time out (create a CancelException)
         * must be inside of this try block. If all else fails, we *must* ensure that the cache gets
         * closed!
         */
            try {
                this.stopServers();
                stopMemcachedServer();
                stopRedisServer();
                stopRestAgentServer();
                // cacheServers or gatewayHubs
                if (this.partitionedRegions != null) {
                    if (isDebugEnabled) {
                        logger.debug("{}: clearing partitioned regions...", this);
                    }
                    synchronized (this.partitionedRegions) {
                        int prSize = -this.partitionedRegions.size();
                        this.partitionedRegions.clear();
                        getCachePerfStats().incPartitionedRegions(prSize);
                    }
                }
                prepareDiskStoresForClose();
                if (GemFireCacheImpl.pdxInstance == this) {
                    GemFireCacheImpl.pdxInstance = null;
                }
                List<LocalRegion> rootRegionValues;
                synchronized (this.rootRegions) {
                    rootRegionValues = new ArrayList<>(this.rootRegions.values());
                }
                {
                    final Operation op;
                    if (this.forcedDisconnect) {
                        op = Operation.FORCED_DISCONNECT;
                    } else if (isReconnecting()) {
                        op = Operation.CACHE_RECONNECT;
                    } else {
                        op = Operation.CACHE_CLOSE;
                    }
                    LocalRegion prRoot = null;
                    for (LocalRegion lr : rootRegionValues) {
                        if (isDebugEnabled) {
                            logger.debug("{}: processing region {}", this, lr.getFullPath());
                        }
                        if (PartitionedRegionHelper.PR_ROOT_REGION_NAME.equals(lr.getName())) {
                            prRoot = lr;
                        } else {
                            if (lr.getName().contains(ParallelGatewaySenderQueue.QSTRING)) {
                                // this region will be closed internally by parent region
                                continue;
                            }
                            if (isDebugEnabled) {
                                logger.debug("{}: closing region {}...", this, lr.getFullPath());
                            }
                            try {
                                lr.handleCacheClose(op);
                            } catch (RuntimeException e) {
                                if (isDebugEnabled || !this.forcedDisconnect) {
                                    logger.warn(LocalizedMessage.create(LocalizedStrings.GemFireCache_0_ERROR_CLOSING_REGION_1, new Object[] { this, lr.getFullPath() }), e);
                                }
                            }
                        }
                    }
                    try {
                        if (isDebugEnabled) {
                            logger.debug("{}: finishing partitioned region close...", this);
                        }
                        PartitionedRegion.afterRegionsClosedByCacheClose(this);
                        if (prRoot != null) {
                            // do the PR meta root region last
                            prRoot.handleCacheClose(op);
                        }
                    } catch (CancelException e) {
                        logger.warn(LocalizedMessage.create(LocalizedStrings.GemFireCache_0_ERROR_IN_LAST_STAGE_OF_PARTITIONEDREGION_CACHE_CLOSE, this), e);
                    }
                    destroyPartitionedRegionLockService();
                }
                closeDiskStores();
                this.diskMonitor.close();
                // Close the CqService Handle.
                try {
                    if (isDebugEnabled) {
                        logger.debug("{}: closing CQ service...", this);
                    }
                    this.cqService.close();
                } catch (RuntimeException ignore) {
                    logger.info(LocalizedMessage.create(LocalizedStrings.GemFireCache_FAILED_TO_GET_THE_CQSERVICE_TO_CLOSE_DURING_CACHE_CLOSE_1));
                }
                PoolManager.close(keepAlive);
                if (isDebugEnabled) {
                    logger.debug("{}: notifying admins of close...", this);
                }
                try {
                    SystemMemberCacheEventProcessor.send(this, Operation.CACHE_CLOSE);
                } catch (CancelException ignore) {
                    if (logger.isDebugEnabled()) {
                        logger.debug("Ignored cancellation while notifying admins");
                    }
                }
                if (isDebugEnabled) {
                    logger.debug("{}: stopping destroyed entries processor...", this);
                }
                this.tombstoneService.stop();
                // NOTICE: the CloseCache message is the *last* message you can send!
                DM distributionManager = null;
                try {
                    distributionManager = this.system.getDistributionManager();
                    distributionManager.removeMembershipListener(this.transactionManager);
                } catch (CancelException ignore) {
                // distributionManager = null;
                }
                if (distributionManager != null) {
                    // Send CacheClosedMessage (and NOTHING ELSE) here
                    if (isDebugEnabled) {
                        logger.debug("{}: sending CloseCache to peers...", this);
                    }
                    Set otherMembers = distributionManager.getOtherDistributionManagerIds();
                    ReplyProcessor21 processor = new ReplyProcessor21(this.system, otherMembers);
                    CloseCacheMessage msg = new CloseCacheMessage();
                    msg.setRecipients(otherMembers);
                    msg.setProcessorId(processor.getProcessorId());
                    distributionManager.putOutgoing(msg);
                    try {
                        processor.waitForReplies();
                    } catch (InterruptedException ignore) {
                    // Thread.currentThread().interrupt(); // TODO ??? should we reset this bit later?
                    // Keep going, make best effort to shut down.
                    } catch (ReplyException ignore) {
                    // keep going
                    }
                // set closed state after telling others and getting responses
                // to avoid complications with others still in the process of
                // sending messages
                }
                // NO MORE Distributed Messaging AFTER THIS POINT!!!!
                ClientMetadataService cms = this.clientMetadataService;
                if (cms != null) {
                    cms.close();
                }
                closeHeapEvictor();
                closeOffHeapEvictor();
            } catch (CancelException ignore) {
                // make sure the disk stores get closed
                closeDiskStores();
            // NO DISTRIBUTED MESSAGING CAN BE DONE HERE!
            }
            // Close the CqService Handle.
            try {
                this.cqService.close();
            } catch (RuntimeException ignore) {
                logger.info(LocalizedMessage.create(LocalizedStrings.GemFireCache_FAILED_TO_GET_THE_CQSERVICE_TO_CLOSE_DURING_CACHE_CLOSE_2));
            }
            this.cachePerfStats.close();
            TXLockService.destroyServices();
            EventTracker.stopTrackerServices(this);
            synchronized (this.ccpTimerMutex) {
                if (this.ccpTimer != null) {
                    this.ccpTimer.cancel();
                }
            }
            this.expirationScheduler.cancel();
            // Stop QueryMonitor if running.
            if (this.queryMonitor != null) {
                this.queryMonitor.stopMonitoring();
            }
            stopDiskStoreTaskPool();
        } finally {
            // NO DISTRIBUTED MESSAGING CAN BE DONE HERE!
            if (this.transactionManager != null) {
                this.transactionManager.close();
            }
            ((DynamicRegionFactoryImpl) DynamicRegionFactory.get()).close();
            if (this.transactionManager != null) {
                this.transactionManager.internalResume(tx);
            }
            TXCommitMessage.getTracker().clearForCacheClose();
        }
        // Added to close the TransactionManager's cleanup thread
        TransactionManagerImpl.refresh();
        if (!keepDS) {
            // keepDS is used by ShutdownAll. It will override DISABLE_DISCONNECT_DS_ON_CACHE_CLOSE
            if (!this.DISABLE_DISCONNECT_DS_ON_CACHE_CLOSE) {
                this.system.disconnect();
            }
        }
        TypeRegistry.close();
        // do this late to prevent 43412
        TypeRegistry.setPdxSerializer(null);
        for (CacheLifecycleListener listener : cacheLifecycleListeners) {
            listener.cacheClosed(this);
        }
        // Fix for #49856
        SequenceLoggerImpl.signalCacheClose();
        SystemFailure.signalCacheClose();
    }
// static synchronization on GemFireCache.class
}
Also used : AbstractGatewaySender(org.apache.geode.internal.cache.wan.AbstractGatewaySender) GatewaySender(org.apache.geode.cache.wan.GatewaySender) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) HashSet(java.util.HashSet) Set(java.util.Set) ConcurrentHashSet(org.apache.geode.internal.concurrent.ConcurrentHashSet) ForcedDisconnectException(org.apache.geode.ForcedDisconnectException) ClientMetadataService(org.apache.geode.cache.client.internal.ClientMetadataService) DM(org.apache.geode.distributed.internal.DM) GatewaySenderAdvisor(org.apache.geode.internal.cache.wan.GatewaySenderAdvisor) Operation(org.apache.geode.cache.Operation) ReplyException(org.apache.geode.distributed.internal.ReplyException) SimpleExtensionPoint(org.apache.geode.internal.cache.extension.SimpleExtensionPoint) ExtensionPoint(org.apache.geode.internal.cache.extension.ExtensionPoint) CancelException(org.apache.geode.CancelException) AbstractGatewaySender(org.apache.geode.internal.cache.wan.AbstractGatewaySender) ReplyProcessor21(org.apache.geode.distributed.internal.ReplyProcessor21)

Example 13 with AbstractGatewaySender

use of org.apache.geode.internal.cache.wan.AbstractGatewaySender in project geode by apache.

the class AsyncEventQueueEvictionAndExpirationJUnitTest method getEventsNotQueuedSize.

public int getEventsNotQueuedSize(String aeqId) {
    AsyncEventQueueImpl aeq = (AsyncEventQueueImpl) cache.getAsyncEventQueue(aeqId);
    AbstractGatewaySender sender = (AbstractGatewaySender) aeq.getSender();
    return sender.getStatistics().getEventsNotQueued();
}
Also used : AsyncEventQueueImpl(org.apache.geode.cache.asyncqueue.internal.AsyncEventQueueImpl) AbstractGatewaySender(org.apache.geode.internal.cache.wan.AbstractGatewaySender)

Example 14 with AbstractGatewaySender

use of org.apache.geode.internal.cache.wan.AbstractGatewaySender in project geode by apache.

the class InitialImageOperation method getFromOne.

/**
   * Fetch an initial image from a single recipient
   * 
   * @param recipientSet list of candidates to fetch from
   * @param targetReinitialized true if candidate should wait until initialized before responding
   * @param advice
   * @param recoveredRVV recovered rvv
   * @return true if succeeded to get image
   * @throws org.apache.geode.cache.TimeoutException
   */
GIIStatus getFromOne(Set recipientSet, boolean targetReinitialized, CacheDistributionAdvisor.InitialImageAdvice advice, boolean recoveredFromDisk, RegionVersionVector recoveredRVV) throws org.apache.geode.cache.TimeoutException {
    final boolean isDebugEnabled = logger.isDebugEnabled();
    if (VMOTION_DURING_GII) {
        /**
       * TODO (ashetkar): recipientSet may contain more than one member. Ensure only the gii-source
       * member is vMotioned. The test hook may need to be placed at another point.
       */
        VMotionObserverHolder.getInstance().vMotionDuringGII(recipientSet, this.region);
    }
    // Make sure that candidates are regarded in random order
    ArrayList recipients = new ArrayList(recipientSet);
    if (this.region.isUsedForSerialGatewaySenderQueue()) {
        AbstractGatewaySender sender = this.region.getSerialGatewaySender();
        if (sender != null) {
            InternalDistributedMember primary = sender.getSenderAdvisor().advisePrimaryGatewaySender();
            if (primary != null) {
                recipients.remove(primary);
                recipients.add(0, primary);
            }
        }
    } else {
        if (recipients.size() > 1) {
            Collections.shuffle(recipients);
        }
    }
    long giiStart = this.region.getCachePerfStats().startGetInitialImage();
    InternalDistributedMember provider = null;
    for (Iterator itr = recipients.iterator(); !this.gotImage && itr.hasNext(); ) {
        // if we got a partial image from the previous recipient, then clear it
        InternalDistributedMember recipient = (InternalDistributedMember) itr.next();
        provider = recipient;
        // GII is happening and is not part of the GII result.
        if (region instanceof HARegion) {
            try {
                // if (!r.isPrimaryQueue()) {
                if (!this.requestFilterInfo(recipient)) {
                    if (isDebugEnabled) {
                        logger.debug("Failed to receive interest and CQ information from {}", recipient);
                    }
                }
            // }
            } catch (Exception ex) {
                if (!itr.hasNext()) {
                    if (isDebugEnabled) {
                        logger.info("Failed while getting interest and CQ information from {}", recipient, ex);
                    }
                }
                continue;
            }
        }
        PersistenceAdvisor persistenceAdvisor = this.region.getPersistenceAdvisor();
        if (persistenceAdvisor != null) {
            try {
                persistenceAdvisor.updateMembershipView(recipient, targetReinitialized);
                persistenceAdvisor.setInitializing(this.region.getPersistentID());
            } catch (ReplyException e) {
                if (isDebugEnabled) {
                    logger.debug("Failed to get membership view", e);
                }
                continue;
            }
        }
        final DistributionManager dm = (DistributionManager) this.region.getDistributionManager();
        boolean allowDeltaGII = true;
        if (FORCE_FULL_GII || recipient.getVersionObject().compareTo(Version.GFE_80) < 0) {
            allowDeltaGII = false;
        }
        Set keysOfUnfinishedOps = null;
        RegionVersionVector received_rvv = null;
        RegionVersionVector remote_rvv = null;
        if (this.region.concurrencyChecksEnabled && recipient.getVersionObject().compareTo(Version.GFE_80) >= 0) {
            if (internalBeforeRequestRVV != null && internalBeforeRequestRVV.getRegionName().equals(this.region.getName())) {
                internalBeforeRequestRVV.run();
            }
            // Request the RVV from the provider and discover any operations on this
            // member that have not been performed on the provider.
            //
            // It is important that this happens *before* the state flush. An operation
            // maybe unfinished because a member crashed during distribution, or because
            // it is in flight right now. If it is in flight right now, we need to make
            // sure the provider receives the latest value for the operation before the
            // GII really starts.
            received_rvv = getRVVFromProvider(dm, recipient, targetReinitialized);
            if (received_rvv == null) {
                continue;
            }
            // remote_rvv will be filled with the versions of unfinished keys
            // then if recoveredRVV is still newer than the filled remote_rvv, do fullGII
            remote_rvv = received_rvv.getCloneForTransmission();
            keysOfUnfinishedOps = processReceivedRVV(remote_rvv, recoveredRVV);
            if (internalAfterCalculatedUnfinishedOps != null && internalAfterCalculatedUnfinishedOps.getRegionName().equals(this.region.getName())) {
                internalAfterCalculatedUnfinishedOps.run();
            }
            if (keysOfUnfinishedOps == null) {
                // if got rvv, keysOfUnfinishedOps at least will be empty
                continue;
            }
        }
        Boolean inhibitFlush = (Boolean) inhibitStateFlush.get();
        if (!inhibitFlush.booleanValue() && !this.region.doesNotDistribute()) {
            if (region instanceof BucketRegionQueue) {
                // get the corresponding userPRs and do state flush on all of them
                // TODO we should be able to do this state flush with a single
                // message, but that will require changing the messaging layer,
                // which has implications for a rolling upgrade.
                Collection<BucketRegion> userPRBuckets = ((BucketRegionQueue) (this.region)).getCorrespondingUserPRBuckets();
                if (isDebugEnabled) {
                    logger.debug("The parent buckets of this shadowPR region are {}", userPRBuckets);
                }
                for (BucketRegion parentBucket : userPRBuckets) {
                    if (isDebugEnabled) {
                        logger.debug("Going to do state flush operation on the parent bucket.");
                    }
                    final StateFlushOperation sf;
                    sf = new StateFlushOperation(parentBucket);
                    final Set<InternalDistributedMember> r = new HashSet<InternalDistributedMember>();
                    r.addAll(advice.replicates);
                    r.addAll(advice.preloaded);
                    r.addAll(advice.others);
                    r.addAll(advice.empties);
                    r.addAll(advice.uninitialized);
                    int processorType = targetReinitialized ? DistributionManager.WAITING_POOL_EXECUTOR : DistributionManager.HIGH_PRIORITY_EXECUTOR;
                    try {
                        boolean success = sf.flush(r, recipient, processorType, true);
                        if (!success) {
                            continue;
                        }
                    } catch (InterruptedException ie) {
                        Thread.currentThread().interrupt();
                        region.getCancelCriterion().checkCancelInProgress(ie);
                        return GIIStatus.NO_GII;
                    }
                    if (isDebugEnabled) {
                        logger.debug("Completed state flush operation on the parent bucket.");
                    }
                }
            }
            final StateFlushOperation sf;
            sf = new StateFlushOperation(this.region);
            final Set<InternalDistributedMember> r = new HashSet<InternalDistributedMember>();
            r.addAll(advice.replicates);
            r.addAll(advice.preloaded);
            r.addAll(advice.others);
            r.addAll(advice.empties);
            r.addAll(advice.uninitialized);
            int processorType = targetReinitialized ? DistributionManager.WAITING_POOL_EXECUTOR : DistributionManager.HIGH_PRIORITY_EXECUTOR;
            try {
                boolean success = sf.flush(r, recipient, processorType, false);
                if (!success) {
                    continue;
                }
            } catch (InterruptedException ie) {
                Thread.currentThread().interrupt();
                region.getCancelCriterion().checkCancelInProgress(ie);
                this.region.getCachePerfStats().endNoGIIDone(giiStart);
                return GIIStatus.NO_GII;
            }
        }
        RequestImageMessage m = new RequestImageMessage();
        m.regionPath = this.region.getFullPath();
        m.keysOnly = false;
        m.targetReinitialized = targetReinitialized;
        m.setRecipient(recipient);
        if (this.region.concurrencyChecksEnabled) {
            if (allowDeltaGII && recoveredFromDisk) {
                if (!this.region.getDiskRegion().getRVVTrusted()) {
                    if (isDebugEnabled) {
                        logger.debug("Region {} recovered without EndGII flag, do full GII", this.region.getFullPath());
                    }
                    m.versionVector = null;
                } else if (keysOfUnfinishedOps.size() > MAXIMUM_UNFINISHED_OPERATIONS) {
                    if (isDebugEnabled) {
                        logger.debug("Region {} has {} unfinished operations, which exceeded threshold {}, do full GII instead", this.region.getFullPath(), keysOfUnfinishedOps.size(), MAXIMUM_UNFINISHED_OPERATIONS);
                    }
                    m.versionVector = null;
                } else {
                    if (recoveredRVV.isNewerThanOrCanFillExceptionsFor(remote_rvv)) {
                        m.versionVector = null;
                        if (isDebugEnabled) {
                            logger.debug("Region {}: after filled versions of unfinished keys, recovered rvv is still newer than remote rvv:{}. recovered rvv is {}. Do full GII", this.region.getFullPath(), remote_rvv, recoveredRVV);
                        }
                    } else {
                        m.versionVector = recoveredRVV;
                        m.unfinishedKeys = keysOfUnfinishedOps;
                        if (isDebugEnabled) {
                            logger.debug("Region {} recovered with EndGII flag, rvv is {}. recovered rvv is {}. Do delta GII", this.region.getFullPath(), m.versionVector, recoveredRVV);
                        }
                    }
                }
                m.checkTombstoneVersions = true;
            }
            if (received_rvv != null) {
                // pack the original RVV, then save the received one
                if (internalBeforeSavedReceivedRVV != null && internalBeforeSavedReceivedRVV.getRegionName().equals(this.region.getName())) {
                    internalBeforeSavedReceivedRVV.run();
                }
                saveReceivedRVV(received_rvv);
                if (internalAfterSavedReceivedRVV != null && internalAfterSavedReceivedRVV.getRegionName().equals(this.region.getName())) {
                    internalAfterSavedReceivedRVV.run();
                }
            }
        }
        ImageProcessor processor = new ImageProcessor(this.region.getSystem(), recipient);
        dm.acquireGIIPermitUninterruptibly();
        try {
            m.processorId = processor.getProcessorId();
            if (region.isUsedForPartitionedRegionBucket() && region.getDistributionConfig().getAckSevereAlertThreshold() > 0) {
                processor.enableSevereAlertProcessing();
                m.severeAlertEnabled = true;
            }
            // do not remove the following log statement
            logger.info(LocalizedMessage.create(LocalizedStrings.InitialImageOperation_REGION_0_REQUESTING_INITIAL_IMAGE_FROM_1, new Object[] { this.region.getName(), recipient }));
            dm.putOutgoing(m);
            this.region.cache.getCancelCriterion().checkCancelInProgress(null);
            if (internalAfterSentRequestImage != null && internalAfterSentRequestImage.getRegionName().equals(this.region.getName())) {
                internalAfterSentRequestImage.run();
            }
            try {
                processor.waitForRepliesUninterruptibly();
                // review unfinished keys and remove untouched entries
                if (this.region.getDataPolicy().withPersistence() && keysOfUnfinishedOps != null && !keysOfUnfinishedOps.isEmpty()) {
                    final DiskRegion dr = this.region.getDiskRegion();
                    assert dr != null;
                    for (Object key : keysOfUnfinishedOps) {
                        RegionEntry re = this.entries.getEntry(key);
                        if (re == null) {
                            continue;
                        }
                        if (logger.isTraceEnabled(LogMarker.GII)) {
                            logger.trace(LogMarker.GII, "Processing unfinished operation:entry={}", re);
                        }
                        DiskEntry de = (DiskEntry) re;
                        synchronized (de) {
                            DiskId id = de.getDiskId();
                            if (id != null && EntryBits.isRecoveredFromDisk(id.getUserBits())) {
                                this.region.destroyRecoveredEntry(key);
                                if (isDebugEnabled) {
                                    logger.debug("Deleted unfinished keys:key={}", key);
                                }
                            }
                        }
                    }
                }
                continue;
            } catch (InternalGemFireException ex) {
                Throwable cause = ex.getCause();
                if (cause instanceof org.apache.geode.cache.TimeoutException) {
                    throw (org.apache.geode.cache.TimeoutException) cause;
                }
                throw ex;
            } catch (ReplyException e) {
                if (!region.isDestroyed()) {
                    e.handleAsUnexpected();
                }
            } finally {
                ImageState imgState = region.getImageState();
                if (imgState.getClearRegionFlag()) {
                    // Asif : Since the operation has been completed clear flag
                    imgState.setClearRegionFlag(false, null);
                }
                // source
                if (this.gcVersions != null) {
                    region.getGemFireCache().getTombstoneService().gcTombstones(region, this.gcVersions, false);
                }
                if (this.gotImage) {
                    RegionLogger.logGII(this.region.getFullPath(), recipient, region.getDistributionManager().getDistributionManagerId(), region.getPersistentID());
                }
                if (this.gotImage) {
                    // TODO add localizedString
                    logger.info("{} is done getting image from {}. isDeltaGII is {}", this.region.getName(), recipient, this.isDeltaGII);
                } else {
                    // TODO add localizedString
                    logger.info("{} failed to get image from {}", this.region.getName(), recipient);
                }
                if (this.region.dataPolicy.withPersistence()) {
                    logger.info(LocalizedMessage.create(LocalizedStrings.InitialImageOperation_REGION_0_INITIALIZED_PERSISTENT_REGION_WITH_ID_1_FROM_2, new Object[] { this.region.getName(), this.region.getPersistentID(), recipient }));
                }
                // detection is enabled
                if (!this.gotImage) {
                    this.region.cleanUpAfterFailedGII(recoveredFromDisk);
                } else if (received_rvv != null) {
                    checkForUnrecordedOperations(recipient);
                }
            }
        } finally {
            dm.releaseGIIPermit();
            processor.cleanup();
        }
    }
    if (this.gotImage) {
        this.region.recordEventStateFromImageProvider(provider);
        this.region.getCachePerfStats().endGetInitialImage(giiStart);
        if (this.isDeltaGII) {
            this.region.getCachePerfStats().incDeltaGIICompleted();
        }
    } else {
        this.region.getCachePerfStats().endNoGIIDone(giiStart);
    }
    return reportGIIStatus();
}
Also used : PersistenceAdvisor(org.apache.geode.internal.cache.persistence.PersistenceAdvisor) TimeoutException(java.util.concurrent.TimeoutException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) DiskAccessException(org.apache.geode.cache.DiskAccessException) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) AbstractGatewaySender(org.apache.geode.internal.cache.wan.AbstractGatewaySender)

Example 15 with AbstractGatewaySender

use of org.apache.geode.internal.cache.wan.AbstractGatewaySender in project geode by apache.

the class ParallelGatewaySenderQueue method addShadowPartitionedRegionForUserPR.

public void addShadowPartitionedRegionForUserPR(PartitionedRegion userPR) {
    if (logger.isDebugEnabled()) {
        logger.debug("{} addShadowPartitionedRegionForUserPR: Attempting to create queue region: {}", this, userPR.getDisplayName());
    }
    this.sender.getLifeCycleLock().writeLock().lock();
    PartitionedRegion prQ = null;
    try {
        String regionName = userPR.getFullPath();
        // Find if there is any parent region for this userPR
        // if there is then no need to add another q for the same
        String leaderRegionName = ColocationHelper.getLeaderRegion(userPR).getFullPath();
        if (!regionName.equals(leaderRegionName)) {
            // colocation chain
            if (!this.userRegionNameToshadowPRMap.containsKey(leaderRegionName)) {
                addShadowPartitionedRegionForUserPR(ColocationHelper.getLeaderRegion(userPR));
            }
            return;
        }
        if (this.userRegionNameToshadowPRMap.containsKey(regionName))
            return;
        if (userPR.getDataPolicy().withPersistence() && !sender.isPersistenceEnabled()) {
            throw new GatewaySenderException(LocalizedStrings.ParallelGatewaySenderQueue_NON_PERSISTENT_GATEWAY_SENDER_0_CAN_NOT_BE_ATTACHED_TO_PERSISTENT_REGION_1.toLocalizedString(new Object[] { this.sender.getId(), userPR.getFullPath() }));
        }
        InternalCache cache = sender.getCache();
        boolean isAccessor = (userPR.getLocalMaxMemory() == 0);
        final String prQName = sender.getId() + QSTRING + convertPathToName(userPR.getFullPath());
        prQ = (PartitionedRegion) cache.getRegion(prQName);
        if (prQ == null) {
            // TODO:REF:Avoid deprecated apis
            AttributesFactory fact = new AttributesFactory();
            fact.setConcurrencyChecksEnabled(false);
            PartitionAttributesFactory pfact = new PartitionAttributesFactory();
            pfact.setTotalNumBuckets(userPR.getTotalNumberOfBuckets());
            pfact.setRedundantCopies(userPR.getRedundantCopies());
            pfact.setColocatedWith(regionName);
            // EITHER set localMaxMemory to 0 for accessor node
            // OR override shadowPRs default local max memory with the sender's max
            // queue memory (Fix for bug#44254)
            int localMaxMemory = isAccessor ? 0 : sender.getMaximumQueueMemory();
            pfact.setLocalMaxMemory(localMaxMemory);
            pfact.setStartupRecoveryDelay(userPR.getPartitionAttributes().getStartupRecoveryDelay());
            pfact.setRecoveryDelay(userPR.getPartitionAttributes().getRecoveryDelay());
            if (sender.isPersistenceEnabled() && !isAccessor) {
                fact.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
            }
            fact.setDiskStoreName(sender.getDiskStoreName());
            // else set it to false
            if (sender.isPersistenceEnabled())
                fact.setDiskSynchronous(sender.isDiskSynchronous());
            else {
                fact.setDiskSynchronous(false);
            }
            // allow for no overflow directory
            EvictionAttributes ea = EvictionAttributes.createLIFOMemoryAttributes(sender.getMaximumQueueMemory(), EvictionAction.OVERFLOW_TO_DISK);
            fact.setEvictionAttributes(ea);
            fact.setPartitionAttributes(pfact.create());
            final RegionAttributes ra = fact.create();
            if (logger.isDebugEnabled()) {
                logger.debug("{}: Attempting to create queue region: {}", this, prQName);
            }
            ParallelGatewaySenderQueueMetaRegion meta = metaRegionFactory.newMetataRegion(cache, prQName, ra, sender);
            try {
                prQ = (PartitionedRegion) cache.createVMRegion(prQName, ra, new InternalRegionArguments().setInternalMetaRegion(meta).setDestroyLockFlag(true).setInternalRegion(true).setSnapshotInputStream(null).setImageTarget(null));
                // at this point we should be able to assert prQ == meta;
                // TODO This should not be set on the PR but on the GatewaySender
                prQ.enableConflation(sender.isBatchConflationEnabled());
                if (isAccessor)
                    // return from here if accessor node
                    return;
                // Wait for buckets to be recovered.
                prQ.shadowPRWaitForBucketRecovery();
            } catch (IOException | ClassNotFoundException veryUnLikely) {
                logger.fatal(LocalizedMessage.create(LocalizedStrings.SingleWriteSingleReadRegionQueue_UNEXPECTED_EXCEPTION_DURING_INIT_OF_0, this.getClass()), veryUnLikely);
            }
            if (logger.isDebugEnabled()) {
                logger.debug("{}: Created queue region: {}", this, prQ);
            }
        } else {
            if (isAccessor)
                // return from here if accessor node
                return;
            // started from stop operation)
            if (// HItesh:for first parallelGatewaySenderQueue only
            this.index == 0)
                handleShadowPRExistsScenario(cache, prQ);
        }
    } finally {
        if (prQ != null) {
            this.userRegionNameToshadowPRMap.put(userPR.getFullPath(), prQ);
        }
        /*
       * Here, enqueueTempEvents need to be invoked when a sender is already running and userPR is
       * created later. When the flow comes here through start() method of sender i.e. userPR
       * already exists and sender is started later, the enqueueTempEvents is done in the start()
       * method of ParallelGatewaySender
       */
        if ((this.index == this.nDispatcher - 1) && this.sender.isRunning()) {
            ((AbstractGatewaySender) sender).enqueueTempEvents();
        }
        afterRegionAdd(userPR);
        this.sender.getLifeCycleLock().writeLock().unlock();
    }
}
Also used : EvictionAttributes(org.apache.geode.cache.EvictionAttributes) RegionAttributes(org.apache.geode.cache.RegionAttributes) GatewaySenderException(org.apache.geode.internal.cache.wan.GatewaySenderException) InternalCache(org.apache.geode.internal.cache.InternalCache) InternalRegionArguments(org.apache.geode.internal.cache.InternalRegionArguments) IOException(java.io.IOException) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) AbstractGatewaySender(org.apache.geode.internal.cache.wan.AbstractGatewaySender)

Aggregations

AbstractGatewaySender (org.apache.geode.internal.cache.wan.AbstractGatewaySender)40 GatewaySender (org.apache.geode.cache.wan.GatewaySender)23 AttributesFactory (org.apache.geode.cache.AttributesFactory)6 ConcurrentParallelGatewaySenderQueue (org.apache.geode.internal.cache.wan.parallel.ConcurrentParallelGatewaySenderQueue)6 IgnoredException (org.apache.geode.test.dunit.IgnoredException)6 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)6 Test (org.junit.Test)6 RegionQueue (org.apache.geode.internal.cache.RegionQueue)5 Properties (java.util.Properties)4 Set (java.util.Set)4 Region (org.apache.geode.cache.Region)4 GatewayEventFilter (org.apache.geode.cache.wan.GatewayEventFilter)4 GatewaySenderFactory (org.apache.geode.cache.wan.GatewaySenderFactory)4 GatewayTransportFilter (org.apache.geode.cache.wan.GatewayTransportFilter)4 MyGatewayEventFilter1 (org.apache.geode.cache30.MyGatewayEventFilter1)4 MyGatewayTransportFilter1 (org.apache.geode.cache30.MyGatewayTransportFilter1)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 AsyncEventQueueImpl (org.apache.geode.cache.asyncqueue.internal.AsyncEventQueueImpl)3 MyGatewayTransportFilter2 (org.apache.geode.cache30.MyGatewayTransportFilter2)3