use of org.apache.geode.internal.cache.partitioned.rebalance.RebalanceDirector 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.
}
}
}
}
Aggregations