Search in sources :

Example 16 with PersistentMemberID

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

the class DiskIFJUnitTest method testMemberIdSets.

@Test
public void testMemberIdSets() throws Exception {
    diskProps.setPersistBackup(true);
    diskProps.setRegionName("testMemberIdSets");
    LocalRegion lr = (LocalRegion) DiskRegionHelperFactory.getSyncPersistOnlyRegion(cache, diskProps, Scope.LOCAL);
    DiskRegion dr = lr.getDiskRegion();
    PersistentMemberID myOnId = createNewPMID();
    PersistentMemberID myOnId2 = createNewPMID();
    PersistentMemberID myOffId = createNewPMID();
    PersistentMemberID myEqualsId = createNewPMID();
    dr.memberOnline(myOnId);
    dr.memberOnline(myOnId2);
    dr.memberOffline(myOffId);
    dr.memberOfflineAndEqual(myEqualsId);
    assertEquals(TestUtils.asSet(myOnId, myOnId2), dr.getOnlineMembers());
    assertEquals(Collections.singleton(myOffId), dr.getOfflineMembers());
    assertEquals(Collections.singleton(myEqualsId), dr.getOfflineAndEqualMembers());
    close(lr);
    // do recovery
    lr = (LocalRegion) DiskRegionHelperFactory.getSyncPersistOnlyRegion(cache, diskProps, Scope.LOCAL);
    dr = lr.getDiskRegion();
    assertEquals(TestUtils.asSet(myOnId, myOnId2), dr.getOnlineMembers());
    assertEquals(Collections.singleton(myOffId), dr.getOfflineMembers());
    assertEquals(Collections.singleton(myEqualsId), dr.getOfflineAndEqualMembers());
    dr.forceIFCompaction();
    assertEquals(TestUtils.asSet(myOnId, myOnId2), dr.getOnlineMembers());
    assertEquals(Collections.singleton(myOffId), dr.getOfflineMembers());
    assertEquals(Collections.singleton(myEqualsId), dr.getOfflineAndEqualMembers());
    close(lr);
    // do recovery
    lr = (LocalRegion) DiskRegionHelperFactory.getSyncPersistOnlyRegion(cache, diskProps, Scope.LOCAL);
    dr = lr.getDiskRegion();
    assertEquals(TestUtils.asSet(myOnId, myOnId2), dr.getOnlineMembers());
    assertEquals(Collections.singleton(myOffId), dr.getOfflineMembers());
    assertEquals(Collections.singleton(myEqualsId), dr.getOfflineAndEqualMembers());
    dr.memberOffline(myOnId);
    dr.memberOfflineAndEqual(myOnId2);
    HashSet<PersistentMemberID> expSet = new HashSet<PersistentMemberID>();
    expSet.add(myOffId);
    expSet.add(myOnId);
    assertTrue(dr.getOnlineMembers().isEmpty());
    assertEquals(expSet, dr.getOfflineMembers());
    HashSet<PersistentMemberID> expSet2 = new HashSet<PersistentMemberID>();
    expSet2.add(myEqualsId);
    expSet2.add(myOnId2);
    assertEquals(expSet2, dr.getOfflineAndEqualMembers());
    close(lr);
    // do recovery
    lr = (LocalRegion) DiskRegionHelperFactory.getSyncPersistOnlyRegion(cache, diskProps, Scope.LOCAL);
    dr = lr.getDiskRegion();
    assertTrue(dr.getOnlineMembers().isEmpty());
    assertEquals(expSet, dr.getOfflineMembers());
    assertEquals(expSet2, dr.getOfflineAndEqualMembers());
    dr.forceIFCompaction();
    assertTrue(dr.getOnlineMembers().isEmpty());
    assertEquals(expSet, dr.getOfflineMembers());
    assertEquals(expSet2, dr.getOfflineAndEqualMembers());
    close(lr);
    // do recovery
    lr = (LocalRegion) DiskRegionHelperFactory.getSyncPersistOnlyRegion(cache, diskProps, Scope.LOCAL);
    dr = lr.getDiskRegion();
    assertTrue(dr.getOnlineMembers().isEmpty());
    assertEquals(expSet, dr.getOfflineMembers());
    assertEquals(expSet2, dr.getOfflineAndEqualMembers());
    dr.memberOnline(myOnId);
    dr.memberOnline(myOnId2);
    dr.memberOnline(myOffId);
    dr.memberOnline(myEqualsId);
    assertTrue(dr.getOfflineMembers().isEmpty());
    assertTrue(dr.getOfflineAndEqualMembers().isEmpty());
    expSet.add(myEqualsId);
    expSet.add(myOnId2);
    ;
    assertEquals(expSet, dr.getOnlineMembers());
    close(lr);
    // do recovery
    lr = (LocalRegion) DiskRegionHelperFactory.getSyncPersistOnlyRegion(cache, diskProps, Scope.LOCAL);
    dr = lr.getDiskRegion();
    assertTrue(dr.getOfflineMembers().isEmpty());
    assertEquals(expSet, dr.getOnlineMembers());
    dr.forceIFCompaction();
    assertTrue(dr.getOfflineMembers().isEmpty());
    assertEquals(expSet, dr.getOnlineMembers());
    close(lr);
    // do recovery
    lr = (LocalRegion) DiskRegionHelperFactory.getSyncPersistOnlyRegion(cache, diskProps, Scope.LOCAL);
    dr = lr.getDiskRegion();
    assertTrue(dr.getOfflineMembers().isEmpty());
    assertEquals(expSet, dr.getOnlineMembers());
    dr.memberOffline(myOffId);
    dr.memberOfflineAndEqual(myEqualsId);
    assertEquals(TestUtils.asSet(myOnId, myOnId2), dr.getOnlineMembers());
    assertEquals(Collections.singleton(myOffId), dr.getOfflineMembers());
    assertEquals(Collections.singleton(myEqualsId), dr.getOfflineAndEqualMembers());
    dr.memberRemoved(myOffId);
    assertTrue(dr.getOfflineMembers().isEmpty());
    assertEquals(TestUtils.asSet(myOnId, myOnId2), dr.getOnlineMembers());
    assertEquals(Collections.singleton(myEqualsId), dr.getOfflineAndEqualMembers());
    dr.memberRemoved(myOnId);
    dr.memberRemoved(myOnId2);
    assertTrue(dr.getOnlineMembers().isEmpty());
    assertTrue(dr.getOfflineMembers().isEmpty());
    assertEquals(Collections.singleton(myEqualsId), dr.getOfflineAndEqualMembers());
    dr.memberRemoved(myEqualsId);
    assertTrue(dr.getOnlineMembers().isEmpty());
    assertTrue(dr.getOfflineMembers().isEmpty());
    assertTrue(dr.getOfflineAndEqualMembers().isEmpty());
    close(lr);
    // do recovery
    lr = (LocalRegion) DiskRegionHelperFactory.getSyncPersistOnlyRegion(cache, diskProps, Scope.LOCAL);
    dr = lr.getDiskRegion();
    assertTrue(dr.getOnlineMembers().isEmpty());
    assertTrue(dr.getOfflineMembers().isEmpty());
    assertTrue(dr.getOfflineAndEqualMembers().isEmpty());
    dr.forceIFCompaction();
    assertTrue(dr.getOnlineMembers().isEmpty());
    assertTrue(dr.getOfflineMembers().isEmpty());
    assertTrue(dr.getOfflineAndEqualMembers().isEmpty());
    close(lr);
    // do recovery
    lr = (LocalRegion) DiskRegionHelperFactory.getSyncPersistOnlyRegion(cache, diskProps, Scope.LOCAL);
    dr = lr.getDiskRegion();
    assertTrue(dr.getOnlineMembers().isEmpty());
    assertTrue(dr.getOfflineMembers().isEmpty());
    assertTrue(dr.getOfflineAndEqualMembers().isEmpty());
}
Also used : PersistentMemberID(org.apache.geode.internal.cache.persistence.PersistentMemberID) HashSet(java.util.HashSet) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 17 with PersistentMemberID

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

the class DiskIFJUnitTest method testIFFIleInSecondDir.

/**
   * See if we can find the init file if it is not in the first directory. See bug 41883.
   */
@Test
public void testIFFIleInSecondDir() throws Exception {
    diskProps.setPersistBackup(true);
    diskProps.setRegionName("testIFFIleInSecondDir");
    diskProps.setDiskDirs(dirs);
    LocalRegion lr = (LocalRegion) DiskRegionHelperFactory.getSyncPersistOnlyRegion(cache, diskProps, Scope.LOCAL);
    DiskRegion dr = lr.getDiskRegion();
    assertEquals(null, dr.getMyInitializingID());
    PersistentMemberID myId = dr.getMyPersistentID();
    assertNotNull(myId);
    assertTrue(dr.getOnlineMembers().isEmpty());
    assertTrue(dr.getOfflineMembers().isEmpty());
    assertTrue(dr.getOfflineAndEqualMembers().isEmpty());
    // do recovery
    close(lr);
    assertEquals(true, (new File(dirs[0], "BACKUPtestIFFIleInSecondDir.if")).exists());
    // switch dir[]0 and dir[1]
    File[] myDirs = new File[2];
    myDirs[0] = dirs[1];
    myDirs[1] = dirs[0];
    diskProps.setDiskDirs(myDirs);
    assertEquals(true, (new File(myDirs[1], "BACKUPtestIFFIleInSecondDir.if")).exists());
    lr = (LocalRegion) DiskRegionHelperFactory.getSyncPersistOnlyRegion(cache, diskProps, Scope.LOCAL);
    dr = lr.getDiskRegion();
    assertEquals(null, dr.getMyInitializingID());
    assertEquals(myId, dr.getMyPersistentID());
    assertTrue(dr.getOnlineMembers().isEmpty());
    assertTrue(dr.getOfflineMembers().isEmpty());
    assertTrue(dr.getOfflineAndEqualMembers().isEmpty());
}
Also used : File(java.io.File) PersistentMemberID(org.apache.geode.internal.cache.persistence.PersistentMemberID) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 18 with PersistentMemberID

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

the class DiskIFJUnitTest method testAboutToDestroy.

@Test
public void testAboutToDestroy() throws Exception {
    diskProps.setPersistBackup(true);
    diskProps.setRegionName("testAboutToDestroy");
    LocalRegion lr = (LocalRegion) DiskRegionHelperFactory.getSyncPersistOnlyRegion(cache, diskProps, Scope.LOCAL);
    DiskRegion dr = lr.getDiskRegion();
    PersistentMemberID myId = createNewPMID();
    PersistentMemberID myOnId = createNewPMID();
    PersistentMemberID myOffId = createNewPMID();
    PersistentMemberID myEqualId = createNewPMID();
    dr.setInitializing(myId);
    dr.setInitialized();
    dr.memberOnline(myOnId);
    dr.memberOffline(myOffId);
    dr.memberOfflineAndEqual(myEqualId);
    assertEquals(Collections.singleton(myOnId), dr.getOnlineMembers());
    assertEquals(Collections.singleton(myOffId), dr.getOfflineMembers());
    assertEquals(Collections.singleton(myEqualId), dr.getOfflineAndEqualMembers());
    assertEquals(null, dr.getMyInitializingID());
    assertEquals(myId, dr.getMyPersistentID());
    assertEquals(false, dr.wasAboutToDestroy());
    dr.beginDestroy(lr);
    assertEquals(Collections.singleton(myOnId), dr.getOnlineMembers());
    assertEquals(Collections.singleton(myOffId), dr.getOfflineMembers());
    assertEquals(Collections.singleton(myEqualId), dr.getOfflineAndEqualMembers());
    assertEquals(myId, dr.getMyPersistentID());
    assertEquals(true, dr.wasAboutToDestroy());
    close(lr);
    // do recovery
    lr = (LocalRegion) DiskRegionHelperFactory.getSyncPersistOnlyRegion(cache, diskProps, Scope.LOCAL);
    dr = lr.getDiskRegion();
    assertEquals(Collections.singleton(myOnId), dr.getOnlineMembers());
    assertEquals(Collections.singleton(myOffId), dr.getOfflineMembers());
    assertEquals(Collections.singleton(myEqualId), dr.getOfflineAndEqualMembers());
    assertEquals(myId, dr.getMyPersistentID());
    assertEquals(true, dr.wasAboutToDestroy());
    dr.forceIFCompaction();
    assertEquals(Collections.singleton(myOnId), dr.getOnlineMembers());
    assertEquals(Collections.singleton(myOffId), dr.getOfflineMembers());
    assertEquals(Collections.singleton(myEqualId), dr.getOfflineAndEqualMembers());
    assertEquals(myId, dr.getMyPersistentID());
    assertEquals(true, dr.wasAboutToDestroy());
    close(lr);
    // do recovery
    lr = (LocalRegion) DiskRegionHelperFactory.getSyncPersistOnlyRegion(cache, diskProps, Scope.LOCAL);
    dr = lr.getDiskRegion();
    assertEquals(Collections.singleton(myOnId), dr.getOnlineMembers());
    assertEquals(Collections.singleton(myOffId), dr.getOfflineMembers());
    assertEquals(Collections.singleton(myEqualId), dr.getOfflineAndEqualMembers());
    assertEquals(myId, dr.getMyPersistentID());
    assertEquals(true, dr.wasAboutToDestroy());
    dr.endDestroy(lr);
    assertEquals(Collections.emptySet(), dr.getOnlineMembers());
    assertEquals(Collections.emptySet(), dr.getOfflineMembers());
    assertEquals(Collections.emptySet(), dr.getOfflineAndEqualMembers());
    assertEquals(false, dr.wasAboutToDestroy());
    close(lr);
    // do recovery
    lr = (LocalRegion) DiskRegionHelperFactory.getSyncPersistOnlyRegion(cache, diskProps, Scope.LOCAL);
    dr = lr.getDiskRegion();
    assertEquals(Collections.emptySet(), dr.getOnlineMembers());
    assertEquals(Collections.emptySet(), dr.getOfflineMembers());
    assertEquals(Collections.emptySet(), dr.getOfflineAndEqualMembers());
    assertEquals(false, dr.wasAboutToDestroy());
    dr.forceIFCompaction();
    assertEquals(Collections.emptySet(), dr.getOnlineMembers());
    assertEquals(Collections.emptySet(), dr.getOfflineMembers());
    assertEquals(Collections.emptySet(), dr.getOfflineAndEqualMembers());
    assertEquals(false, dr.wasAboutToDestroy());
    close(lr);
    assertEquals(Collections.emptySet(), dr.getOnlineMembers());
    assertEquals(Collections.emptySet(), dr.getOfflineMembers());
    assertEquals(Collections.emptySet(), dr.getOfflineAndEqualMembers());
    assertEquals(false, dr.wasAboutToDestroy());
}
Also used : PersistentMemberID(org.apache.geode.internal.cache.persistence.PersistentMemberID) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 19 with PersistentMemberID

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

the class DiskIFJUnitTest method testMyPMID.

@Test
public void testMyPMID() throws Exception {
    diskProps.setPersistBackup(true);
    diskProps.setRegionName("testMyPMID");
    LocalRegion lr = (LocalRegion) DiskRegionHelperFactory.getSyncPersistOnlyRegion(cache, diskProps, Scope.LOCAL);
    DiskRegion dr = lr.getDiskRegion();
    PersistentMemberID myId = createNewPMID();
    assertEquals(null, dr.getMyInitializingID());
    PersistentMemberID oldId = dr.getMyPersistentID();
    dr.setInitializing(myId);
    assertEquals(myId, dr.getMyInitializingID());
    assertEquals(oldId, dr.getMyPersistentID());
    close(lr);
    // do recovery
    lr = (LocalRegion) DiskRegionHelperFactory.getSyncPersistOnlyRegion(cache, diskProps, Scope.LOCAL);
    dr = lr.getDiskRegion();
    assertEquals(myId, dr.getMyInitializingID());
    assertEquals(oldId, dr.getMyPersistentID());
    dr.forceIFCompaction();
    assertEquals(myId, dr.getMyInitializingID());
    assertEquals(oldId, dr.getMyPersistentID());
    close(lr);
    // do recovery
    lr = (LocalRegion) DiskRegionHelperFactory.getSyncPersistOnlyRegion(cache, diskProps, Scope.LOCAL);
    dr = lr.getDiskRegion();
    assertEquals(myId, dr.getMyInitializingID());
    assertEquals(oldId, dr.getMyPersistentID());
    dr.setInitialized();
    assertEquals(null, dr.getMyInitializingID());
    assertEquals(myId, dr.getMyPersistentID());
    close(lr);
    // do recovery
    lr = (LocalRegion) DiskRegionHelperFactory.getSyncPersistOnlyRegion(cache, diskProps, Scope.LOCAL);
    dr = lr.getDiskRegion();
    assertEquals(null, dr.getMyInitializingID());
    assertEquals(myId, dr.getMyPersistentID());
    dr.forceIFCompaction();
    assertEquals(null, dr.getMyInitializingID());
    assertEquals(myId, dr.getMyPersistentID());
    close(lr);
    // do recovery
    lr = (LocalRegion) DiskRegionHelperFactory.getSyncPersistOnlyRegion(cache, diskProps, Scope.LOCAL);
    dr = lr.getDiskRegion();
    assertEquals(null, dr.getMyInitializingID());
    assertEquals(myId, dr.getMyPersistentID());
}
Also used : PersistentMemberID(org.apache.geode.internal.cache.persistence.PersistentMemberID) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 20 with PersistentMemberID

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

the class DiskStoreImpl method generatePersistentID.

public PersistentMemberID generatePersistentID(DiskRegionView dr) {
    File firstDir = getInfoFileDir().getDir();
    InternalDistributedSystem ids = getCache().getInternalDistributedSystem();
    InternalDistributedMember memberId = ids.getDistributionManager().getDistributionManagerId();
    // NOTE - do NOT use DM.cacheTimeMillis here. See bug #49920
    long timestamp = System.currentTimeMillis();
    return new PersistentMemberID(getDiskStoreID(), memberId.getInetAddress(), firstDir.getAbsolutePath(), memberId.getName(), timestamp, (short) 0);
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) File(java.io.File) 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