Search in sources :

Example 1 with CreatePersistentRegionProcessor

use of org.apache.geode.internal.cache.persistence.CreatePersistentRegionProcessor in project geode by apache.

the class DistributedRegion method getInitialImageAndRecovery.

// TODO: cleanup getInitialImageAndRecovery
private void getInitialImageAndRecovery(InputStream snapshotInputStream, InternalDistributedMember imageSrc, InternalRegionArguments internalRegionArgs, boolean recoverFromDisk, PersistentMemberID persistentId) throws TimeoutException {
    logger.info(LocalizedMessage.create(LocalizedStrings.DistributedRegion_INITIALIZING_REGION_0, this.getName()));
    ImageState imgState = getImageState();
    imgState.init();
    boolean targetRecreated = internalRegionArgs.getRecreateFlag();
    Boolean isCBool = (Boolean) isConversion.get();
    boolean isForConversion = isCBool != null ? isCBool : false;
    if (recoverFromDisk && snapshotInputStream != null && !isForConversion) {
        throw new InternalGemFireError(LocalizedStrings.DistributedRegion_IF_LOADING_A_SNAPSHOT_THEN_SHOULD_NOT_BE_RECOVERING_ISRECOVERING_0_SNAPSHOTSTREAM_1.toLocalizedString(new Object[] { true, snapshotInputStream }));
    }
    ProfileExchangeProcessor targetProvider;
    if (this.dataPolicy.withPersistence()) {
        targetProvider = new CreatePersistentRegionProcessor(this, getPersistenceAdvisor(), recoverFromDisk);
    } else {
        // this will go in the advisor profile
        targetProvider = new CreateRegionProcessor(this);
    }
    imgState.setInRecovery(false);
    RegionVersionVector recovered_rvv = null;
    if (this.dataPolicy.withPersistence()) {
        recovered_rvv = this.getVersionVector() == null ? null : this.getVersionVector().getCloneForTransmission();
    }
    // initializeRegion will send out our profile
    targetProvider.initializeRegion();
    if (this.persistenceAdvisor != null) {
        this.persistenceAdvisor.initialize();
    }
    // remote members
    if (!isInternalRegion()) {
        if (!this.isDestroyed) {
            this.cache.getInternalResourceManager().addResourceListener(ResourceType.MEMORY, this);
        }
    }
    releaseBeforeGetInitialImageLatch();
    // allow GII to invoke test hooks. Do this just after releasing the
    // before-gii latch for bug #48962. See ConcurrentLeaveDuringGIIDUnitTest
    InitialImageOperation.beforeGetInitialImage(this);
    if (snapshotInputStream != null) {
        try {
            if (logger.isDebugEnabled()) {
                logger.debug("DistributedRegion.getInitialImageAndRecovery: About to load snapshot, isInitialized={}; {}", isInitialized(), getFullPath());
            }
            loadSnapshotDuringInitialization(snapshotInputStream);
        } catch (IOException e) {
            // TODO: change this exception?
            throw new RuntimeException(e);
        } catch (ClassNotFoundException e) {
            // TODO: change this exception?
            throw new RuntimeException(e);
        }
        cleanUpDestroyedTokensAndMarkGIIComplete(GIIStatus.NO_GII);
        return;
    }
    // No snapshot provided, use the imageTarget(s)
    // if we were given a recommended imageTarget, use that first, and
    // treat it like it is a replicate (regardless of whether it actually is
    // or not)
    InitialImageOperation iiop = new InitialImageOperation(this, this.entries);
    CacheDistributionAdvisor.InitialImageAdvice advice = null;
    boolean done = false;
    while (!done && !isDestroyed()) {
        advice = targetProvider.getInitialImageAdvice(advice);
        boolean attemptGetFromOne = // we were given a specific member
        imageSrc != null || // this is a preloaded
        this.dataPolicy.withPreloaded() && !advice.preloaded.isEmpty() || // region
        (!advice.replicates.isEmpty());
        if (attemptGetFromOne) {
            if (recoverFromDisk) {
                if (LocalRegion.ISSUE_CALLBACKS_TO_CACHE_OBSERVER) {
                    CacheObserverHolder.getInstance().afterMarkingGIIStarted();
                }
            }
            {
                // Plan A: use specified imageSrc, if specified
                if (imageSrc != null) {
                    try {
                        GIIStatus ret = iiop.getFromOne(Collections.singleton(imageSrc), targetRecreated, advice, recoverFromDisk, recovered_rvv);
                        if (GIIStatus.didGII(ret)) {
                            this.giiMissingRequiredRoles = false;
                            cleanUpDestroyedTokensAndMarkGIIComplete(ret);
                            done = true;
                            return;
                        }
                    } finally {
                        imageSrc = null;
                    }
                }
                // Plan C: use a replicate, if one exists
                GIIStatus ret = iiop.getFromOne(advice.replicates, false, advice, recoverFromDisk, recovered_rvv);
                if (GIIStatus.didGII(ret)) {
                    cleanUpDestroyedTokensAndMarkGIIComplete(ret);
                    done = true;
                    return;
                }
                // Plan D: if this is a PRELOADED region, fetch from another PRELOADED
                if (this.dataPolicy.isPreloaded()) {
                    GIIStatus ret_preload = iiop.getFromOne(advice.preloaded, false, advice, recoverFromDisk, recovered_rvv);
                    if (GIIStatus.didGII(ret_preload)) {
                        cleanUpDestroyedTokensAndMarkGIIComplete(ret_preload);
                        done = true;
                        return;
                    }
                }
            // isPreloaded
            }
            // If we got to this point, we failed in the GII. Cleanup
            // any partial image we received
            cleanUpAfterFailedGII(recoverFromDisk);
        } else // attemptGetFromOne
        {
            if (!isDestroyed()) {
                if (recoverFromDisk) {
                    logger.info(LocalizedMessage.create(LocalizedStrings.DistributedRegion_INITIALIZED_FROM_DISK, new Object[] { this.getFullPath(), persistentId, getPersistentID() }));
                    if (persistentId != null) {
                        RegionLogger.logRecovery(this.getFullPath(), persistentId, getDistributionManager().getDistributionManagerId());
                    }
                } else {
                    RegionLogger.logCreate(this.getFullPath(), getDistributionManager().getDistributionManagerId());
                    if (getPersistentID() != null) {
                        RegionLogger.logPersistence(this.getFullPath(), getDistributionManager().getDistributionManagerId(), getPersistentID());
                        logger.info(LocalizedMessage.create(LocalizedStrings.DistributedRegion_NEW_PERSISTENT_REGION_CREATED, new Object[] { this.getFullPath(), getPersistentID() }));
                    }
                }
                cleanUpDestroyedTokensAndMarkGIIComplete(GIIStatus.NO_GII);
                done = true;
                return;
            }
            break;
        }
    }
}
Also used : RegionVersionVector(org.apache.geode.internal.cache.versions.RegionVersionVector) IOException(java.io.IOException) GIIStatus(org.apache.geode.internal.cache.InitialImageOperation.GIIStatus) CreatePersistentRegionProcessor(org.apache.geode.internal.cache.persistence.CreatePersistentRegionProcessor) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) InternalGemFireError(org.apache.geode.InternalGemFireError)

Aggregations

IOException (java.io.IOException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 InternalGemFireError (org.apache.geode.InternalGemFireError)1 GIIStatus (org.apache.geode.internal.cache.InitialImageOperation.GIIStatus)1 CreatePersistentRegionProcessor (org.apache.geode.internal.cache.persistence.CreatePersistentRegionProcessor)1 RegionVersionVector (org.apache.geode.internal.cache.versions.RegionVersionVector)1