Search in sources :

Example 26 with PersistentMemberID

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

the class DistributedRegion method initialize.

/**
   * Called while NOT holding lock on parent's subregions
   * 
   * @throws IllegalStateException if region is not compatible with a region in another VM.
   */
@Override
protected void initialize(InputStream snapshotInputStream, InternalDistributedMember imageTarget, InternalRegionArguments internalRegionArgs) throws TimeoutException, IOException, ClassNotFoundException {
    Assert.assertTrue(!isInitialized());
    if (logger.isDebugEnabled()) {
        logger.debug("DistributedRegion.initialize BEGIN: {}", getFullPath());
    }
    // if we're versioning entries we need a region-level version vector
    if (this.scope.isDistributed() && this.concurrencyChecksEnabled) {
        createVersionVector();
    }
    if (this.scope.isGlobal()) {
        // create lock service eagerly now
        getLockService();
    }
    try {
        try {
            PersistentMemberID persistentMemberId = null;
            boolean recoverFromDisk = isRecoveryNeeded();
            DiskRegion dskRgn = getDiskRegion();
            if (recoverFromDisk) {
                if (logger.isDebugEnabled()) {
                    logger.debug("DistributedRegion.getInitialImageAndRecovery: Starting Recovery");
                }
                // do recovery
                dskRgn.initializeOwner(this);
                if (logger.isDebugEnabled()) {
                    logger.debug("DistributedRegion.getInitialImageAndRecovery: Finished Recovery");
                }
                persistentMemberId = dskRgn.getMyPersistentID();
            }
            // Create OQL indexes before starting GII.
            createOQLIndexes(internalRegionArgs, recoverFromDisk);
            if (getDataPolicy().withReplication() || getDataPolicy().withPreloaded()) {
                getInitialImageAndRecovery(snapshotInputStream, imageTarget, internalRegionArgs, recoverFromDisk, persistentMemberId);
            } else {
                new CreateRegionProcessor(this).initializeRegion();
                if (snapshotInputStream != null) {
                    releaseBeforeGetInitialImageLatch();
                    loadSnapshotDuringInitialization(snapshotInputStream);
                }
            }
        } catch (DiskAccessException dae) {
            this.handleDiskAccessException(dae, true);
            throw dae;
        }
        initMembershipRoles();
        this.isInitializingThread = false;
        // makes sure all latches are released if they haven't been already
        super.initialize(null, null, null);
    } finally {
        if (this.eventTracker != null) {
            this.eventTracker.setInitialized();
        }
    }
}
Also used : DiskAccessException(org.apache.geode.cache.DiskAccessException) PersistentMemberID(org.apache.geode.internal.cache.persistence.PersistentMemberID)

Example 27 with PersistentMemberID

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

the class BucketPersistenceAdvisor method recoveryDone.

public void recoveryDone(RuntimeException e) {
    this.recovering = false;
    if (!getPersistedMembers().isEmpty()) {
        ((BucketAdvisor) advisor).setHadPrimary();
    }
    // Make sure any removes that we saw during recovery are
    // applied.
    removeListener(recoveryListener);
    for (PersistentMemberID id : recoveryListener.getRemovedMembers()) {
        removeMember(id);
    }
    if (someMemberRecoveredLatch.getCount() > 0) {
        this.recoveryException = e;
        this.someMemberRecoveredLatch.countDown();
    } else if (recoveryException != null) {
        logger.fatal(LocalizedMessage.create(LocalizedStrings.BucketPersistenceAdvisor_ERROR_RECOVERYING_SECONDARY_BUCKET_0, new Object[] { proxyBucket.getPartitionedRegion().getFullPath(), proxyBucket.getBucketId() }), e);
    }
}
Also used : PersistentMemberID(org.apache.geode.internal.cache.persistence.PersistentMemberID)

Example 28 with PersistentMemberID

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

the class ShowMissingDiskStoresFunction method execute.

@Override
public void execute(FunctionContext context) {
    final Set<PersistentMemberPattern> memberMissingIDs = new HashSet<PersistentMemberPattern>();
    Set<ColocatedRegionDetails> missingColocatedRegions = new HashSet<ColocatedRegionDetails>();
    if (context == null) {
        throw new RuntimeException();
    }
    try {
        final InternalCache cache = getCache();
        if (cache != null && !cache.isClosed()) {
            final DistributedMember member = cache.getMyId();
            // Missing DiskStores
            PersistentMemberManager mm = cache.getPersistentMemberManager();
            Map<String, Set<PersistentMemberID>> waitingRegions = mm.getWaitingRegions();
            for (Set<PersistentMemberID> entry : waitingRegions.values()) {
                for (PersistentMemberID id : entry) {
                    memberMissingIDs.add(new PersistentMemberPattern(id));
                }
            }
            // Missing colocated regions
            Set<PartitionedRegion> prs = cache.getPartitionedRegions();
            for (PartitionedRegion pr : prs) {
                List<String> missingChildRegions = pr.getMissingColocatedChildren();
                for (String child : missingChildRegions) {
                    missingColocatedRegions.add(new ColocatedRegionDetails(member.getHost(), member.getName(), pr.getFullPath(), child));
                }
            }
        }
        if (memberMissingIDs.isEmpty() && missingColocatedRegions.isEmpty()) {
            context.getResultSender().lastResult(null);
        } else {
            if (!memberMissingIDs.isEmpty()) {
                if (missingColocatedRegions.isEmpty()) {
                    context.getResultSender().lastResult(memberMissingIDs);
                } else {
                    context.getResultSender().sendResult(memberMissingIDs);
                }
            }
            if (!missingColocatedRegions.isEmpty()) {
                context.getResultSender().lastResult(missingColocatedRegions);
            }
        }
    } catch (Exception e) {
        context.getResultSender().sendException(e);
    }
}
Also used : PersistentMemberPattern(org.apache.geode.internal.cache.persistence.PersistentMemberPattern) Set(java.util.Set) HashSet(java.util.HashSet) InternalCache(org.apache.geode.internal.cache.InternalCache) PersistentMemberID(org.apache.geode.internal.cache.persistence.PersistentMemberID) PersistentMemberManager(org.apache.geode.internal.cache.persistence.PersistentMemberManager) ColocatedRegionDetails(org.apache.geode.internal.cache.partitioned.ColocatedRegionDetails) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) DistributedMember(org.apache.geode.distributed.DistributedMember) HashSet(java.util.HashSet)

Example 29 with PersistentMemberID

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

the class AbstractDiskRegion method addMyInitializingPMID.

public PersistentMemberID addMyInitializingPMID(PersistentMemberID pmid) {
    PersistentMemberID result = this.myInitializingId;
    this.myInitializingId = pmid;
    if (result != null) {
        this.myInitializedId = result;
    }
    return result;
}
Also used : PersistentMemberID(org.apache.geode.internal.cache.persistence.PersistentMemberID)

Example 30 with PersistentMemberID

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

the class PRHARedundancyProvider method endBucketCreationLocally.

public void endBucketCreationLocally(int bucketId, InternalDistributedMember newPrimary) {
    // has been destroyed.
    if (prRegion.getCancelCriterion().isCancelInProgress() || prRegion.isDestroyed()) {
        return;
    }
    if (logger.isDebugEnabled()) {
        logger.debug("endBucketCreationLocally: for region {} bucketId={} new primary: {}", this.prRegion.getFullPath(), bucketId, newPrimary);
    }
    BucketAdvisor bucketAdvisor = prRegion.getRegionAdvisor().getBucketAdvisor(bucketId);
    final ProxyBucketRegion proxyBucketRegion = bucketAdvisor.getProxyBucketRegion();
    BucketPersistenceAdvisor persistentAdvisor = proxyBucketRegion.getPersistenceAdvisor();
    // on the persistent advisor and marking a bucket as initialized twice.
    synchronized (proxyBucketRegion) {
        if (persistentAdvisor != null) {
            BucketRegion realBucket = proxyBucketRegion.getCreatedBucketRegion();
            if (realBucket != null) {
                PersistentMemberID persistentID = realBucket.getPersistentID();
                persistentAdvisor.endBucketCreation(persistentID);
            }
        }
        // We've received an endBucketCreationMessage, but the primary
        // may not have. So now we wait for the chosen member to become
        // primary.
        bucketAdvisor.setPrimaryElector(newPrimary);
        if (prRegion.getGemFireCache().getMyId().equals(newPrimary)) {
            // If we're the choosen primary, volunteer for primary now
            if (bucketAdvisor.isHosting()) {
                bucketAdvisor.clearPrimaryElector();
                bucketAdvisor.volunteerForPrimary();
            }
        } else {
            // that case, volunteer for primary now.
            if (!bucketAdvisor.adviseInitialized().contains(newPrimary)) {
                bucketAdvisor.clearPrimaryElector();
                bucketAdvisor.volunteerForPrimary();
            }
            // clear the primary elector field.
            if (bucketAdvisor.getHadPrimary()) {
                bucketAdvisor.clearPrimaryElector();
                bucketAdvisor.volunteerForPrimary();
            }
        }
    }
    // send out a profile update to indicate the persistence is initialized, if needed.
    if (persistentAdvisor != null) {
        bucketAdvisor.endBucketCreation();
    }
    List<PartitionedRegion> colocatedWithList = ColocationHelper.getColocatedChildRegions(prRegion);
    for (PartitionedRegion child : colocatedWithList) {
        if (child.getRegionAdvisor().isBucketLocal(bucketId)) {
            child.getRedundancyProvider().endBucketCreationLocally(bucketId, newPrimary);
        }
    }
}
Also used : PersistentMemberID(org.apache.geode.internal.cache.persistence.PersistentMemberID)

Aggregations

PersistentMemberID (org.apache.geode.internal.cache.persistence.PersistentMemberID)35 Test (org.junit.Test)14 HashSet (java.util.HashSet)10 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)8 Set (java.util.Set)7 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)7 HashMap (java.util.HashMap)6 UnitTest (org.apache.geode.test.junit.categories.UnitTest)6 PersistentMemberPattern (org.apache.geode.internal.cache.persistence.PersistentMemberPattern)5 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 PersistentMemberManager (org.apache.geode.internal.cache.persistence.PersistentMemberManager)4 File (java.io.File)3 DiskAccessException (org.apache.geode.cache.DiskAccessException)3 DiskStoreID (org.apache.geode.internal.cache.persistence.DiskStoreID)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 DataInputStream (java.io.DataInputStream)2 Entry (java.util.Map.Entry)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 CancelException (org.apache.geode.CancelException)2