Search in sources :

Example 31 with PersistentMemberID

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

the class DistributionAdvisor method syncForCrashedMember.

/** perform a delta-GII for the given lost member */
public void syncForCrashedMember(final InternalDistributedMember id, final Profile profile) {
    final DistributedRegion dr = getRegionForDeltaGII();
    if (dr == null) {
        return;
    }
    final boolean isDebugEnabled = logger.isDebugEnabled();
    if (isDebugEnabled) {
        logger.debug("da.syncForCrashedMember will sync region in waiting thread pool: {}", dr);
    }
    dr.getDistributionManager().getWaitingThreadPool().execute(new Runnable() {

        // bug #49601 - don't synchronize until GII has been performed
        public void run() {
            while (!dr.isInitialized()) {
                if (dr.isDestroyed()) {
                    return;
                } else {
                    try {
                        if (isDebugEnabled) {
                            logger.debug("da.syncForCrashedMember waiting for region to finish initializing: {}", dr);
                        }
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        return;
                    }
                }
            }
            CacheProfile cp = (CacheProfile) profile;
            PersistentMemberID persistentId = cp.persistentID;
            if (dr.getDataPolicy().withPersistence() && persistentId == null) {
                // a persistent member.
                if (isDebugEnabled) {
                    logger.debug("da.syncForCrashedMember skipping sync because crashed member is not persistent: {}", id);
                }
                return;
            }
            VersionSource lostVersionID;
            if (persistentId != null) {
                lostVersionID = persistentId.getVersionMember();
            } else {
                lostVersionID = id;
            }
            dr.synchronizeForLostMember(id, lostVersionID);
        }
    });
}
Also used : CacheProfile(org.apache.geode.internal.cache.CacheDistributionAdvisor.CacheProfile) VersionSource(org.apache.geode.internal.cache.versions.VersionSource) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) PersistentMemberID(org.apache.geode.internal.cache.persistence.PersistentMemberID)

Example 32 with PersistentMemberID

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

the class PartitionedRegionLoadModel method addRegion.

/**
   * Add a region to the model. All regions that are added are assumed to be colocated. The first
   * region added to the model should be the parent region. The parent region is expected to have at
   * least as many members as child regions; it may have more. If the parent has more members than
   * child regions those members will be considered invalid.
   * 
   * @param region
   * @param memberDetailSet A set of details about each member.
   * @param offlineDetails
   */
public void addRegion(String region, Collection<? extends InternalPartitionDetails> memberDetailSet, OfflineMemberDetails offlineDetails, boolean enforceLocalMaxMemory) {
    this.allColocatedRegions.add(region);
    // build up a list of members and an array of buckets for this
    // region. Each bucket has a reference to all of the members
    // that host it and each member has a reference to all of the buckets
    // it hosts
    Map<InternalDistributedMember, Member> regionMember = new HashMap<InternalDistributedMember, Member>();
    Bucket[] regionBuckets = new Bucket[this.buckets.length];
    for (InternalPartitionDetails memberDetails : memberDetailSet) {
        InternalDistributedMember memberId = (InternalDistributedMember) memberDetails.getDistributedMember();
        boolean isCritical = criticalMembers.contains(memberId);
        Member member = new Member(memberId, memberDetails.getPRLoad().getWeight(), memberDetails.getConfiguredMaxMemory(), isCritical, enforceLocalMaxMemory);
        regionMember.put(memberId, member);
        PRLoad load = memberDetails.getPRLoad();
        for (int i = 0; i < regionBuckets.length; i++) {
            if (load.getReadLoad(i) > 0) {
                Bucket bucket = regionBuckets[i];
                if (bucket == null) {
                    Set<PersistentMemberID> offlineMembers = offlineDetails.getOfflineMembers(i);
                    bucket = new Bucket(i, load.getReadLoad(i), memberDetails.getBucketSize(i), offlineMembers);
                    regionBuckets[i] = bucket;
                }
                bucket.addMember(member);
                if (load.getWriteLoad(i) > 0) {
                    if (bucket.getPrimary() == null) {
                        bucket.setPrimary(member, load.getWriteLoad(i));
                    } else if (!bucket.getPrimary().equals(member)) {
                        bucket.setPrimary(INVALID_MEMBER, 1);
                    }
                }
            }
        }
    }
    // regions
    for (Member member : regionMember.values()) {
        InternalDistributedMember memberId = member.getDistributedMember();
        MemberRollup memberSum = this.members.get(memberId);
        boolean isCritical = criticalMembers.contains(memberId);
        if (memberSum == null) {
            memberSum = new MemberRollup(memberId, isCritical, enforceLocalMaxMemory);
            this.members.put(memberId, memberSum);
        }
        memberSum.addColocatedMember(region, member);
    }
    // regions and buckets
    for (int i = 0; i < this.buckets.length; i++) {
        if (regionBuckets[i] == null) {
            // do nothing, this bucket is not hosted for this region.
            // [sumedh] remove from buckets array too to be consistent since
            // this method will be invoked repeatedly for all colocated regions,
            // and then we may miss some colocated regions for a bucket leading
            // to all kinds of issues later
            this.buckets[i] = null;
            continue;
        }
        if (this.buckets[i] == null) {
            // If this is the first region we have seen that is hosting this bucket, create a bucket
            // rollup
            this.buckets[i] = new BucketRollup(i);
        }
        // Add all of the members hosting the bucket to the rollup
        for (Member member : regionBuckets[i].getMembersHosting()) {
            InternalDistributedMember memberId = member.getDistributedMember();
            this.buckets[i].addMember(this.members.get(memberId));
        }
        // set the primary for the rollup
        if (regionBuckets[i].getPrimary() != null) {
            if (this.buckets[i].getPrimary() == null) {
                InternalDistributedMember memberId = regionBuckets[i].getPrimary().getDistributedMember();
                this.buckets[i].setPrimary(this.members.get(memberId), 0);
            } else {
                if (!(this.buckets[i].getPrimary() == INVALID_MEMBER)) {
                    if (!this.buckets[i].getPrimary().getDistributedMember().equals(regionBuckets[i].getPrimary().getDistributedMember())) {
                        if (logger.isDebugEnabled()) {
                            logger.debug("PartitionedRegionLoadModel - Setting bucket {} to INVALID because it is the primary on two members.This could just be a race in the collocation of data. member1={} member2={}", this.buckets[i], this.buckets[i].getPrimary(), regionBuckets[i].getPrimary());
                        }
                        this.buckets[i].setPrimary(INVALID_MEMBER, 0);
                    }
                }
            }
        }
        this.buckets[i].addColocatedBucket(region, regionBuckets[i]);
    }
    // If any members don't have this new region, remove them.
    for (Iterator<Entry<InternalDistributedMember, MemberRollup>> itr = members.entrySet().iterator(); itr.hasNext(); ) {
        MemberRollup memberRollup = itr.next().getValue();
        if (!memberRollup.getColocatedMembers().keySet().equals(this.allColocatedRegions)) {
            itr.remove();
            if (logger.isDebugEnabled()) {
                logger.debug("PartitionedRegionLoadModel - removing member {} from the consideration because it doesn't have all of the colocated regions. Expected={}, was={}", memberRollup, allColocatedRegions, memberRollup.getColocatedMembers());
            }
            // This state should never happen
            if (!memberRollup.getBuckets().isEmpty()) {
                logger.warn(LocalizedMessage.create(LocalizedStrings.PartitionedRegionLoadModel_INCOMPLETE_COLOCATION, new Object[] { memberRollup, this.allColocatedRegions, memberRollup.getColocatedMembers().keySet(), memberRollup.getBuckets() }));
            }
            for (Bucket bucket : new HashSet<Bucket>(memberRollup.getBuckets())) {
                bucket.removeMember(memberRollup);
            }
        }
    }
}
Also used : PRLoad(org.apache.geode.internal.cache.partitioned.PRLoad) HashMap(java.util.HashMap) PersistentMemberID(org.apache.geode.internal.cache.persistence.PersistentMemberID) Entry(java.util.Map.Entry) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) InternalPartitionDetails(org.apache.geode.internal.cache.partitioned.InternalPartitionDetails) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) HashSet(java.util.HashSet)

Example 33 with PersistentMemberID

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

the class DiskManagementDUnitTest method testMissingMembers.

/**
   * Checks the test case of missing disks and revoking them through MemberMXBean interfaces
   */
@Test
public void testMissingMembers() throws Exception {
    VM memberVM1 = this.memberVMs[0];
    VM memberVM2 = this.memberVMs[1];
    createPersistentRegion(memberVM1);
    createPersistentRegion(memberVM2);
    putAnEntry(memberVM1);
    this.managerVM.invoke("checkForMissingDiskStores", () -> {
        ManagementService service = this.managementTestRule.getManagementService();
        DistributedSystemMXBean distributedSystemMXBean = service.getDistributedSystemMXBean();
        PersistentMemberDetails[] missingDiskStores = distributedSystemMXBean.listMissingDiskStores();
        assertThat(missingDiskStores).isNull();
    });
    closeRegion(memberVM1);
    updateTheEntry(memberVM2, "C");
    closeRegion(memberVM2);
    AsyncInvocation creatingPersistentRegionAsync = createPersistentRegionAsync(memberVM1);
    memberVM1.invoke(() -> await().until(() -> {
        GemFireCacheImpl cache = (GemFireCacheImpl) this.managementTestRule.getCache();
        PersistentMemberManager persistentMemberManager = cache.getPersistentMemberManager();
        Map<String, Set<PersistentMemberID>> regions = persistentMemberManager.getWaitingRegions();
        return !regions.isEmpty();
    }));
    assertThat(creatingPersistentRegionAsync.isAlive()).isTrue();
    this.managerVM.invoke("revokeMissingDiskStore", () -> {
        ManagementService service = this.managementTestRule.getManagementService();
        DistributedSystemMXBean bean = service.getDistributedSystemMXBean();
        PersistentMemberDetails[] missingDiskStores = bean.listMissingDiskStores();
        assertThat(missingDiskStores).isNotNull().hasSize(1);
        assertThat(bean.revokeMissingDiskStores(missingDiskStores[0].getDiskStoreId())).isTrue();
    });
    await(creatingPersistentRegionAsync);
    verifyRecoveryStats(memberVM1, true);
    // Check to make sure we recovered the old value of the entry.
    memberVM1.invoke("check for the entry", () -> {
        Cache cache = this.managementTestRule.getCache();
        Region region = cache.getRegion(REGION_NAME);
        assertThat(region.get("A")).isEqualTo("B");
    });
}
Also used : PersistentMemberManager(org.apache.geode.internal.cache.persistence.PersistentMemberManager) SystemManagementService(org.apache.geode.management.internal.SystemManagementService) VM(org.apache.geode.test.dunit.VM) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) Region(org.apache.geode.cache.Region) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) Map(java.util.Map) PersistentMemberID(org.apache.geode.internal.cache.persistence.PersistentMemberID) Cache(org.apache.geode.cache.Cache) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 34 with PersistentMemberID

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

the class ShowMissingDiskStoresFunctionJUnitTest method testExecuteReturnsMissingDiskStores.

@Test
public void testExecuteReturnsMissingDiskStores() throws Throwable {
    ShowMissingDiskStoresFunction smdsFunc = new ShowMissingDiskStoresFunction();
    List<?> results = null;
    when(cache.getPersistentMemberManager()).thenReturn(memberManager);
    // Fake missing disk-stores
    Set<PersistentMemberID> regions1 = new HashSet<PersistentMemberID>();
    regions1.add(new PersistentMemberID(new DiskStoreID(), InetAddress.getLocalHost(), "/diskStore1", 1L, (short) 1));
    regions1.add(new PersistentMemberID(new DiskStoreID(), InetAddress.getLocalHost(), "/diskStore2", 2L, (short) 2));
    Map<String, Set<PersistentMemberID>> mapMember1 = new HashMap<String, Set<PersistentMemberID>>();
    ;
    mapMember1.put("member1", regions1);
    when(memberManager.getWaitingRegions()).thenReturn(mapMember1);
    smdsFunc.execute(context);
    results = resultSender.getResults();
    assertNotNull(results);
    assertEquals(1, results.size());
    Set<?> detailSet = (Set<?>) results.get(0);
    assertEquals(2, detailSet.toArray().length);
    assertTrue(detailSet.toArray()[0] instanceof PersistentMemberPattern);
    assertTrue(detailSet.toArray()[1] instanceof PersistentMemberPattern);
    // Results are not sorted so verify results in either order
    if (((PersistentMemberPattern) detailSet.toArray()[0]).getDirectory().equals("/diskStore1")) {
        assertEquals("/diskStore2", ((PersistentMemberPattern) detailSet.toArray()[1]).getDirectory());
    } else if (((PersistentMemberPattern) detailSet.toArray()[0]).getDirectory().equals("/diskStore2")) {
        assertEquals("/diskStore1", ((PersistentMemberPattern) detailSet.toArray()[1]).getDirectory());
    } else {
        fail("Incorrect missing colocated region results");
    }
}
Also used : PersistentMemberPattern(org.apache.geode.internal.cache.persistence.PersistentMemberPattern) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) DiskStoreID(org.apache.geode.internal.cache.persistence.DiskStoreID) HashSet(java.util.HashSet) PersistentMemberID(org.apache.geode.internal.cache.persistence.PersistentMemberID) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 35 with PersistentMemberID

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

the class ShowMissingDiskStoresFunctionJUnitTest method testExecuteReturnsMissingStoresAndRegions.

@Test
public void testExecuteReturnsMissingStoresAndRegions() throws Throwable {
    ShowMissingDiskStoresFunction smdsFunc = new ShowMissingDiskStoresFunction();
    List<?> results = null;
    when(cache.getPersistentMemberManager()).thenReturn(memberManager);
    // Fake missing disk-stores
    Set<PersistentMemberID> regions1 = new HashSet<PersistentMemberID>();
    regions1.add(new PersistentMemberID(new DiskStoreID(), InetAddress.getLocalHost(), "/diskStore1", 1L, (short) 1));
    regions1.add(new PersistentMemberID(new DiskStoreID(), InetAddress.getLocalHost(), "/diskStore2", 2L, (short) 2));
    Map<String, Set<PersistentMemberID>> mapMember1 = new HashMap<String, Set<PersistentMemberID>>();
    ;
    mapMember1.put("member1", regions1);
    when(memberManager.getWaitingRegions()).thenReturn(mapMember1);
    // Fake missing colocated regions
    Set<PartitionedRegion> prs = new HashSet<PartitionedRegion>();
    prs.add(pr1);
    prs.add(pr2);
    List<String> missing1 = new ArrayList<String>(Arrays.asList("child1", "child2"));
    when(cache.getPartitionedRegions()).thenReturn(prs);
    when(pr1.getMissingColocatedChildren()).thenReturn(missing1);
    when(pr1.getFullPath()).thenReturn("/pr1");
    smdsFunc.execute(context);
    results = resultSender.getResults();
    assertEquals(2, results.size());
    for (Object result : results) {
        Set<?> detailSet = (Set<?>) result;
        if (detailSet.toArray()[0] instanceof PersistentMemberPattern) {
            assertEquals(2, detailSet.toArray().length);
            assertTrue(detailSet.toArray()[1] instanceof PersistentMemberPattern);
            // Results are not sorted so verify results in either order
            if (((PersistentMemberPattern) detailSet.toArray()[0]).getDirectory().equals("/diskStore1")) {
                assertEquals("/diskStore2", ((PersistentMemberPattern) detailSet.toArray()[1]).getDirectory());
            } else if (((PersistentMemberPattern) detailSet.toArray()[0]).getDirectory().equals("/diskStore2")) {
                assertEquals("/diskStore1", ((PersistentMemberPattern) detailSet.toArray()[1]).getDirectory());
            } else {
                fail("Incorrect missing colocated region results");
            }
        } else if (detailSet.toArray()[0] instanceof ColocatedRegionDetails) {
            assertEquals(2, detailSet.toArray().length);
            assertTrue(detailSet.toArray()[1] instanceof ColocatedRegionDetails);
            assertEquals("/pr1", ((ColocatedRegionDetails) detailSet.toArray()[0]).getParent());
            assertEquals("/pr1", ((ColocatedRegionDetails) detailSet.toArray()[1]).getParent());
            // Results are not sorted so verify results in either order
            if (((ColocatedRegionDetails) detailSet.toArray()[0]).getChild().equals("child1")) {
                assertEquals("child2", ((ColocatedRegionDetails) detailSet.toArray()[1]).getChild());
            } else if (((ColocatedRegionDetails) detailSet.toArray()[0]).getChild().equals("child2")) {
                assertEquals("child1", ((ColocatedRegionDetails) detailSet.toArray()[1]).getChild());
            } else {
                fail("Incorrect missing colocated region results");
            }
        } else {
            fail("Unexpected result type: " + detailSet.toArray()[0].getClass());
        }
    }
}
Also used : PersistentMemberPattern(org.apache.geode.internal.cache.persistence.PersistentMemberPattern) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PersistentMemberID(org.apache.geode.internal.cache.persistence.PersistentMemberID) ColocatedRegionDetails(org.apache.geode.internal.cache.partitioned.ColocatedRegionDetails) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) DiskStoreID(org.apache.geode.internal.cache.persistence.DiskStoreID) HashSet(java.util.HashSet) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

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