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);
}
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();
}
}
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;
}
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();
// }
}
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();
}
}
}
});
}
Aggregations