Search in sources :

Example 1 with FPRDirector

use of org.apache.geode.internal.cache.partitioned.rebalance.FPRDirector in project geode by apache.

the class PRHARedundancyProvider method scheduleRedundancyRecovery.

/**
   * Schedule a task to perform redundancy recovery for a new node or for the node departed.
   */
public void scheduleRedundancyRecovery(Object failedMemId) {
    final boolean isStartup = failedMemId == null ? true : false;
    final InternalCache cache = this.prRegion.getCache();
    final int redundantCopies = PRHARedundancyProvider.this.prRegion.getRedundantCopies();
    final long delay;
    final boolean movePrimaries;
    if (isStartup) {
        delay = this.prRegion.getPartitionAttributes().getStartupRecoveryDelay();
        movePrimaries = !Boolean.getBoolean(DistributionConfig.GEMFIRE_PREFIX + "DISABLE_MOVE_PRIMARIES_ON_STARTUP");
    } else {
        delay = this.prRegion.getPartitionAttributes().getRecoveryDelay();
        movePrimaries = false;
    }
    final boolean requiresRedundancyRecovery = delay >= 0;
    if (!requiresRedundancyRecovery) {
        return;
    }
    if (!PRHARedundancyProvider.this.prRegion.isDataStore()) {
        return;
    }
    Runnable task = new RecoveryRunnable(this) {

        @Override
        public void run2() {
            try {
                final boolean isFixedPartitionedRegion = PRHARedundancyProvider.this.prRegion.isFixedPartitionedRegion();
                // Fix for 43582 - always replace offline data for fixed partitioned
                // regions - this guarantees we create the buckets we are supposed to
                // create on this node.
                boolean replaceOfflineData = isFixedPartitionedRegion || !isStartup;
                RebalanceDirector director;
                if (isFixedPartitionedRegion) {
                    director = new FPRDirector(true, movePrimaries);
                } else {
                    director = new CompositeDirector(true, true, false, movePrimaries);
                }
                final PartitionedRegionRebalanceOp rebalance = new PartitionedRegionRebalanceOp(PRHARedundancyProvider.this.prRegion, false, director, replaceOfflineData, false);
                long start = PRHARedundancyProvider.this.prRegion.getPrStats().startRecovery();
                if (isFixedPartitionedRegion) {
                    rebalance.executeFPA();
                } else {
                    rebalance.execute();
                }
                PRHARedundancyProvider.this.prRegion.getPrStats().endRecovery(start);
                PRHARedundancyProvider.this.recoveryFuture = null;
            } catch (CancelException e) {
                logger.debug("Cache closed while recovery in progress");
            } catch (RegionDestroyedException e) {
                logger.debug("Region destroyed while recovery in progress");
            } catch (Exception e) {
                logger.error(LocalizedMessage.create(LocalizedStrings.PRHARedundancyProvider_UNEXPECTED_EXCEPTION_DURING_BUCKET_RECOVERY), e);
            }
        }
    };
    synchronized (this.shutdownLock) {
        // possible fix for bug 41094
        if (!this.shutdown) {
            try {
                if (logger.isDebugEnabled()) {
                    if (isStartup) {
                        logger.debug(this.prRegion + " scheduling redundancy recovery in {} ms", delay);
                    } else {
                        logger.debug("prRegion scheduling redundancy recovery after departure/crash/error in {} in {} ms", failedMemId, delay);
                    }
                }
                recoveryFuture = this.recoveryExecutor.schedule(task, delay, TimeUnit.MILLISECONDS);
            } catch (RejectedExecutionException e) {
            // ok, the executor is shutting down.
            }
        }
    }
}
Also used : RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) CompositeDirector(org.apache.geode.internal.cache.partitioned.rebalance.CompositeDirector) PartitionedRegionStorageException(org.apache.geode.cache.PartitionedRegionStorageException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) CacheClosedException(org.apache.geode.cache.CacheClosedException) CancelException(org.apache.geode.CancelException) PartitionOfflineException(org.apache.geode.cache.persistence.PartitionOfflineException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) RebalanceDirector(org.apache.geode.internal.cache.partitioned.rebalance.RebalanceDirector) FPRDirector(org.apache.geode.internal.cache.partitioned.rebalance.FPRDirector) CancelException(org.apache.geode.CancelException)

Aggregations

RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 CancelException (org.apache.geode.CancelException)1 CacheClosedException (org.apache.geode.cache.CacheClosedException)1 PartitionedRegionStorageException (org.apache.geode.cache.PartitionedRegionStorageException)1 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)1 PartitionOfflineException (org.apache.geode.cache.persistence.PartitionOfflineException)1 CompositeDirector (org.apache.geode.internal.cache.partitioned.rebalance.CompositeDirector)1 FPRDirector (org.apache.geode.internal.cache.partitioned.rebalance.FPRDirector)1 RebalanceDirector (org.apache.geode.internal.cache.partitioned.rebalance.RebalanceDirector)1