Search in sources :

Example 21 with PersistentID

use of org.apache.geode.cache.persistence.PersistentID in project geode by apache.

the class FinishBackupRequest method createResponse.

@Override
protected AdminResponse createResponse(DistributionManager dm) {
    InternalCache cache = GemFireCacheImpl.getInstance();
    HashSet<PersistentID> persistentIds;
    if (cache == null || cache.getBackupManager() == null) {
        persistentIds = new HashSet<PersistentID>();
    } else {
        try {
            persistentIds = cache.getBackupManager().finishBackup(targetDir, baselineDir, abort);
        } catch (IOException e) {
            logger.error(LocalizedMessage.create(LocalizedStrings.CliLegacyMessage_ERROR, this.getClass()), e);
            return AdminFailureResponse.create(dm, getSender(), e);
        }
    }
    return new FinishBackupResponse(this.getSender(), persistentIds);
}
Also used : InternalCache(org.apache.geode.internal.cache.InternalCache) IOException(java.io.IOException) PersistentID(org.apache.geode.cache.persistence.PersistentID)

Example 22 with PersistentID

use of org.apache.geode.cache.persistence.PersistentID in project geode by apache.

the class BackupManager method finishBackup.

public HashSet<PersistentID> finishBackup(File targetDir, File baselineDir, boolean abort) throws IOException {
    try {
        if (abort) {
            return new HashSet<PersistentID>();
        }
        File backupDir = getBackupDir(targetDir);
        // Make sure our baseline is okay for this member
        baselineDir = checkBaseline(baselineDir);
        // Create an inspector for the baseline backup
        BackupInspector inspector = (baselineDir == null ? null : BackupInspector.createInspector(baselineDir));
        File storesDir = new File(backupDir, DATA_STORES);
        RestoreScript restoreScript = new RestoreScript();
        HashSet<PersistentID> persistentIds = new HashSet<PersistentID>();
        Collection<DiskStore> diskStores = new ArrayList<DiskStore>(cache.listDiskStoresIncludingRegionOwned());
        boolean foundPersistentData = false;
        for (Iterator<DiskStore> itr = diskStores.iterator(); itr.hasNext(); ) {
            DiskStoreImpl store = (DiskStoreImpl) itr.next();
            if (store.hasPersistedData()) {
                if (!foundPersistentData) {
                    createBackupDir(backupDir);
                    foundPersistentData = true;
                }
                File diskStoreDir = new File(storesDir, store.getBackupDirName());
                diskStoreDir.mkdir();
                store.startBackup(diskStoreDir, inspector, restoreScript);
            } else {
                itr.remove();
            }
            store.releaseBackupLock();
        }
        allowDestroys.countDown();
        for (DiskStore store : diskStores) {
            DiskStoreImpl storeImpl = (DiskStoreImpl) store;
            storeImpl.finishBackup(this);
            storeImpl.getStats().endBackup();
            persistentIds.add(storeImpl.getPersistentID());
        }
        if (foundPersistentData) {
            backupConfigFiles(restoreScript, backupDir);
            backupUserFiles(restoreScript, backupDir);
            backupDeployedJars(restoreScript, backupDir);
            restoreScript.generate(backupDir);
            File incompleteFile = new File(backupDir, INCOMPLETE_BACKUP);
            if (!incompleteFile.delete()) {
                throw new IOException("Could not delete file " + INCOMPLETE_BACKUP);
            }
        }
        return persistentIds;
    } finally {
        cleanup();
    }
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) DiskStore(org.apache.geode.cache.DiskStore) DiskStoreImpl(org.apache.geode.internal.cache.DiskStoreImpl) File(java.io.File) HashSet(java.util.HashSet) PersistentID(org.apache.geode.cache.persistence.PersistentID)

Example 23 with PersistentID

use of org.apache.geode.cache.persistence.PersistentID in project geode by apache.

the class BackupManager method prepareBackup.

public HashSet<PersistentID> prepareBackup() {
    HashSet<PersistentID> persistentIds = new HashSet<PersistentID>();
    Collection<DiskStore> diskStores = cache.listDiskStoresIncludingRegionOwned();
    for (DiskStore store : diskStores) {
        DiskStoreImpl storeImpl = (DiskStoreImpl) store;
        storeImpl.lockStoreBeforeBackup();
        if (storeImpl.hasPersistedData()) {
            persistentIds.add(storeImpl.getPersistentID());
            storeImpl.getStats().startBackup();
        }
    }
    return persistentIds;
}
Also used : DiskStore(org.apache.geode.cache.DiskStore) DiskStoreImpl(org.apache.geode.internal.cache.DiskStoreImpl) HashSet(java.util.HashSet) PersistentID(org.apache.geode.cache.persistence.PersistentID)

Example 24 with PersistentID

use of org.apache.geode.cache.persistence.PersistentID in project geode by apache.

the class PersistentRecoveryOrderDUnitTest method testRevokeAMember.

/**
   * Tests to make sure that we stop waiting for a member that we revoke.
   * 
   * @throws Exception
   */
@Test
public void testRevokeAMember() throws Exception {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    VM vm2 = host.getVM(2);
    LogWriterUtils.getLogWriter().info("Creating region in VM0");
    createPersistentRegion(vm0);
    LogWriterUtils.getLogWriter().info("Creating region in VM1");
    createPersistentRegion(vm1);
    putAnEntry(vm0);
    vm0.invoke(new SerializableRunnable("Check for waiting regions") {

        public void run() {
            GemFireCacheImpl cache = (GemFireCacheImpl) getCache();
            PersistentMemberManager mm = cache.getPersistentMemberManager();
            Map<String, Set<PersistentMemberID>> waitingRegions = mm.getWaitingRegions();
            assertEquals(0, waitingRegions.size());
        }
    });
    LogWriterUtils.getLogWriter().info("closing region in vm0");
    closeRegion(vm0);
    updateTheEntry(vm1);
    LogWriterUtils.getLogWriter().info("closing region in vm1");
    closeCache(vm1);
    // This ought to wait for VM1 to come back
    LogWriterUtils.getLogWriter().info("Creating region in VM0");
    AsyncInvocation future = createPersistentRegionAsync(vm0);
    waitForBlockedInitialization(vm0);
    assertTrue(future.isAlive());
    vm2.invoke(new SerializableRunnable("Revoke the member") {

        public void run() {
            GemFireCacheImpl cache = (GemFireCacheImpl) getCache();
            DistributedSystemConfig config;
            AdminDistributedSystem adminDS = null;
            try {
                config = AdminDistributedSystemFactory.defineDistributedSystem(getSystem(), "");
                adminDS = AdminDistributedSystemFactory.getDistributedSystem(config);
                adminDS.connect();
                Set<PersistentID> missingIds = adminDS.getMissingPersistentMembers();
                LogWriterUtils.getLogWriter().info("waiting members=" + missingIds);
                assertEquals(1, missingIds.size());
                PersistentID missingMember = missingIds.iterator().next();
                adminDS.revokePersistentMember(missingMember.getUUID());
            } catch (AdminException e) {
                throw new RuntimeException(e);
            } finally {
                if (adminDS != null) {
                    adminDS.disconnect();
                }
            }
        }
    });
    future.join(MAX_WAIT);
    if (future.isAlive()) {
        fail("Region not created within" + MAX_WAIT);
    }
    if (future.exceptionOccurred()) {
        throw new Exception(future.getException());
    }
    checkForRecoveryStat(vm0, true);
    // Check to make sure we recovered the old
    // value of the entry.
    SerializableRunnable checkForEntry = new SerializableRunnable("check for the entry") {

        public void run() {
            Cache cache = getCache();
            Region region = cache.getRegion(REGION_NAME);
            assertEquals("B", region.get("A"));
        }
    };
    vm0.invoke(checkForEntry);
    // Now, we should not be able to create a region
    // in vm1, because the this member was revoked
    LogWriterUtils.getLogWriter().info("Creating region in VM1");
    IgnoredException e = IgnoredException.addIgnoredException(RevokedPersistentDataException.class.getSimpleName(), vm1);
    try {
        createPersistentRegion(vm1);
        fail("We should have received a split distributed system exception");
    } catch (RuntimeException expected) {
        if (!(expected.getCause() instanceof RevokedPersistentDataException)) {
            throw expected;
        }
    } finally {
        e.remove();
    }
    closeCache(vm1);
    // Restart vm0
    closeCache(vm0);
    createPersistentRegion(vm0);
// Make sure we still get a RevokedPersistentDataException
// TODO - RVV - This won't work until we actually persist the revoked
// members. I want to refactor to use disk store id before we do that.
// getLogWriter().info("Creating region in VM1");
// e = addExpectedException(RevokedPersistentDataException.class.getSimpleName(), vm1);
// try {
// createPersistentRegion(vm1);
// fail("We should have received a split distributed system exception");
// } catch(RuntimeException expected) {
// if(!(expected.getCause() instanceof RevokedPersistentDataException)) {
// throw expected;
// }
// //Do nothing
// } finally {
// e.remove();
// }
}
Also used : AdminException(org.apache.geode.admin.AdminException) RevokedPersistentDataException(org.apache.geode.cache.persistence.RevokedPersistentDataException) Set(java.util.Set) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Host(org.apache.geode.test.dunit.Host) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) AdminDistributedSystem(org.apache.geode.admin.AdminDistributedSystem) RevokedPersistentDataException(org.apache.geode.cache.persistence.RevokedPersistentDataException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) AdminException(org.apache.geode.admin.AdminException) ConflictingPersistentDataException(org.apache.geode.cache.persistence.ConflictingPersistentDataException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) LockServiceDestroyedException(org.apache.geode.distributed.LockServiceDestroyedException) CacheClosedException(org.apache.geode.cache.CacheClosedException) PersistentReplicatesOfflineException(org.apache.geode.cache.persistence.PersistentReplicatesOfflineException) IOException(java.io.IOException) DistributedSystemConfig(org.apache.geode.admin.DistributedSystemConfig) VM(org.apache.geode.test.dunit.VM) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) LocalRegion(org.apache.geode.internal.cache.LocalRegion) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) DiskRegion(org.apache.geode.internal.cache.DiskRegion) Region(org.apache.geode.cache.Region) IgnoredException(org.apache.geode.test.dunit.IgnoredException) Map(java.util.Map) HashMap(java.util.HashMap) PersistentID(org.apache.geode.cache.persistence.PersistentID) Cache(org.apache.geode.cache.Cache) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 25 with PersistentID

use of org.apache.geode.cache.persistence.PersistentID in project geode by apache.

the class PersistentRecoveryOrderDUnitTest method testWaitingMemberList.

/**
   * Test which members show up in the list of members we're waiting on.
   * 
   * @throws Exception
   */
@Test
public void testWaitingMemberList() throws Exception {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    VM vm2 = host.getVM(2);
    VM vm3 = host.getVM(3);
    LogWriterUtils.getLogWriter().info("Creating region in VM0");
    createPersistentRegion(vm0);
    LogWriterUtils.getLogWriter().info("Creating region in VM1");
    createPersistentRegion(vm1);
    createPersistentRegion(vm2);
    putAnEntry(vm0);
    vm0.invoke(new SerializableRunnable("Check for waiting regions") {

        public void run() {
            GemFireCacheImpl cache = (GemFireCacheImpl) getCache();
            PersistentMemberManager mm = cache.getPersistentMemberManager();
            Map<String, Set<PersistentMemberID>> waitingRegions = mm.getWaitingRegions();
            assertEquals(0, waitingRegions.size());
        }
    });
    LogWriterUtils.getLogWriter().info("closing region in vm0");
    closeRegion(vm0);
    updateTheEntry(vm1);
    LogWriterUtils.getLogWriter().info("closing region in vm1");
    closeRegion(vm1);
    updateTheEntry(vm2, "D");
    LogWriterUtils.getLogWriter().info("closing region in vm2");
    closeRegion(vm2);
    // These ought to wait for VM2 to come back
    LogWriterUtils.getLogWriter().info("Creating region in VM0");
    AsyncInvocation future0 = createPersistentRegionAsync(vm0);
    waitForBlockedInitialization(vm0);
    assertTrue(future0.isAlive());
    LogWriterUtils.getLogWriter().info("Creating region in VM1");
    final AsyncInvocation future1 = createPersistentRegionAsync(vm1);
    waitForBlockedInitialization(vm1);
    assertTrue(future1.isAlive());
    vm3.invoke(new SerializableRunnable("check waiting members") {

        public void run() {
            GemFireCacheImpl cache = (GemFireCacheImpl) getCache();
            DistributedSystemConfig config;
            AdminDistributedSystem adminDS = null;
            try {
                config = AdminDistributedSystemFactory.defineDistributedSystem(getSystem(), "");
                adminDS = AdminDistributedSystemFactory.getDistributedSystem(config);
                adminDS.connect();
                Set<PersistentID> missingIds = adminDS.getMissingPersistentMembers();
                LogWriterUtils.getLogWriter().info("waiting members=" + missingIds);
                assertEquals(1, missingIds.size());
            } catch (AdminException e) {
                throw new RuntimeException(e);
            } finally {
                if (adminDS != null) {
                    adminDS.disconnect();
                }
            }
        }
    });
    vm1.invoke(new SerializableRunnable("close cache") {

        public void run() {
            getCache().close();
        }
    });
    Wait.waitForCriterion(new WaitCriterion() {

        public boolean done() {
            return !future1.isAlive();
        }

        public String description() {
            return "Waiting for blocked initialization to terminate because the cache was closed.";
        }
    }, 30000, 500, true);
    // Now we should be missing 2 members
    vm3.invoke(new SerializableRunnable("check waiting members again") {

        public void run() {
            GemFireCacheImpl cache = (GemFireCacheImpl) getCache();
            DistributedSystemConfig config;
            AdminDistributedSystem adminDS = null;
            try {
                config = AdminDistributedSystemFactory.defineDistributedSystem(getSystem(), "");
                adminDS = AdminDistributedSystemFactory.getDistributedSystem(config);
                adminDS.connect();
                final AdminDistributedSystem connectedDS = adminDS;
                Wait.waitForCriterion(new WaitCriterion() {

                    public String description() {
                        return "Waiting for waiting members to have 2 members";
                    }

                    public boolean done() {
                        Set<PersistentID> missingIds;
                        try {
                            missingIds = connectedDS.getMissingPersistentMembers();
                        } catch (AdminException e) {
                            throw new RuntimeException(e);
                        }
                        return 2 == missingIds.size();
                    }
                }, MAX_WAIT, 500, true);
            } catch (AdminException e) {
                throw new RuntimeException(e);
            } finally {
                if (adminDS != null) {
                    adminDS.disconnect();
                }
            }
        }
    });
}
Also used : AdminException(org.apache.geode.admin.AdminException) Set(java.util.Set) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Host(org.apache.geode.test.dunit.Host) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) AdminDistributedSystem(org.apache.geode.admin.AdminDistributedSystem) DistributedSystemConfig(org.apache.geode.admin.DistributedSystemConfig) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) VM(org.apache.geode.test.dunit.VM) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) Map(java.util.Map) HashMap(java.util.HashMap) PersistentID(org.apache.geode.cache.persistence.PersistentID) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Aggregations

PersistentID (org.apache.geode.cache.persistence.PersistentID)29 HashSet (java.util.HashSet)11 File (java.io.File)8 Set (java.util.Set)8 IOException (java.io.IOException)7 DiskStore (org.apache.geode.cache.DiskStore)7 InternalCache (org.apache.geode.internal.cache.InternalCache)6 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)6 Test (org.junit.Test)6 HashMap (java.util.HashMap)5 DistributedMember (org.apache.geode.distributed.DistributedMember)5 Map (java.util.Map)4 AdminException (org.apache.geode.admin.AdminException)4 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)4 LinkedList (java.util.LinkedList)3 TreeSet (java.util.TreeSet)3 RegexFileFilter (org.apache.commons.io.filefilter.RegexFileFilter)3 AdminDistributedSystem (org.apache.geode.admin.AdminDistributedSystem)3 BackupStatus (org.apache.geode.admin.BackupStatus)3 DistributedSystemConfig (org.apache.geode.admin.DistributedSystemConfig)3