Search in sources :

Example 21 with PersistentMemberID

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

the class DiskInitFile method dumpPRMetaData.

/**
   * Dump the metadata for a partitioned region, optionally dumping the meta data for individual
   * buckets.
   */
private void dumpPRMetaData(boolean showBuckets, List<PlaceHolderDiskRegion> regions) {
    StringBuilder msg = new StringBuilder(regions.get(0).getPrName());
    regions.get(0).dumpCommonAttributes(msg);
    if (showBuckets) {
        for (PlaceHolderDiskRegion region : regions) {
            msg.append("\n");
            msg.append("\n");
            msg.append(region.getName());
            region.dumpPersistentView(msg);
        }
    } else {
        Map<DiskStoreID, String> online = new HashMap<DiskStoreID, String>();
        Map<DiskStoreID, String> offline = new HashMap<DiskStoreID, String>();
        Map<DiskStoreID, String> equal = new HashMap<DiskStoreID, String>();
        for (PlaceHolderDiskRegion region : regions) {
            for (PersistentMemberID mem : region.getOnlineMembers()) {
                online.put(mem.diskStoreId, mem.host + ":" + mem.directory);
            }
            for (PersistentMemberID mem : region.getOfflineMembers()) {
                offline.put(mem.diskStoreId, mem.host + ":" + mem.directory);
            }
            for (PersistentMemberID mem : region.getOfflineAndEqualMembers()) {
                equal.put(mem.diskStoreId, mem.host + ":" + mem.directory);
            }
        }
        msg.append("\n\tonlineMembers:");
        for (Map.Entry<DiskStoreID, String> id : online.entrySet()) {
            msg.append("\n\t\t").append(id.getKey()).append(" ").append(id.getValue());
        }
        msg.append("\n\tofflineMembers:");
        for (Map.Entry<DiskStoreID, String> id : offline.entrySet()) {
            msg.append("\n\t\t").append(id.getKey()).append(" ").append(id.getValue());
        }
        msg.append("\n\tequalsMembers:");
        for (Map.Entry<DiskStoreID, String> id : equal.entrySet()) {
            msg.append("\n\t\t").append(id.getKey()).append(" ").append(id.getValue());
        }
    }
    System.out.println(msg);
}
Also used : Int2ObjectOpenHashMap(it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) DiskStoreID(org.apache.geode.internal.cache.persistence.DiskStoreID) Map(java.util.Map) Int2ObjectOpenHashMap(it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Int2ObjectMap(it.unimi.dsi.fastutil.ints.Int2ObjectMap) PersistentMemberID(org.apache.geode.internal.cache.persistence.PersistentMemberID)

Example 22 with PersistentMemberID

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

the class DiskInitFile method writeLiveData.

private void writeLiveData(DiskRegionView drv) {
    writeIFRecord(IFREC_CREATE_REGION_ID, drv, drv.getName());
    writeRegionConfig(drv);
    if (drv.wasAboutToDestroy()) {
        writeIFRecord(IFREC_BEGIN_DESTROY_REGION_ID, drv);
    } else if (drv.wasAboutToDestroyDataStorage()) {
        writeIFRecord(IFREC_BEGIN_PARTIAL_DESTROY_REGION_ID, drv);
    }
    if (drv.getClearOplogEntryId() != DiskStoreImpl.INVALID_ID) {
        writeIFRecord(IFREC_CLEAR_REGION_ID, drv, drv.getClearOplogEntryId());
        this.ifTotalRecordCount++;
        this.ifLiveRecordCount++;
    }
    if (drv.getClearRVV() != null) {
        writeClearRecord(drv, drv.getClearRVV());
    }
    for (PersistentMemberID pmid : drv.getOnlineMembers()) {
        writePMIDRecord(IFREC_ONLINE_MEMBER_ID, drv, pmid, true);
    }
    for (PersistentMemberID pmid : drv.getOfflineMembers()) {
        writePMIDRecord(IFREC_OFFLINE_MEMBER_ID, drv, pmid, true);
    }
    for (PersistentMemberID pmid : drv.getOfflineAndEqualMembers()) {
        writePMIDRecord(IFREC_OFFLINE_AND_EQUAL_MEMBER_ID, drv, pmid, true);
    }
    if (drv.getMyPersistentID() != null) {
        writePMIDRecord(IFREC_MY_MEMBER_INITIALIZING_ID, drv, drv.getMyPersistentID(), true);
        writeIFRecord(IFREC_MY_MEMBER_INITIALIZED_ID, drv);
    }
    if (drv.getMyInitializingID() != null) {
        writePMIDRecord(IFREC_MY_MEMBER_INITIALIZING_ID, drv, drv.getMyInitializingID(), true);
    }
}
Also used : PersistentMemberID(org.apache.geode.internal.cache.persistence.PersistentMemberID)

Example 23 with PersistentMemberID

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

the class ProxyBucketRegion method checkBucketRedundancyBeforeGrab.

public boolean checkBucketRedundancyBeforeGrab(InternalDistributedMember moveSource, boolean replaceOfflineData) {
    int redundancy = getBucketAdvisor().getBucketRedundancy();
    // Skip any checks if this is a colocated bucket. We need to create
    // the colocated bucket if we managed to create the parent bucket. There are
    // race conditions where the parent region may know that a member is no longer
    // hosting the bucket, but the child region doesn't know that yet.
    PartitionedRegion colocatedRegion = ColocationHelper.getColocatedRegion(this.partitionedRegion);
    if (colocatedRegion != null) {
        return true;
    }
    // sure the bucket isn't completely offline
    if (!replaceOfflineData || redundancy == -1) {
        BucketPersistenceAdvisor persistAdvisor = getPersistenceAdvisor();
        if (persistAdvisor != null) {
            // any offline buckets should be empty
            if (!persistAdvisor.wasHosting() && advisor.getHadPrimary()) {
                final PersistentMembershipView membershipView = persistAdvisor.getMembershipView();
                if (membershipView == null) {
                    // Refuse to create the bucket if that is the case.
                    if (logger.isDebugEnabled()) {
                        logger.debug("grabFreeBucket: Can't create bucket because persistence is not yet initialized {}{}{}", this.partitionedRegion.getPRId(), PartitionedRegion.BUCKET_ID_SEPARATOR, bid);
                    }
                    return false;
                }
                Set<PersistentMemberID> offlineMembers = membershipView.getOfflineMembers();
                if (logger.isDebugEnabled()) {
                    logger.debug("We didn't host the bucket. Checking redundancy level before creating the bucket. Redundancy={} offline members={}", redundancy, offlineMembers);
                }
                if (offlineMembers != null && !offlineMembers.isEmpty() && redundancy == -1) {
                    // If there are offline members, and no online members, throw
                    // an exception indicating that we can't create the bucket.
                    String message = LocalizedStrings.PartitionedRegionDataStore_DATA_OFFLINE_MESSAGE.toLocalizedString(partitionedRegion.getFullPath(), bid, offlineMembers);
                    throw new PartitionOfflineException((Set) offlineMembers, message);
                } else {
                    // an extra copy of the bucket.
                    if (offlineMembers != null) {
                        redundancy += offlineMembers.size();
                    }
                }
            }
        }
    }
    if (moveSource == null) {
        if (redundancy >= this.partitionedRegion.getRedundantCopies()) {
            if (logger.isDebugEnabled()) {
                logger.debug("grabFreeBucket: Bucket already meets redundancy level bucketId={}{}{}", this.partitionedRegion.getPRId(), PartitionedRegion.BUCKET_ID_SEPARATOR, bid);
            }
            return false;
        }
    }
    // is a bucket move, we allow the source to be on the same host.
    if (!PartitionedRegionBucketMgmtHelper.bucketIsAllowedOnThisHost(this, moveSource)) {
        if (logger.isDebugEnabled()) {
            logger.debug("grabFreeBucket: Bucket can't be recovered because we're enforcing that the bucket host must be unique {}{}{}", this.partitionedRegion.getPRId(), PartitionedRegion.BUCKET_ID_SEPARATOR, bid);
        }
        return false;
    }
    return true;
}
Also used : PartitionOfflineException(org.apache.geode.cache.persistence.PartitionOfflineException) PersistentMembershipView(org.apache.geode.internal.cache.persistence.PersistentMembershipView) PersistentMemberID(org.apache.geode.internal.cache.persistence.PersistentMemberID)

Example 24 with PersistentMemberID

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

the class OfflineMemberDetailsImpl method fromData.

public void fromData(DataInput in) throws IOException, ClassNotFoundException {
    int offlineMembersLength = in.readInt();
    this.offlineMembers = new Set[offlineMembersLength];
    for (int i = 0; i < offlineMembersLength; i++) {
        int setSize = in.readInt();
        Set<PersistentMemberID> set = new HashSet<PersistentMemberID>(setSize);
        for (int j = 0; j < setSize; j++) {
            PersistentMemberID id = new PersistentMemberID();
            InternalDataSerializer.invokeFromData(id, in);
            set.add(id);
        }
        this.offlineMembers[i] = set;
    }
}
Also used : HashSet(java.util.HashSet) PersistentMemberID(org.apache.geode.internal.cache.persistence.PersistentMemberID)

Example 25 with PersistentMemberID

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

the class DistributedCacheOperation method handleClosedMembers.

private void handleClosedMembers(Set<InternalDistributedMember> closedMembers, Map<InternalDistributedMember, PersistentMemberID> persistentIds) {
    if (persistentIds == null) {
        return;
    }
    for (InternalDistributedMember member : closedMembers) {
        PersistentMemberID persistentId = persistentIds.get(member);
        if (persistentId != null) {
            // Fix for bug 42142 - In order for recovery to work,
            // we must either
            // 1) persistent the region operation successfully on the peer
            // 2) record that the peer is offline
            // or
            // 3) fail the operation
            // if we have started to shutdown, we don't want to mark the peer
            // as offline, or we will think we have newer data when in fact we don't
            getRegion().getCancelCriterion().checkCancelInProgress(null);
            // Otherwise, mark the peer as offline, because it didn't complete
            // the operation.
            getRegion().getPersistenceAdvisor().markMemberOffline(member, persistentId);
        }
    }
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) 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